summaryrefslogtreecommitdiff
path: root/src/filters.h
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-03-16 04:02:56 -0400
committerJohn Wiegley <johnw@newartisans.com>2009-03-16 04:02:56 -0400
commitd0ea10f9a709de8f67b4c4eb1e763ab32309957f (patch)
tree4e968c574a1c84bbf23493b57bfe61e4ac852cf7 /src/filters.h
parent63080a727540e5168d6eb230e86d06ad390dc6c5 (diff)
parentf1523b5464924bf9d9987fce0cb3dbe4acda5a4b (diff)
downloadfork-ledger-d0ea10f9a709de8f67b4c4eb1e763ab32309957f.tar.gz
fork-ledger-d0ea10f9a709de8f67b4c4eb1e763ab32309957f.tar.bz2
fork-ledger-d0ea10f9a709de8f67b4c4eb1e763ab32309957f.zip
Rewrote the interval_t class
The purpose of this rewrite is to greatly simplify the code that walks through time periods, toward opening up the possibility in future of allowing exclusions and logically combined periods, such as "weekly except weekends". The new code is much simpler to use, as well as simpler internally, and yet is more robust at the same time.
Diffstat (limited to 'src/filters.h')
-rw-r--r--src/filters.h48
1 files changed, 24 insertions, 24 deletions
diff --git a/src/filters.h b/src/filters.h
index d3968c51..14b97c23 100644
--- a/src/filters.h
+++ b/src/filters.h
@@ -539,9 +539,8 @@ public:
clear_xacts_posts(xact_temps);
}
- void report_subtotal(const char * spec_fmt = NULL,
- const date_t& start = date_t(),
- const date_t& finish = date_t());
+ void report_subtotal(const char * spec_fmt = NULL,
+ const optional<date_interval_t>& interval = none);
virtual void flush() {
if (values.size() > 0)
@@ -558,22 +557,22 @@ public:
*/
class interval_posts : public subtotal_posts
{
- interval_t interval;
- post_t * last_post;
- account_t empty_account;
- bool exact_periods;
- bool generate_empty_posts;
- date_t start;
+ date_interval_t interval;
+ date_interval_t last_interval;
+ post_t * last_post;
+ account_t empty_account;
+ bool exact_periods;
+ bool generate_empty_posts;
interval_posts();
public:
- interval_posts(post_handler_ptr _handler,
- expr_t& amount_expr,
- const interval_t& _interval,
- bool _exact_periods = false,
- bool _generate_empty_posts = false)
+ interval_posts(post_handler_ptr _handler,
+ expr_t& amount_expr,
+ const date_interval_t& _interval,
+ bool _exact_periods = false,
+ bool _generate_empty_posts = false)
: subtotal_posts(_handler, amount_expr), interval(_interval),
last_post(NULL), empty_account(NULL, _("<None>")),
exact_periods(_exact_periods),
@@ -585,19 +584,20 @@ public:
TRACE_DTOR(interval_posts);
}
- void report_subtotal(const date_t& finish);
+ void report_subtotal(const date_interval_t& interval);
virtual void flush() {
- if (last_post && interval)
- report_subtotal(interval.increment(interval.begin) - gregorian::days(1));
- subtotal_posts::flush();
+ if (last_post && interval.duration) {
+ if (interval.is_valid())
+ report_subtotal(interval);
+ subtotal_posts::flush();
+ }
}
virtual void operator()(post_t& post);
};
class posts_as_equity : public subtotal_posts
{
- interval_t interval;
post_t * last_post;
account_t equity_account;
account_t * balance_account;
@@ -726,11 +726,11 @@ class generate_posts : public item_handler<post_t>
generate_posts();
protected:
- typedef std::pair<interval_t, post_t *> pending_posts_pair;
- typedef std::list<pending_posts_pair> pending_posts_list;
+ typedef std::pair<date_interval_t, post_t *> pending_posts_pair;
+ typedef std::list<pending_posts_pair> pending_posts_list;
pending_posts_list pending_posts;
- std::list<xact_t> xact_temps;
+ std::list<xact_t> xact_temps;
std::list<post_t> post_temps;
public:
@@ -746,7 +746,7 @@ public:
void add_period_xacts(period_xacts_list& period_xacts);
- virtual void add_post(const interval_t& period, post_t& post);
+ virtual void add_post(const date_interval_t& period, post_t& post);
};
/**
@@ -801,7 +801,7 @@ class forecast_posts : public generate_posts
TRACE_DTOR(forecast_posts);
}
- virtual void add_post(const interval_t& period, post_t& post);
+ virtual void add_post(const date_interval_t& period, post_t& post);
virtual void flush();
};