From 4518ea95408e2d5fe90a87159b88bb41734ec1dc Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Tue, 29 Jul 2008 05:10:16 -0400 Subject: Value expression architecture is now rewritten, but the functionality of the old system (for example, the meaning of 'a') has yet to be restored. In the new scheme, this will be done by definition a function outside of the value expression logic, rather than the tight coupling between journal innards and value expressions that occurred in 2.x. --- journal.h | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 56 insertions(+), 5 deletions(-) (limited to 'journal.h') diff --git a/journal.h b/journal.h index c5a58d74..2248714e 100644 --- a/journal.h +++ b/journal.h @@ -34,8 +34,8 @@ #include "amount.h" #include "value.h" -#include "valexpr.h" -#include "utils.h" +#include "expr.h" +#include "predicate.h" namespace ledger { @@ -62,9 +62,9 @@ class transaction_t : public supports_flags<> optional _date; optional _date_eff; amount_t amount; - value_expr amount_expr; + expr_t amount_expr; optional cost; - optional cost_expr; + optional cost_expr; optional note; istream_pos_type beg_pos; unsigned long beg_line; @@ -452,7 +452,7 @@ class session_t; class journal_t : public noncopyable { - public: +public: session_t * owner; account_t * master; account_t * basket; @@ -488,6 +488,57 @@ class journal_t : public noncopyable } bool valid() const; + +/** + * @class journal_t::parser_t + * + * @brief Provides an abstract interface for writing journal parsers. + * + * Any data format for Ledger data is possible, as long as it can be parsed + * into a journal_t data tree. This class provides the basic interface which + * must be implemented by every such journal parser. + */ + class parser_t : public noncopyable + { + public: + parser_t() { + TRACE_CTOR(parser_t, ""); + } + virtual ~parser_t() { + TRACE_DTOR(parser_t); + } + + virtual bool test(std::istream& in) const = 0; + + virtual unsigned int parse(std::istream& in, + session_t& session, + journal_t& journal, + account_t * master = NULL, + const path * original_file = NULL) = 0; + }; + + class binary_parser_t : public parser_t + { + public: + virtual bool test(std::istream& in) const; + + virtual unsigned int parse(std::istream& in, + session_t& session, + journal_t& journal, + account_t * master = NULL, + const path * original_file = NULL); + }; + + unsigned int read(std::istream& in, const path& file, account_t * master); + void write(std::ostream& out); + + class parse_error : public error + { + public: + parse_error(const string& reason, error_context * ctxt = NULL) throw() + : error(reason, ctxt) {} + virtual ~parse_error() throw() {} + }; }; inline void extend_entry_base(journal_t * journal, entry_base_t& entry, -- cgit v1.2.3