Added annotation_t::operator<()

This commit is contained in:
John Wiegley 2012-03-05 17:47:12 -06:00
parent f9de33d21c
commit e5885cc8a8
2 changed files with 29 additions and 0 deletions

View file

@ -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 {

View file

@ -79,6 +79,7 @@ struct annotation_t : public supports_flags<>,
return price || date || tag;
}
bool operator<(const annotation_t& rhs) const;
bool operator==(const annotation_t& rhs) const {
return (price == rhs.price &&
date == rhs.date &&