summaryrefslogtreecommitdiff
path: root/src/xact.h
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2008-09-19 08:06:20 -0400
committerJohn Wiegley <johnw@newartisans.com>2008-09-19 08:06:20 -0400
commitfdc7a4e4c5423e79df4ad8905b5a67d45d2f85bc (patch)
treeb7aa301f7d884315f00c42903778ea549e7833d7 /src/xact.h
parent43ba0bb03807eea3fdcd4dd40fba10b00f823e24 (diff)
downloadfork-ledger-fdc7a4e4c5423e79df4ad8905b5a67d45d2f85bc.tar.gz
fork-ledger-fdc7a4e4c5423e79df4ad8905b5a67d45d2f85bc.tar.bz2
fork-ledger-fdc7a4e4c5423e79df4ad8905b5a67d45d2f85bc.zip
Factored common parts of entry_t and xact_t into new item_t
Diffstat (limited to 'src/xact.h')
-rw-r--r--src/xact.h89
1 files changed, 29 insertions, 60 deletions
diff --git a/src/xact.h b/src/xact.h
index 91630481..01268fc3 100644
--- a/src/xact.h
+++ b/src/xact.h
@@ -32,8 +32,7 @@
#ifndef _XACT_H
#define _XACT_H
-#include "utils.h"
-#include "scope.h"
+#include "item.h"
namespace ledger {
@@ -43,90 +42,59 @@ class account_t;
class xact_t;
typedef std::list<xact_t *> xacts_list;
-class xact_t : public supports_flags<>, public scope_t
+class xact_t : public item_t
{
public:
-#define XACT_NORMAL 0x0000 // no flags at all, a basic transaction
-#define XACT_VIRTUAL 0x0001 // the account was specified with (parens)
-#define XACT_BALANCE 0x0002 // the account was specified with [brackets]
-#define XACT_AUTO 0x0004 // transaction created by automated entry
-#define XACT_IN_CACHE 0x0008 // transaction allocated by the binary cache
-#define XACT_CALCULATED 0x0010 // transaction's amount was auto-calculated
-#define XACT_GENERATED 0x0020 // transaction was not found in a journal
-#define XACT_TEMP 0x0040 // transaction is a temporary object
-
- enum state_t { UNCLEARED = 0, CLEARED, PENDING };
-
- entry_t * entry;
- account_t * account;
- state_t state;
+#define XACT_VIRTUAL 0x0100 // the account was specified with (parens)
+#define XACT_BALANCE 0x0200 // the account was specified with [brackets]
+#define XACT_AUTO 0x0400 // transaction created by automated entry
+#define XACT_CALCULATED 0x0800 // transaction's amount was auto-calculated
- optional<date_t> _date;
- optional<date_t> _date_eff;
- optional<string> note;
+ entry_t * entry; // only set for xacts of regular entries
+ account_t * account;
- amount_t amount;
+ amount_t amount; // can be null until finalization
optional<expr_t> amount_expr;
optional<amount_t> cost;
optional<expr_t> cost_expr;
optional<amount_t> assigned_amount;
optional<expr_t> assigned_amount_expr;
- istream_pos_type beg_pos;
- unsigned long beg_line;
- istream_pos_type end_pos;
- unsigned long end_line;
-
- static bool use_effective_date;
-
xact_t(account_t * _account = NULL,
- flags_t _flags = XACT_NORMAL)
- : supports_flags<>(_flags), entry(NULL), account(_account),
- state(UNCLEARED), beg_pos(0), beg_line(0), end_pos(0), end_line(0)
+ flags_t _flags = ITEM_NORMAL)
+ : item_t(_flags),
+ entry(NULL), account(_account)
{
TRACE_CTOR(xact_t, "account_t *, flags_t");
}
- xact_t(account_t * _account,
- const amount_t& _amount,
- flags_t _flags = XACT_NORMAL,
+ xact_t(account_t * _account,
+ const amount_t& _amount,
+ flags_t _flags = ITEM_NORMAL,
const optional<string>& _note = none)
- : supports_flags<>(_flags), entry(NULL), account(_account),
- state(UNCLEARED), note(_note), amount(_amount),
- beg_pos(0), beg_line(0), end_pos(0), end_line(0)
+ : item_t(_flags, _note),
+ entry(NULL), account(_account), amount(_amount)
{
- TRACE_CTOR(xact_t,
- "account_t *, const amount_t&, flags_t, const string&");
+ TRACE_CTOR(xact_t, "account_t *, const amount_t&, flags_t, const optional<string>&");
}
xact_t(const xact_t& xact)
- : supports_flags<>(xact),
- scope_t(),
+ : item_t(xact),
entry(xact.entry),
account(xact.account),
- state(xact.state),
- _date(xact._date),
- _date_eff(xact._date_eff),
- note(xact.note),
amount(xact.amount),
cost(xact.cost),
- beg_pos(xact.beg_pos),
- beg_line(xact.beg_line),
- end_pos(xact.end_pos),
- end_line(xact.end_line),
xdata_(xact.xdata_) // jww (2008-07-19): What are the copy semantics?
{
TRACE_CTOR(xact_t, "copy");
}
- ~xact_t();
-
- date_t actual_date() const;
- date_t effective_date() const;
- date_t date() const {
- if (use_effective_date)
- return effective_date();
- else
- return actual_date();
+ ~xact_t() {
+ TRACE_DTOR(xact_t);
}
+ virtual optional<date_t> actual_date() const;
+ virtual optional<date_t> effective_date() const;
+
+ virtual state_t state() const;
+
bool must_balance() const {
return ! has_flags(XACT_VIRTUAL) || has_flags(XACT_BALANCE);
}
@@ -221,8 +189,7 @@ public:
date_t reported_date() const {
if (xdata_ && is_valid(xdata_->date))
return xdata_->date;
- return
- date();
+ return *date();
}
account_t * reported_account() {
@@ -235,6 +202,8 @@ public:
const account_t * reported_account() const {
return const_cast<xact_t *>(this)->reported_account();
}
+
+ friend class entry_t;
};
} // namespace ledger