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.
This commit is contained in:
parent
f4c7f86e21
commit
08bc27ff0d
2 changed files with 25 additions and 87 deletions
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -175,17 +175,14 @@ public:
|
|||
public:
|
||||
static bool symbol_needs_quotes(const string& symbol);
|
||||
|
||||
typedef base_t::history_t history_t;
|
||||
typedef base_t::history_map history_map;
|
||||
typedef base_t::varied_history_t varied_history_t;
|
||||
typedef uint_least32_t ident_t;
|
||||
|
||||
typedef base_t::history_t history_t;
|
||||
typedef base_t::history_map history_map;
|
||||
typedef base_t::varied_history_t varied_history_t;
|
||||
typedef base_t::history_by_commodity_map history_by_commodity_map;
|
||||
|
||||
shared_ptr<base_t> base;
|
||||
|
||||
commodity_pool_t * parent_;
|
||||
ident_t ident;
|
||||
optional<string> qualified_symbol;
|
||||
optional<string> mapping_key_;
|
||||
bool annotated;
|
||||
|
|
@ -556,55 +553,22 @@ struct compare_amount_commodities {
|
|||
class commodity_pool_t : public noncopyable
|
||||
{
|
||||
/**
|
||||
* The commodities collection in commodity_pool_t maintains pointers
|
||||
* to all the commodities which have ever been created by the user,
|
||||
* whether explicitly by calling the create methods of
|
||||
* commodity_pool_t, or implicitly by parsing a commoditized amount.
|
||||
*
|
||||
* The `commodities' member variable represents a collection which
|
||||
* is indexed by two vertices: first, and ordered sequence of unique
|
||||
* integer which identify commodities by a numerical identifier; and
|
||||
* second, by a hashed set of symbolic names which reflect how the
|
||||
* commodity was referred to by the user.
|
||||
* The commodities collection in commodity_pool_t maintains pointers to all
|
||||
* the commodities which have ever been created by the user, whether
|
||||
* explicitly by calling the create methods of commodity_pool_t, or
|
||||
* implicitly by parsing a commoditized amount.
|
||||
*/
|
||||
typedef multi_index_container<
|
||||
commodity_t *,
|
||||
multi_index::indexed_by<
|
||||
multi_index::random_access<>,
|
||||
multi_index::hashed_unique<
|
||||
multi_index::const_mem_fun<commodity_t,
|
||||
string, &commodity_t::mapping_key> >
|
||||
>
|
||||
> commodities_t;
|
||||
typedef std::map<string, commodity_t *> commodities_map;
|
||||
|
||||
public:
|
||||
typedef commodity_pool_t::commodities_t::nth_index<0>::type
|
||||
commodities_by_ident;
|
||||
|
||||
commodities_t commodities;
|
||||
commodities_map commodities;
|
||||
|
||||
commodity_t * null_commodity;
|
||||
commodity_t * default_commodity;
|
||||
|
||||
private:
|
||||
template<typename T>
|
||||
struct first_initialized
|
||||
{
|
||||
typedef T result_type;
|
||||
|
||||
template<typename InputIterator>
|
||||
T operator()(InputIterator first, InputIterator last) const
|
||||
{
|
||||
for (; first != last; first++)
|
||||
if (*first)
|
||||
return *first;
|
||||
return T();
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
boost::function<optional<amount_t>
|
||||
(commodity_t& commodity,
|
||||
(commodity_t& commodity,
|
||||
const optional<datetime_t>& date,
|
||||
const optional<datetime_t>& moment,
|
||||
const optional<datetime_t>& last)> get_quote;
|
||||
|
|
@ -613,16 +577,12 @@ public:
|
|||
|
||||
~commodity_pool_t() {
|
||||
TRACE_DTOR(commodity_pool_t);
|
||||
commodities_by_ident& ident_index = commodities.get<0>();
|
||||
for (commodities_by_ident::iterator i = ident_index.begin();
|
||||
i != ident_index.end();
|
||||
i++)
|
||||
checked_delete(*i);
|
||||
foreach (commodities_map::value_type pair, commodities)
|
||||
checked_delete(pair.second);
|
||||
}
|
||||
|
||||
commodity_t * create(const string& symbol);
|
||||
commodity_t * find(const string& name);
|
||||
commodity_t * find(const commodity_t::ident_t ident);
|
||||
commodity_t * find_or_create(const string& symbol);
|
||||
|
||||
commodity_t * create(const string& symbol, const annotation_t& details);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue