summaryrefslogtreecommitdiff
path: root/constraint.h
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2004-07-30 23:42:59 -0400
committerJohn Wiegley <johnw@newartisans.com>2004-07-30 23:42:59 -0400
commit493694f84869190340a035e524c78d6a6a71bf6c (patch)
treee87ab37f98b0fe2ec05ef3da92b67710cad25a87 /constraint.h
parent94e76ae87e883291d13320738fe165c7a2a2415b (diff)
downloadfork-ledger-493694f84869190340a035e524c78d6a6a71bf6c.tar.gz
fork-ledger-493694f84869190340a035e524c78d6a6a71bf6c.tar.bz2
fork-ledger-493694f84869190340a035e524c78d6a6a71bf6c.zip
predicate are now used instead of constraints
Diffstat (limited to 'constraint.h')
-rw-r--r--constraint.h106
1 files changed, 41 insertions, 65 deletions
diff --git a/constraint.h b/constraint.h
index 79e01fc6..7ee77581 100644
--- a/constraint.h
+++ b/constraint.h
@@ -2,6 +2,7 @@
#define _CONSTRAINT_H
#include "ledger.h"
+#include "expr.h"
#include "item.h"
template <typename ForwardIterator, typename ValueType, typename Constraint>
@@ -60,96 +61,71 @@ class constrained_iterator
namespace ledger {
-class mask_t
-{
- public:
- bool exclude;
- std::string pattern;
- void * regexp;
-
- explicit mask_t(const std::string& pattern);
- mask_t(const mask_t&);
-
- ~mask_t();
-
- bool match(const std::string& str) const;
-};
-
-typedef std::list<mask_t> masks_list;
-
-bool matches(const masks_list& regexps, const std::string& str,
- bool * by_exclusion = NULL);
-
-
-struct node_t;
-
-enum periodicity_t {
- PERIOD_NONE,
- PERIOD_MONTHLY,
- PERIOD_WEEKLY_SUN,
- PERIOD_WEEKLY_MON
-};
-
class constraints_t
{
public:
- bool real_only;
- bool cleared_only;
- bool uncleared_only;
-
bool show_expanded;
bool show_related;
bool show_inverted;
bool show_subtotals;
bool show_empty;
- std::time_t begin_date;
- std::time_t end_date;
- struct std::tm date_mask;
- bool have_date_mask;
-
- masks_list payee_masks;
- masks_list account_masks;
-
- periodicity_t period;
- node_t * predicate;
- node_t * sort_order;
+ node_t * predicate;
explicit constraints_t() {
- real_only = false;
- cleared_only = false;
- uncleared_only = false;
-
show_expanded = false;
show_related = false;
show_inverted = false;
show_subtotals = true;
show_empty = false;
- begin_date = -1;
- end_date = -1;
- have_date_mask = false;
-
- period = PERIOD_NONE;
predicate = NULL;
- sort_order = NULL;
}
- ~constraints_t();
-
- std::time_t begin() const {
- return begin_date == -1 ? 0 : begin_date;
+ ~constraints_t() {
+ if (predicate) delete predicate;
}
- std::time_t end() const {
- return end_date == -1 ? std::time(NULL) : end_date;
+ bool operator ()(const transaction_t * xact) const {
+ if (! predicate) {
+ return true;
+ } else {
+ item_t temp;
+ temp.date = xact->entry->date;
+ temp.payee = xact->entry->payee;
+ temp.account = xact->account;
+ return predicate->compute(&temp);
+ }
}
- bool matches_date_range(const std::time_t date) const;
+ bool operator ()(const entry_t * entry) const {
+ if (! predicate) {
+ return true;
+ } else {
+ item_t temp;
+ temp.date = entry->date;
+ temp.payee = entry->payee;
+
+ // Although there may be conflicting account masks for the whole
+ // set of transactions -- for example, /rent/&!/expenses/, which
+ // might match one by not another transactions -- we let the
+ // entry through if at least one of the transactions meets the
+ // criterion
+
+ for (transactions_list::const_iterator i = entry->transactions.begin();
+ i != entry->transactions.end();
+ i++) {
+ temp.account = (*i)->account;
+ if (predicate->compute(&temp))
+ return true;
+ }
+ return false;
+ }
+ }
- bool operator ()(const transaction_t * xact) const;
- bool operator ()(const entry_t * entry) const;
- bool operator ()(const item_t * item) const;
+ bool operator ()(const item_t * item) const {
+ return ! predicate || predicate->compute(item);
+ }
};
typedef constrained_iterator<transactions_list::const_iterator, transaction_t *,