summaryrefslogtreecommitdiff
path: root/format.h
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2004-07-30 21:57:02 -0400
committerJohn Wiegley <johnw@newartisans.com>2004-07-30 21:57:02 -0400
commit94e76ae87e883291d13320738fe165c7a2a2415b (patch)
treeb90eff2ee3737ecdfea96dbee52ecd239fcb2578 /format.h
parent5087a60deef7c618a07562511e9a1fbf2414776c (diff)
downloadfork-ledger-94e76ae87e883291d13320738fe165c7a2a2415b.tar.gz
fork-ledger-94e76ae87e883291d13320738fe165c7a2a2415b.tar.bz2
fork-ledger-94e76ae87e883291d13320738fe165c7a2a2415b.zip
two major changes
Complete changed the way format strings are handled. They are now compiled first, which is far more efficient than what was being done before. Also, there is now a global ledger::commodity_t::commodities map, which saves me from having to pass the current journal around to a zillion different functions, for the sole purpose of making sure that all commodity symbols that are parsed refer to the same commodity object.
Diffstat (limited to 'format.h')
-rw-r--r--format.h85
1 files changed, 59 insertions, 26 deletions
diff --git a/format.h b/format.h
index 298715cb..33443508 100644
--- a/format.h
+++ b/format.h
@@ -11,56 +11,89 @@ namespace ledger {
std::string truncated(const std::string& str, unsigned int width);
std::string maximal_account_name(const item_t * item, const item_t * parent);
-struct format_t
+struct element_t
{
- std::string format_string;
- node_t * value_style;
- node_t * total_style;
+ enum kind_t {
+ STRING,
+ VALUE_EXPR,
+ DATE_STRING,
+ PAYEE,
+ ACCOUNT_NAME,
+ ACCOUNT_FULLNAME,
+ VALUE,
+ TOTAL,
+ SPACER
+ };
+
+ bool align_left;
+ unsigned int min_width;
+ unsigned int max_width;
+
+ kind_t type;
+ std::string chars;
+ node_t * val_expr;
+
+ struct element_t * next;
- format_t() {
- value_style = NULL;
- total_style = NULL;
+ element_t() : align_left(false), min_width(0), max_width(0),
+ type(STRING), val_expr(NULL), next(NULL) {}
+
+ ~element_t() {
+ if (val_expr) delete val_expr;
+ if (next) delete next; // recursive, but not too deep
}
+};
+
+struct format_t
+{
+ element_t * elements;
+ static node_t * value_expr;
+ static node_t * total_expr;
+
+ format_t(const std::string& _format) {
+ elements = parse_elements(_format);
+ }
~format_t() {
- if (value_style) delete value_style;
- if (total_style) delete total_style;
+ if (elements) delete elements;
}
+ static element_t * parse_elements(const std::string& fmt);
+
+ void format_elements(std::ostream& out, const item_t * item,
+ const item_t * displayed_parent = NULL) const;
+
#if 1
- balance_t compute_value(const item_t * item) const {
- if (value_style)
- return value_style->compute(item);
+ static balance_t compute_value(const item_t * item) {
+ if (value_expr)
+ return value_expr->compute(item);
else
return balance_t();
}
- balance_t compute_total(const item_t * item) const {
- if (total_style)
- return total_style->compute(item);
+ static balance_t compute_total(const item_t * item) {
+ if (total_expr)
+ return total_expr->compute(item);
else
return balance_t();
}
#else
- balance_t compute_value(const item_t * item,
- const constraints_t& constraints) const {
- if (value_style)
- return value_style->compute(item, constraints.begin(), constraints.end());
+ static balance_t compute_value(const item_t * item,
+ const constraints_t& constraints) {
+ if (value_expr)
+ return value_expr->compute(item, constraints.begin(), constraints.end());
else
return balance_t();
}
- balance_t compute_total(const item_t * item,
- const constraints_t& constraints) const {
- if (total_style)
- return total_style->compute(item, constraints.begin(), constraints.end());
+ static balance_t compute_total(const item_t * item,
+ const constraints_t& constraints) {
+ if (total_expr)
+ return total_expr->compute(item, constraints.begin(), constraints.end());
else
return balance_t();
}
#endif
-
- std::string report_line(const item_t * item,
- const item_t * displayed_parent = NULL) const;
};
} // namespace ledger