diff options
author | John Wiegley <johnw@newartisans.com> | 2009-06-18 18:50:49 +0100 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-06-18 18:50:49 +0100 |
commit | 86dfc1e0be5dbfab195cba8a8be31d3dbf0f68c9 (patch) | |
tree | 55965512c0a1abf8f4bbb1519817c7b96fdcab12 /src/value.cc | |
parent | 1dc21c2d344aa52833e516fea831ff45d8bf7aa1 (diff) | |
download | fork-ledger-86dfc1e0be5dbfab195cba8a8be31d3dbf0f68c9.tar.gz fork-ledger-86dfc1e0be5dbfab195cba8a8be31d3dbf0f68c9.tar.bz2 fork-ledger-86dfc1e0be5dbfab195cba8a8be31d3dbf0f68c9.zip |
The -X option now accepts price settings
For example, if you had 100 AU (onces of gold) and wanted to report it
in dollars, but at a price of $997 per ounce, you could now easily say:
ledger bal -X '$,AU=$997'
Diffstat (limited to 'src/value.cc')
-rw-r--r-- | src/value.cc | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/value.cc b/src/value.cc index 6f6e665d..7fa9866f 100644 --- a/src/value.cc +++ b/src/value.cc @@ -1228,6 +1228,27 @@ value_t value_t::value(const bool primary_only, return NULL_VALUE; } +value_t value_t::exchange_commodities(const std::string& commodities, + const bool add_prices, + const optional<datetime_t>& moment) +{ + scoped_array<char> buf(new char[commodities.length() + 1]); + + std::strcpy(buf.get(), commodities.c_str()); + + for (char * p = std::strtok(buf.get(), ","); + p; + p = std::strtok(NULL, ",")) { + if (commodity_t * commodity = + amount_t::current_pool->parse_commodity_prices(p, add_prices, moment)) { + value_t result = value(false, moment, *commodity); + if (! result.is_null()) + return result; + } + } + return *this; +} + void value_t::in_place_reduce() { switch (type()) { |