summaryrefslogtreecommitdiff
path: root/src/commodity.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-02-07 18:41:45 -0400
committerJohn Wiegley <johnw@newartisans.com>2009-02-07 18:41:45 -0400
commit08bc27ff0dae8183b540d30dd9c3fe3b3efffeda (patch)
treec33daf146d1ea50ab83128fe6ed55e0c7cd141ff /src/commodity.cc
parentf4c7f86e212b35c4221a1e46c7b720e94d244e71 (diff)
downloadfork-ledger-08bc27ff0dae8183b540d30dd9c3fe3b3efffeda.tar.gz
fork-ledger-08bc27ff0dae8183b540d30dd9c3fe3b3efffeda.tar.bz2
fork-ledger-08bc27ff0dae8183b540d30dd9c3fe3b3efffeda.zip
Removed commodity_pool_t's use of boost::multi_index_container, and also its
used of the ident membe, which was only ever used by the binary cache code.
Diffstat (limited to 'src/commodity.cc')
-rw-r--r--src/commodity.cc48
1 files changed, 13 insertions, 35 deletions
diff --git a/src/commodity.cc b/src/commodity.cc
index d651f8ae..ee441706 100644
--- a/src/commodity.cc
+++ b/src/commodity.cc
@@ -29,18 +29,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-/**
- * @file commodity.cc
- * @author John Wiegley
- * @date Thu Apr 26 15:19:46 2007
- *
- * @brief Types for dealing with commodities
- *
- * This file defines member functions for flavors of commodity_t.
- */
-
#include "amount.h"
-#include "token.h"
namespace ledger {
@@ -856,9 +845,11 @@ commodity_t * commodity_pool_t::create(const string& symbol)
DEBUG("amounts.commodities",
"Creating commodity '" << commodity->symbol() << "'");
- commodity->ident = commodities.size();
+ std::pair<commodities_map::iterator, bool> result
+ = commodities.insert(commodities_map::value_type(commodity->mapping_key(),
+ commodity.get()));
+ assert(result.second);
- commodities.push_back(commodity.get());
return commodity.release();
}
@@ -876,26 +867,10 @@ commodity_t * commodity_pool_t::find(const string& symbol)
{
DEBUG("amounts.commodities", "Find commodity " << symbol);
- typedef commodity_pool_t::commodities_t::nth_index<1>::type
- commodities_by_name;
-
- commodities_by_name& name_index = commodities.get<1>();
- commodities_by_name::const_iterator i = name_index.find(symbol);
- if (i != name_index.end())
- return *i;
- else
- return NULL;
-}
-
-commodity_t * commodity_pool_t::find(const commodity_t::ident_t ident)
-{
- DEBUG("amounts.commodities", "Find commodity by ident " << ident);
-
- typedef commodity_pool_t::commodities_t::nth_index<0>::type
- commodities_by_ident;
-
- commodities_by_ident& ident_index = commodities.get<0>();
- return ident_index[ident];
+ commodities_map::const_iterator i = commodities.find(symbol);
+ if (i != commodities.end())
+ return (*i).second;
+ return NULL;
}
commodity_t *
@@ -987,10 +962,13 @@ commodity_pool_t::create(commodity_t& comm,
// Add the fully annotated name to the map, so that this symbol may
// quickly be found again.
- commodity->ident = commodities.size();
commodity->mapping_key_ = mapping_key;
- commodities.push_back(commodity.get());
+ std::pair<commodities_map::iterator, bool> result
+ = commodities.insert(commodities_map::value_type(mapping_key,
+ commodity.get()));
+ assert(result.second);
+
return commodity.release();
}