Loading...
Searching...
No Matches
pool.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2003-2023, John Wiegley. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * - Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * - Neither the name of New Artisans LLC nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
46#pragma once
47
48#include "history.h"
49#include "annotate.h"
50
51namespace ledger {
52
59
60class commodity_pool_t : public noncopyable
61{
62public:
69 typedef std::map<string, shared_ptr<commodity_t> > commodities_map;
70 typedef std::map<std::pair<string, annotation_t>,
71 shared_ptr<annotated_commodity_t> > annotated_commodities_map;
72
78
79 bool keep_base; // --base
80 optional<path> price_db; // --price-db=
81 long quote_leeway; // --leeway=
82 bool get_quotes; // --download
83
85 (commodity_t& commodity, const commodity_t * in_terms_of)>
87
89
90 explicit commodity_pool_t();
94
95 commodity_t * create(const string& symbol);
96 commodity_t * find(const string& name);
97 commodity_t * find_or_create(const string& symbol);
98 commodity_t * alias(const string& name, commodity_t& referent);
99
100 commodity_t * create(const string& symbol,
101 const annotation_t& details);
102 commodity_t * find(const string& symbol,
103 const annotation_t& details);
104 commodity_t * find_or_create(const string& symbol,
105 const annotation_t& details);
107
109 const annotation_t& details);
110
111 // Exchange one commodity for another, while recording the factored price.
112
113 void exchange(commodity_t& commodity,
114 const amount_t& per_unit_cost,
115 const datetime_t& moment);
116
118 const amount_t& cost,
119 const bool is_per_unit = false,
120 const bool add_price = true,
122 const optional<string>& tag = none);
123
124 // Parse commodity prices from a textual representation
125
128 bool no_date = false);
129
131 parse_price_expression(const std::string& str,
132 const bool add_prices = true,
134};
135
136} // namespace ledger
#define TRACE_DTOR(cls)
Definition utils.h:144
Types for annotating commodities.
Types for managing commodity historys.
T & downcast(U &object)
Definition utils.h:468
boost::posix_time::ptime datetime_t
Definition times.h:53
Encapsulate infinite-precision commoditized amounts.
Definition amount.h:96
amount_t final_cost
Definition pool.h:56
amount_t basis_cost
Definition pool.h:57
commodity_t * create(const string &symbol, const annotation_t &details)
commodity_t * find(const string &name)
commodities_map commodities
Definition pool.h:73
static shared_ptr< commodity_pool_t > current_pool
Definition pool.h:88
commodity_t * default_commodity
Definition pool.h:77
std::map< string, shared_ptr< commodity_t > > commodities_map
The commodities collection in commodity_pool_t maintains pointers to all the commodities which have e...
Definition pool.h:69
commodity_t * find(const string &symbol, const annotation_t &details)
cost_breakdown_t exchange(const amount_t &amount, const amount_t &cost, const bool is_per_unit=false, const bool add_price=true, const optional< datetime_t > &moment=none, const optional< string > &tag=none)
commodity_t * null_commodity
Definition pool.h:76
commodity_t * alias(const string &name, commodity_t &referent)
void exchange(commodity_t &commodity, const amount_t &per_unit_cost, const datetime_t &moment)
function< optional< price_point_t >(commodity_t &commodity, const commodity_t *in_terms_of) get_commodity_quote)
Definition pool.h:86
commodity_history_t commodity_price_history
Definition pool.h:75
optional< path > price_db
Definition pool.h:80
annotated_commodities_map annotated_commodities
Definition pool.h:74
commodity_t * find_or_create(commodity_t &comm, const annotation_t &details)
virtual ~commodity_pool_t()
Definition pool.h:91
commodity_t * find_or_create(const string &symbol, const annotation_t &details)
commodity_t * create(const string &symbol)
commodity_t * find_or_create(const string &symbol)
std::map< std::pair< string, annotation_t >, shared_ptr< annotated_commodity_t > > annotated_commodities_map
Definition pool.h:71
commodity_t * parse_price_expression(const std::string &str, const bool add_prices=true, const optional< datetime_t > &moment=none)
optional< std::pair< commodity_t *, price_point_t > > parse_price_directive(char *line, bool do_not_add_price=false, bool no_date=false)
annotated_commodity_t * create(commodity_t &comm, const annotation_t &details)