summaryrefslogtreecommitdiff
path: root/src/annotate.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/annotate.h')
-rw-r--r--src/annotate.h62
1 files changed, 46 insertions, 16 deletions
diff --git a/src/annotate.h b/src/annotate.h
index 3c6db8e8..044ebc4d 100644
--- a/src/annotate.h
+++ b/src/annotate.h
@@ -46,29 +46,39 @@
#ifndef _ANNOTATE_H
#define _ANNOTATE_H
+#include "expr.h"
+
namespace ledger {
struct annotation_t : public supports_flags<>,
public equality_comparable<annotation_t>
{
-#define ANNOTATION_PRICE_CALCULATED 0x01
-#define ANNOTATION_PRICE_FIXATED 0x02
-#define ANNOTATION_DATE_CALCULATED 0x04
-#define ANNOTATION_TAG_CALCULATED 0x08
+#define ANNOTATION_PRICE_CALCULATED 0x01
+#define ANNOTATION_PRICE_FIXATED 0x02
+#define ANNOTATION_PRICE_NOT_PER_UNIT 0x04
+#define ANNOTATION_DATE_CALCULATED 0x08
+#define ANNOTATION_TAG_CALCULATED 0x10
+#define ANNOTATION_VALUE_EXPR_CALCULATED 0x20
optional<amount_t> price;
optional<date_t> date;
optional<string> tag;
-
- explicit annotation_t(const optional<amount_t>& _price = none,
- const optional<date_t>& _date = none,
- const optional<string>& _tag = none)
- : supports_flags<>(), price(_price), date(_date), tag(_tag) {
- TRACE_CTOR(annotation_t, "const optional<amount_t>& + date_t + string");
+ optional<expr_t> value_expr;
+
+ explicit annotation_t(const optional<amount_t>& _price = none,
+ const optional<date_t>& _date = none,
+ const optional<string>& _tag = none,
+ const optional<expr_t>& _value_expr = none)
+ : supports_flags<>(), price(_price), date(_date), tag(_tag),
+ value_expr(_value_expr) {
+ TRACE_CTOR(annotation_t,
+ "const optional<amount_t>& + date_t + string + expr_t");
}
annotation_t(const annotation_t& other)
: supports_flags<>(other.flags()),
- price(other.price), date(other.date), tag(other.tag) {
+ price(other.price), date(other.date), tag(other.tag),
+ value_expr(other.value_expr)
+ {
TRACE_CTOR(annotation_t, "copy");
}
~annotation_t() {
@@ -76,17 +86,20 @@ struct annotation_t : public supports_flags<>,
}
operator bool() const {
- return price || date || tag;
+ return price || date || tag || value_expr;
}
+ bool operator<(const annotation_t& rhs) const;
bool operator==(const annotation_t& rhs) const {
- return (price == rhs.price &&
- date == rhs.date &&
- tag == rhs.tag);
+ return (price == rhs.price &&
+ date == rhs.date &&
+ tag == rhs.tag &&
+ (value_expr && rhs.value_expr ?
+ value_expr->text() == rhs.value_expr->text() :
+ value_expr == rhs.value_expr));
}
void parse(std::istream& in);
-
void print(std::ostream& out, bool keep_base = false,
bool no_computed_annotations = false) const;
@@ -132,6 +145,12 @@ inline void to_xml(std::ostream& out, const annotation_t& details)
push_xml y(out, "tag");
out << y.guard(*details.tag);
}
+
+ if (details.value_expr)
+ {
+ push_xml y(out, "value-expr");
+ out << y.guard(details.value_expr->text());
+ }
}
struct keep_details_t
@@ -230,6 +249,17 @@ public:
return *ptr;
}
+ virtual optional<expr_t> value_expr() const {
+ if (details.value_expr)
+ return details.value_expr;
+ return commodity_t::value_expr();
+ }
+
+ optional<price_point_t>
+ virtual find_price(const commodity_t * commodity = NULL,
+ const datetime_t& moment = datetime_t(),
+ const datetime_t& oldest = datetime_t()) const;
+
virtual commodity_t& strip_annotations(const keep_details_t& what_to_keep);
virtual void write_annotations(std::ostream& out,
bool no_computed_annotations = false) const;