*** empty log message ***
This commit is contained in:
parent
326235ffbe
commit
d02f74efea
4 changed files with 54 additions and 37 deletions
39
amount.cc
39
amount.cc
|
|
@ -15,11 +15,11 @@ namespace ledger {
|
||||||
|
|
||||||
class amount_t::bigint_t {
|
class amount_t::bigint_t {
|
||||||
public:
|
public:
|
||||||
mpz_t val;
|
mpz_t val;
|
||||||
unsigned short prec;
|
unsigned char prec;
|
||||||
unsigned short flags;
|
unsigned char flags;
|
||||||
unsigned int ref;
|
unsigned int ref;
|
||||||
unsigned int index;
|
unsigned int index;
|
||||||
|
|
||||||
bigint_t() : prec(0), flags(0), ref(1), index(0) {
|
bigint_t() : prec(0), flags(0), ref(1), index(0) {
|
||||||
mpz_init(val);
|
mpz_init(val);
|
||||||
|
|
@ -631,8 +631,8 @@ std::string amount_t::quantity_string() const
|
||||||
// Ensure the value is rounded to the commodity's precision before
|
// Ensure the value is rounded to the commodity's precision before
|
||||||
// outputting it. NOTE: `rquotient' is used here as a temp variable!
|
// outputting it. NOTE: `rquotient' is used here as a temp variable!
|
||||||
|
|
||||||
commodity_t& comm(commodity());
|
commodity_t& comm(commodity());
|
||||||
unsigned short precision;
|
unsigned char precision;
|
||||||
|
|
||||||
if (! comm || quantity->flags & BIGINT_KEEP_PREC) {
|
if (! comm || quantity->flags & BIGINT_KEEP_PREC) {
|
||||||
mpz_ui_pow_ui(divisor, 10, quantity->prec);
|
mpz_ui_pow_ui(divisor, 10, quantity->prec);
|
||||||
|
|
@ -737,8 +737,8 @@ std::ostream& operator<<(std::ostream& _out, const amount_t& amt)
|
||||||
// Ensure the value is rounded to the commodity's precision before
|
// Ensure the value is rounded to the commodity's precision before
|
||||||
// outputting it. NOTE: `rquotient' is used here as a temp variable!
|
// outputting it. NOTE: `rquotient' is used here as a temp variable!
|
||||||
|
|
||||||
commodity_t& comm(base.commodity());
|
commodity_t& comm(base.commodity());
|
||||||
unsigned short precision;
|
unsigned char precision;
|
||||||
|
|
||||||
if (! comm || base.quantity->flags & BIGINT_KEEP_PREC) {
|
if (! comm || base.quantity->flags & BIGINT_KEEP_PREC) {
|
||||||
mpz_ui_pow_ui(divisor, 10, base.quantity->prec);
|
mpz_ui_pow_ui(divisor, 10, base.quantity->prec);
|
||||||
|
|
@ -1007,7 +1007,7 @@ void parse_annotations(std::istream& in, const std::string& symbol,
|
||||||
<< " tag " << tag);
|
<< " tag " << tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
void amount_t::parse(std::istream& in, unsigned short flags)
|
void amount_t::parse(std::istream& in, unsigned char flags)
|
||||||
{
|
{
|
||||||
// The possible syntax for an amount is:
|
// The possible syntax for an amount is:
|
||||||
//
|
//
|
||||||
|
|
@ -1168,7 +1168,7 @@ void amount_t::reduce()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void amount_t::parse(const std::string& str, unsigned short flags)
|
void amount_t::parse(const std::string& str, unsigned char flags)
|
||||||
{
|
{
|
||||||
std::istringstream stream(str);
|
std::istringstream stream(str);
|
||||||
parse(stream, flags);
|
parse(stream, flags);
|
||||||
|
|
@ -1209,7 +1209,6 @@ void amount_t::read_quantity(char *& data)
|
||||||
else if (byte == 1) {
|
else if (byte == 1) {
|
||||||
quantity = new((bigint_t *)bigints_next) bigint_t;
|
quantity = new((bigint_t *)bigints_next) bigint_t;
|
||||||
bigints_next += sizeof(bigint_t);
|
bigints_next += sizeof(bigint_t);
|
||||||
quantity->flags |= BIGINT_BULK_ALLOC;
|
|
||||||
|
|
||||||
unsigned short len = *((unsigned short *) data);
|
unsigned short len = *((unsigned short *) data);
|
||||||
data += sizeof(unsigned short);
|
data += sizeof(unsigned short);
|
||||||
|
|
@ -1221,8 +1220,11 @@ void amount_t::read_quantity(char *& data)
|
||||||
if (negative)
|
if (negative)
|
||||||
mpz_neg(MPZ(quantity), MPZ(quantity));
|
mpz_neg(MPZ(quantity), MPZ(quantity));
|
||||||
|
|
||||||
quantity->prec = *((unsigned short *) data);
|
quantity->prec = *((unsigned char *) data);
|
||||||
data += sizeof(unsigned short);
|
data += sizeof(unsigned char);
|
||||||
|
quantity->flags = *((unsigned char *) data);
|
||||||
|
data += sizeof(unsigned char);
|
||||||
|
quantity->flags |= BIGINT_BULK_ALLOC;
|
||||||
} else {
|
} else {
|
||||||
unsigned int index = *((unsigned int *) data);
|
unsigned int index = *((unsigned int *) data);
|
||||||
data += sizeof(unsigned int);
|
data += sizeof(unsigned int);
|
||||||
|
|
@ -1258,6 +1260,7 @@ void amount_t::read_quantity(std::istream& in)
|
||||||
mpz_neg(MPZ(quantity), MPZ(quantity));
|
mpz_neg(MPZ(quantity), MPZ(quantity));
|
||||||
|
|
||||||
in.read((char *)&quantity->prec, sizeof(quantity->prec));
|
in.read((char *)&quantity->prec, sizeof(quantity->prec));
|
||||||
|
in.read((char *)&quantity->flags, sizeof(quantity->flags));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
assert(0);
|
assert(0);
|
||||||
|
|
@ -1294,6 +1297,9 @@ void amount_t::write_quantity(std::ostream& out) const
|
||||||
out.write(&byte, sizeof(byte));
|
out.write(&byte, sizeof(byte));
|
||||||
|
|
||||||
out.write((char *)&quantity->prec, sizeof(quantity->prec));
|
out.write((char *)&quantity->prec, sizeof(quantity->prec));
|
||||||
|
unsigned char flags = quantity->flags & ~BIGINT_BULK_ALLOC;
|
||||||
|
assert(sizeof(flags) == sizeof(quantity->flags));
|
||||||
|
out.write((char *)&flags, sizeof(flags));
|
||||||
} else {
|
} else {
|
||||||
assert(quantity->ref > 1);
|
assert(quantity->ref > 1);
|
||||||
|
|
||||||
|
|
@ -1330,6 +1336,7 @@ void amount_t::annotate_commodity(const amount_t& price,
|
||||||
} else {
|
} else {
|
||||||
this_base = &commodity();
|
this_base = &commodity();
|
||||||
}
|
}
|
||||||
|
assert(this_base);
|
||||||
|
|
||||||
DEBUG_PRINT("amounts.commodities", "Annotating commodity for amount "
|
DEBUG_PRINT("amounts.commodities", "Annotating commodity for amount "
|
||||||
<< *this << std::endl
|
<< *this << std::endl
|
||||||
|
|
@ -1364,6 +1371,7 @@ amount_t amount_t::reduce_commodity(const bool keep_price,
|
||||||
|
|
||||||
annotated_commodity_t&
|
annotated_commodity_t&
|
||||||
ann_comm(static_cast<annotated_commodity_t&>(commodity()));
|
ann_comm(static_cast<annotated_commodity_t&>(commodity()));
|
||||||
|
assert(ann_comm.base);
|
||||||
|
|
||||||
commodity_t * new_comm;
|
commodity_t * new_comm;
|
||||||
|
|
||||||
|
|
@ -1377,7 +1385,6 @@ amount_t amount_t::reduce_commodity(const bool keep_price,
|
||||||
} else {
|
} else {
|
||||||
new_comm = commodity_t::find_or_create(ann_comm.base_symbol());
|
new_comm = commodity_t::find_or_create(ann_comm.base_symbol());
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(new_comm);
|
assert(new_comm);
|
||||||
|
|
||||||
amount_t temp(*this);
|
amount_t temp(*this);
|
||||||
|
|
@ -1694,7 +1701,7 @@ int py_amount_quantity(amount_t& amount)
|
||||||
}
|
}
|
||||||
|
|
||||||
void py_parse_1(amount_t& amount, const std::string& str,
|
void py_parse_1(amount_t& amount, const std::string& str,
|
||||||
unsigned short flags) {
|
unsigned char flags) {
|
||||||
amount.parse(str, flags);
|
amount.parse(str, flags);
|
||||||
}
|
}
|
||||||
void py_parse_2(amount_t& amount, const std::string& str) {
|
void py_parse_2(amount_t& amount, const std::string& str) {
|
||||||
|
|
|
||||||
30
amount.h
30
amount.h
|
|
@ -249,8 +249,8 @@ class amount_t
|
||||||
#define AMOUNT_PARSE_NO_MIGRATE 0x01
|
#define AMOUNT_PARSE_NO_MIGRATE 0x01
|
||||||
#define AMOUNT_PARSE_NO_REDUCE 0x02
|
#define AMOUNT_PARSE_NO_REDUCE 0x02
|
||||||
|
|
||||||
void parse(std::istream& in, unsigned short flags = 0);
|
void parse(std::istream& in, unsigned char flags = 0);
|
||||||
void parse(const std::string& str, unsigned short flags = 0);
|
void parse(const std::string& str, unsigned char flags = 0);
|
||||||
void reduce();
|
void reduce();
|
||||||
|
|
||||||
void read_quantity(char *& data);
|
void read_quantity(char *& data);
|
||||||
|
|
@ -349,13 +349,13 @@ class commodity_base_t
|
||||||
|
|
||||||
typedef unsigned long ident_t;
|
typedef unsigned long ident_t;
|
||||||
|
|
||||||
ident_t ident;
|
ident_t ident;
|
||||||
std::string name;
|
std::string name;
|
||||||
std::string note;
|
std::string note;
|
||||||
unsigned short precision;
|
unsigned char precision;
|
||||||
unsigned short flags;
|
unsigned char flags;
|
||||||
amount_t * smaller;
|
amount_t * smaller;
|
||||||
amount_t * larger;
|
amount_t * larger;
|
||||||
|
|
||||||
commodity_base_t() : precision(0), flags(COMMODITY_STYLE_DEFAULTS),
|
commodity_base_t() : precision(0), flags(COMMODITY_STYLE_DEFAULTS),
|
||||||
history(NULL), smaller(NULL), larger(NULL) {}
|
history(NULL), smaller(NULL), larger(NULL) {}
|
||||||
|
|
@ -479,23 +479,23 @@ class commodity_t
|
||||||
ptr->note = arg;
|
ptr->note = arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned short precision() const {
|
unsigned char precision() const {
|
||||||
return ptr->precision;
|
return ptr->precision;
|
||||||
}
|
}
|
||||||
void set_precision(unsigned short arg) {
|
void set_precision(unsigned char arg) {
|
||||||
ptr->precision = arg;
|
ptr->precision = arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned short flags() const {
|
unsigned char flags() const {
|
||||||
return ptr->flags;
|
return ptr->flags;
|
||||||
}
|
}
|
||||||
void set_flags(unsigned short arg) {
|
void set_flags(unsigned char arg) {
|
||||||
ptr->flags = arg;
|
ptr->flags = arg;
|
||||||
}
|
}
|
||||||
void add_flags(unsigned short arg) {
|
void add_flags(unsigned char arg) {
|
||||||
ptr->flags |= arg;
|
ptr->flags |= arg;
|
||||||
}
|
}
|
||||||
void drop_flags(unsigned short arg) {
|
void drop_flags(unsigned char arg) {
|
||||||
ptr->flags &= ~arg;
|
ptr->flags &= ~arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
18
binary.cc
18
binary.cc
|
|
@ -12,9 +12,9 @@ namespace ledger {
|
||||||
|
|
||||||
static unsigned long binary_magic_number = 0xFFEED765;
|
static unsigned long binary_magic_number = 0xFFEED765;
|
||||||
#ifdef DEBUG_ENABLED
|
#ifdef DEBUG_ENABLED
|
||||||
static unsigned long format_version = 0x00020605;
|
static unsigned long format_version = 0x00020607;
|
||||||
#else
|
#else
|
||||||
static unsigned long format_version = 0x00020604;
|
static unsigned long format_version = 0x00020606;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static account_t ** accounts;
|
static account_t ** accounts;
|
||||||
|
|
@ -475,6 +475,8 @@ inline commodity_t * read_binary_commodity_annotated(char *& data)
|
||||||
read_binary_string(data, commodity->qualified_symbol);
|
read_binary_string(data, commodity->qualified_symbol);
|
||||||
commodity->annotated = true;
|
commodity->annotated = true;
|
||||||
|
|
||||||
|
commodity->base =
|
||||||
|
commodities[read_binary_long<commodity_t::ident_t>(data) - 1];
|
||||||
read_binary_amount(data, commodity->price);
|
read_binary_amount(data, commodity->price);
|
||||||
read_binary_long(data, commodity->date);
|
read_binary_long(data, commodity->date);
|
||||||
read_binary_string(data, commodity->tag);
|
read_binary_string(data, commodity->tag);
|
||||||
|
|
@ -998,6 +1000,7 @@ void write_binary_commodity_annotated(std::ostream& out,
|
||||||
annotated_commodity_t * ann_comm =
|
annotated_commodity_t * ann_comm =
|
||||||
static_cast<annotated_commodity_t *>(commodity);
|
static_cast<annotated_commodity_t *>(commodity);
|
||||||
|
|
||||||
|
write_binary_long(out, ann_comm->base->ident);
|
||||||
write_binary_amount(out, ann_comm->price);
|
write_binary_amount(out, ann_comm->price);
|
||||||
write_binary_long(out, ann_comm->date);
|
write_binary_long(out, ann_comm->date);
|
||||||
write_binary_string(out, ann_comm->tag);
|
write_binary_string(out, ann_comm->tag);
|
||||||
|
|
@ -1116,10 +1119,17 @@ void write_binary_journal(std::ostream& out, journal_t * journal)
|
||||||
for (commodities_map::const_iterator i = commodity_t::commodities.begin();
|
for (commodities_map::const_iterator i = commodity_t::commodities.begin();
|
||||||
i != commodity_t::commodities.end();
|
i != commodity_t::commodities.end();
|
||||||
i++) {
|
i++) {
|
||||||
write_binary_number<char>(out, (*i).second->annotated ? 1 : 0);
|
|
||||||
if (! (*i).second->annotated) {
|
if (! (*i).second->annotated) {
|
||||||
|
write_binary_number<char>(out, 0);
|
||||||
write_binary_commodity(out, (*i).second);
|
write_binary_commodity(out, (*i).second);
|
||||||
} else {
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (commodities_map::const_iterator i = commodity_t::commodities.begin();
|
||||||
|
i != commodity_t::commodities.end();
|
||||||
|
i++) {
|
||||||
|
if ((*i).second->annotated) {
|
||||||
|
write_binary_number<char>(out, 1);
|
||||||
write_binary_string(out, (*i).first); // the mapping key
|
write_binary_string(out, (*i).first); // the mapping key
|
||||||
write_binary_commodity_annotated(out, (*i).second);
|
write_binary_commodity_annotated(out, (*i).second);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
4
qif.cc
4
qif.cc
|
|
@ -115,8 +115,8 @@ unsigned int qif_parser_t::parse(std::istream& in,
|
||||||
get_line(in);
|
get_line(in);
|
||||||
xact->amount.parse(line);
|
xact->amount.parse(line);
|
||||||
|
|
||||||
unsigned long flags = xact->amount.commodity().flags();
|
unsigned char flags = xact->amount.commodity().flags();
|
||||||
unsigned short prec = xact->amount.commodity().precision();
|
unsigned char prec = xact->amount.commodity().precision();
|
||||||
|
|
||||||
if (! def_commodity) {
|
if (! def_commodity) {
|
||||||
def_commodity = commodity_t::find_or_create("$");
|
def_commodity = commodity_t::find_or_create("$");
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue