From e5885cc8a8a1d6cd2a65d04c56ba86d65317f4a1 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Mon, 5 Mar 2012 17:47:12 -0600 Subject: Added annotation_t::operator<() --- src/annotate.cc | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/annotate.cc') diff --git a/src/annotate.cc b/src/annotate.cc index cd1733ca..1e243beb 100644 --- a/src/annotate.cc +++ b/src/annotate.cc @@ -38,6 +38,34 @@ namespace ledger { +bool annotation_t::operator<(const annotation_t& rhs) const +{ + if (! price && rhs.price) return true; + if (price && ! rhs.price) return false; + if (! date && rhs.date) return true; + if (date && ! rhs.date) return false; + if (! tag && rhs.tag) return true; + if (tag && ! rhs.tag) return false; + + if (price) { + if (price->commodity().symbol() < rhs.price->commodity().symbol()) + return true; + if (price->commodity().symbol() > rhs.price->commodity().symbol()) + return false; + if (*price < *rhs.price) return true; + if (*price > *rhs.price) return false; + } + if (date) { + if (*date < *rhs.date) return true; + if (*date > *rhs.date) return false; + } + if (tag) { + if (*tag < *rhs.tag) return true; + if (*tag > *rhs.tag) return false; + } + return false; +} + void annotation_t::parse(std::istream& in) { do { -- cgit v1.2.3