summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--amount.cc34
-rw-r--r--amount.h4
-rw-r--r--balance.cc34
3 files changed, 38 insertions, 34 deletions
diff --git a/amount.cc b/amount.cc
index 2040ffa8..251d3e7c 100644
--- a/amount.cc
+++ b/amount.cc
@@ -1729,6 +1729,40 @@ annotated_commodity_t::find_or_create(const commodity_t& comm,
return create(comm, price, date, tag, name);
}
+bool compare_amount_commodities::operator()(const amount_t * left,
+ const amount_t * right) const
+{
+ commodity_t& leftcomm(left->commodity());
+ commodity_t& rightcomm(right->commodity());
+
+ int cmp = leftcomm.base_symbol().compare(rightcomm.base_symbol());
+ if (cmp != 0)
+ return cmp < 0;
+
+ if (! leftcomm.annotated) {
+ assert(rightcomm.annotated);
+ return true;
+ }
+ else if (! rightcomm.annotated) {
+ assert(leftcomm.annotated);
+ return false;
+ }
+ else {
+ annotated_commodity_t& aleftcomm(static_cast<annotated_commodity_t&>(leftcomm));
+ annotated_commodity_t& arightcomm(static_cast<annotated_commodity_t&>(rightcomm));
+
+ amount_t val = aleftcomm.price - arightcomm.price;
+ if (val)
+ return val < 0;
+
+ int diff = aleftcomm.date - arightcomm.date;
+ if (diff)
+ return diff < 0;
+
+ return aleftcomm.tag < arightcomm.tag;
+ }
+}
+
} // namespace ledger
#ifdef USE_BOOST_PYTHON
diff --git a/amount.h b/amount.h
index b0712ca3..dfef8d06 100644
--- a/amount.h
+++ b/amount.h
@@ -606,6 +606,10 @@ class amount_error : public error {
virtual ~amount_error() throw() {}
};
+struct compare_amount_commodities {
+ bool operator()(const amount_t * left, const amount_t * right) const;
+};
+
} // namespace ledger
#endif // _AMOUNT_H
diff --git a/balance.cc b/balance.cc
index c67ca2de..86292781 100644
--- a/balance.cc
+++ b/balance.cc
@@ -88,40 +88,6 @@ balance_t balance_t::strip_annotations(const bool keep_price,
return temp;
}
-struct compare_amount_commodities {
- bool operator()(const amount_t * left, const amount_t * right) const {
- commodity_t& leftcomm(left->commodity());
- commodity_t& rightcomm(right->commodity());
-
- int cmp = leftcomm.symbol().compare(rightcomm.symbol());
- if (cmp != 0)
- return cmp < 0;
-
- if (! leftcomm.annotated) {
- assert(rightcomm.annotated);
- return true;
- }
- else if (! rightcomm.annotated) {
- assert(leftcomm.annotated);
- return false;
- }
- else {
- annotated_commodity_t& aleftcomm(static_cast<annotated_commodity_t&>(leftcomm));
- annotated_commodity_t& arightcomm(static_cast<annotated_commodity_t&>(rightcomm));
-
- amount_t val = aleftcomm.price - arightcomm.price;
- if (val)
- return val < 0;
-
- int diff = aleftcomm.date - arightcomm.date;
- if (diff)
- return diff < 0;
-
- return aleftcomm.tag < arightcomm.tag;
- }
- }
-};
-
void balance_t::write(std::ostream& out,
const int first_width,
const int latter_width) const