diff options
author | John Wiegley <johnw@newartisans.com> | 2009-11-09 01:24:44 -0500 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-11-09 02:06:08 -0500 |
commit | fb8be53edb9d9fdd91fd906e9a4ce6c3e8e3adb3 (patch) | |
tree | e1e41cd4e926ad108743f29158b4ef8e451b90f5 /src/format.h | |
parent | c3535d06c89732a0ba4c13274702b0f48198ae79 (diff) | |
download | fork-ledger-fb8be53edb9d9fdd91fd906e9a4ce6c3e8e3adb3.tar.gz fork-ledger-fb8be53edb9d9fdd91fd906e9a4ce6c3e8e3adb3.tar.bz2 fork-ledger-fb8be53edb9d9fdd91fd906e9a4ce6c3e8e3adb3.zip |
Redesigned the format_t class
Diffstat (limited to 'src/format.h')
-rw-r--r-- | src/format.h | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/src/format.h b/src/format.h index 8043594b..516b6d7e 100644 --- a/src/format.h +++ b/src/format.h @@ -50,20 +50,20 @@ class unistring; DECLARE_EXCEPTION(format_error, std::runtime_error); -class format_t : public noncopyable +class format_t : public expr_base_t<string> { + typedef expr_base_t<string> base_type; + struct element_t : public supports_flags<> { #define ELEMENT_ALIGN_LEFT 0x01 enum kind_t { STRING, EXPR }; - kind_t type; - std::size_t min_width; - std::size_t max_width; - string chars; - expr_t expr; - + kind_t type; + std::size_t min_width; + std::size_t max_width; + variant<string, expr_t> data; scoped_ptr<struct element_t> next; element_t() throw() @@ -83,8 +83,7 @@ class format_t : public noncopyable type = elem.type; min_width = elem.min_width; max_width = elem.max_width; - chars = elem.chars; - expr = elem.expr; + data = elem.data; } return *this; } @@ -124,25 +123,28 @@ private: const optional<format_t&>& tmpl); public: - format_t() { + format_t() : base_type() { TRACE_CTOR(format_t, ""); } - format_t(const string& _format) { + format_t(const string& _str, scope_t * context = NULL) + : base_type(context) { TRACE_CTOR(format_t, "const string&"); - parse(_format); + if (! _str.empty()) + parse_format(_str); } ~format_t() { TRACE_DTOR(format_t); } - void parse(const string& _format, const optional<format_t&>& tmpl = none) { + void parse_format(const string& _format, + const optional<format_t&>& tmpl = none) { elements.reset(parse_elements(_format, tmpl)); - format_string = _format; + set_text(_format); } - void format(std::ostream& out, scope_t& scope); + virtual result_type real_calc(scope_t& scope); - void dump(std::ostream& out) const { + virtual void dump(std::ostream& out) const { for (const element_t * elem = elements.get(); elem; elem = elem->next.get()) @@ -154,12 +156,6 @@ public: const std::size_t account_abbrev_length = 0); }; -#define FMT_PREFIX "fmt_" -#define FMT_PREFIX_LEN 4 - -#define WANT_FMT() \ - (std::strncmp(p, FMT_PREFIX, FMT_PREFIX_LEN) == 0) - } // namespace ledger #endif // _FORMAT_H |