diff options
author | John Wiegley <johnw@newartisans.com> | 2009-02-03 12:21:54 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-02-03 12:22:10 -0400 |
commit | 3434650848e500d605447388ef7e069ee1515b72 (patch) | |
tree | da05e1bc5dbf5ef321d258f524518e9631dc7574 /src/amount.cc | |
parent | 9bdcbffb150387d64e7eff630aaad84fb0d696b1 (diff) | |
download | fork-ledger-3434650848e500d605447388ef7e069ee1515b72.tar.gz fork-ledger-3434650848e500d605447388ef7e069ee1515b72.tar.bz2 fork-ledger-3434650848e500d605447388ef7e069ee1515b72.zip |
Removed the binary caching code, and the XML, QIF and Gnucash parsers.
Diffstat (limited to 'src/amount.cc')
-rw-r--r-- | src/amount.cc | 220 |
1 files changed, 0 insertions, 220 deletions
diff --git a/src/amount.cc b/src/amount.cc index e95f6350..1d1a3c36 100644 --- a/src/amount.cc +++ b/src/amount.cc @@ -30,7 +30,6 @@ */ #include "amount.h" -#include "binary.h" namespace ledger { @@ -1021,225 +1020,6 @@ void amount_t::print(std::ostream& _out, bool omit_commodity, _out << out.str(); } -void amount_t::read(std::istream& in) -{ - using namespace ledger::binary; - - // Read in the commodity for this amount - - commodity_t::ident_t ident; - read_long(in, ident); - if (ident == 0xffffffff) - commodity_ = NULL; - else if (ident == 0) - commodity_ = current_pool->null_commodity; - else { - commodity_ = current_pool->find(ident); - assert(commodity_); - } - - // Read in the quantity - - char byte; - in.read(&byte, sizeof(byte)); - - if (byte < 3) { - quantity = new bigint_t; - - unsigned short len; - in.read(reinterpret_cast<char *>(&len), sizeof(len)); - assert(len < 4096); - static char buf[4096]; - in.read(buf, len); - - mpz_import(temp, len / sizeof(short), 1, sizeof(short), - 0, 0, buf); - mpq_set_num(MP(quantity), temp); - - in.read(reinterpret_cast<char *>(&len), sizeof(len)); - assert(len < 4096); - in.read(buf, len); - mpz_import(temp, len / sizeof(short), 1, sizeof(short), - 0, 0, buf); - mpq_set_den(MP(quantity), temp); - - char negative; - in.read(&negative, sizeof(negative)); - if (negative) - mpq_neg(MP(quantity), MP(quantity)); - - in.read(reinterpret_cast<char *>(&quantity->prec), sizeof(quantity->prec)); - - bigint_t::flags_t tflags; - in.read(reinterpret_cast<char *>(&tflags), sizeof(tflags)); - quantity->set_flags(tflags); - } - else { - assert(false); - } -} - -void amount_t::read(const char *& data, - char ** pool, - char ** pool_next) -{ - using namespace ledger::binary; - - // Read in the commodity for this amount - - commodity_t::ident_t ident; - read_long(data, ident); - if (ident == 0xffffffff) - commodity_ = NULL; - else if (ident == 0) - commodity_ = current_pool->null_commodity; - else { - commodity_ = current_pool->find(ident); - assert(commodity_); - } - - // Read in the quantity - - char byte = *data++;; - - if (byte < 3) { - if (byte == 2) { - quantity = new(reinterpret_cast<bigint_t *>(*pool_next)) bigint_t; - *pool_next += sizeof(bigint_t); - } else { - quantity = new bigint_t; - } - - unsigned short len = - *reinterpret_cast<unsigned short *>(const_cast<char *>(data)); - data += sizeof(unsigned short); - mpz_init(temp); - mpz_import(temp, len / sizeof(short), 1, sizeof(short), - 0, 0, data); - data += len; - - mpq_set_num(MP(quantity), temp); - - len = *reinterpret_cast<unsigned short *>(const_cast<char *>(data)); - data += sizeof(unsigned short); - mpz_init(temp); - mpz_import(temp, len / sizeof(short), 1, sizeof(short), - 0, 0, data); - data += len; - - mpq_set_den(MP(quantity), temp); - - char negative = *data++; - if (negative) - mpq_neg(MP(quantity), MP(quantity)); - - quantity->prec = *reinterpret_cast<precision_t *>(const_cast<char *>(data)); - data += sizeof(precision_t); - quantity->set_flags(*reinterpret_cast<bigint_t::flags_t *>(const_cast<char *>(data))); - data += sizeof(bigint_t::flags_t); - - if (byte == 2) - quantity->add_flags(BIGINT_BULK_ALLOC); - } else { - uint_fast32_t index = *reinterpret_cast<uint_fast32_t *>(const_cast<char *>(data)); - data += sizeof(uint_fast32_t); - - quantity = reinterpret_cast<bigint_t *>(*pool + (index - 1) * sizeof(bigint_t)); - - DEBUG("amounts.refs", - quantity << " ref++, now " << (quantity->ref + 1)); - quantity->ref++; - } -} - -namespace { - void write_bytes(std::ostream& out, - const char * buf, - const std::size_t size) - { - unsigned short len = size * sizeof(short); - out.write(reinterpret_cast<char *>(&len), sizeof(len)); - if (len) { - assert(len < 4096); - out.write(buf, len); - } - } -} - -void amount_t::write(std::ostream& out, std::size_t index) const -{ - using namespace ledger::binary; - - // Write out the commodity for this amount - - if (! quantity) - throw_(amount_error, "Cannot serialize an uninitialized amount"); - - if (commodity_) - write_long(out, commodity_->ident); - else - write_long<commodity_t::ident_t>(out, 0xffffffff); - - // Write out the quantity - - char byte; - - if (index == 0 || quantity->index == 0) { - if (index != 0) { - quantity->index = index; // if !optimized, this is garbage - byte = 2; - } else { - byte = 1; - } - out.write(&byte, sizeof(byte)); - - std::size_t size; - static char buf[4096]; - - mpq_get_num(temp, MP(quantity)); - mpz_export(buf, &size, 1, sizeof(short), 0, 0, temp); - write_bytes(out, buf, size); - - mpq_get_den(temp, MP(quantity)); - mpz_export(buf, &size, 1, sizeof(short), 0, 0, temp); - write_bytes(out, buf, size); - - byte = mpq_sgn(MP(quantity)) < 0 ? 1 : 0; - out.write(&byte, sizeof(byte)); - - out.write(reinterpret_cast<char *>(&quantity->prec), sizeof(quantity->prec)); - bigint_t::flags_t tflags = quantity->flags() & ~BIGINT_BULK_ALLOC; - assert(sizeof(tflags) == sizeof(bigint_t::flags_t)); - out.write(reinterpret_cast<char *>(&tflags), sizeof(tflags)); - } else { - assert(quantity->ref > 1); - - // Since this value has already been written, we simply write - // out a reference to which one it was. - byte = 3; - out.write(&byte, sizeof(byte)); - out.write(reinterpret_cast<char *>(&quantity->index), sizeof(quantity->index)); - } -} - -void amount_t::read_xml(std::istream& in) -{ -} - -void amount_t::write_xml(std::ostream& out, const int depth) const -{ - out << xml_str("<amount>\n", depth); - - if (has_commodity()) - commodity().write_xml(out, depth + 1); - - out << xml_str("<quantity>", depth + 1) - << quantity_string() - << "</quantity>\n"; - - out << xml_str("</amount>\n", depth); -} - bool amount_t::valid() const { if (quantity) { |