summaryrefslogtreecommitdiff
path: root/src/commodity.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/commodity.h')
-rw-r--r--src/commodity.h239
1 files changed, 0 insertions, 239 deletions
diff --git a/src/commodity.h b/src/commodity.h
index c678293e..4bd5ee82 100644
--- a/src/commodity.h
+++ b/src/commodity.h
@@ -309,37 +309,9 @@ public:
return none;
}
- // Methods to exchange one commodity for another, while recording the
- // factored price.
-
- static void exchange(commodity_t& commodity,
- const amount_t& per_unit_cost,
- const datetime_t& moment);
-
- struct cost_breakdown_t {
- amount_t amount;
- amount_t final_cost;
- amount_t basis_cost;
- };
-
- static cost_breakdown_t exchange(const amount_t& amount,
- const amount_t& cost,
- const bool is_per_unit = false,
- const optional<datetime_t>& moment = none,
- const optional<string>& tag = none);
-
// Methods related to parsing, reading, writing, etc., the commodity
// itself.
- static optional<path> price_db;
- static long download_leeway;
- static bool download_quotes;
-
- static optional<price_point_t> parse_commodity_price(char * line);
-
- optional<price_point_t>
- download_quote(const optional<commodity_t&>& commodity = none) const;
-
static void parse_symbol(std::istream& in, string& symbol);
static void parse_symbol(char *& p, string& symbol);
static string parse_symbol(std::istream& in) {
@@ -365,221 +337,10 @@ inline std::ostream& operator<<(std::ostream& out, const commodity_t& comm) {
*
* Long.
*/
-struct annotation_t : public supports_flags<>,
- public equality_comparable<annotation_t>
-{
-#define ANNOTATION_PRICE_CALCULATED 0x01
-#define ANNOTATION_PRICE_FIXATED 0x02
-#define ANNOTATION_DATE_CALCULATED 0x04
-#define ANNOTATION_TAG_CALCULATED 0x08
-
- optional<amount_t> price;
- optional<date_t> date;
- optional<string> tag;
-
- explicit annotation_t(const optional<amount_t>& _price = none,
- const optional<date_t>& _date = none,
- const optional<string>& _tag = none)
- : supports_flags<>(), price(_price), date(_date), tag(_tag) {
- TRACE_CTOR(annotation_t, "const optional<amount_t>& + date_t + string");
- }
- annotation_t(const annotation_t& other)
- : supports_flags<>(other.flags()),
- price(other.price), date(other.date), tag(other.tag) {
- TRACE_CTOR(annotation_t, "copy");
- }
- ~annotation_t() {
- TRACE_DTOR(annotation_t);
- }
-
- operator bool() const {
- return price || date || tag;
- }
-
- bool operator==(const annotation_t& rhs) const {
- return (price == rhs.price &&
- date == rhs.date &&
- tag == rhs.tag);
- }
-
- void parse(std::istream& in);
-
- void print(std::ostream& out, bool keep_base = false) const;
-
- bool valid() const {
- assert(*this);
- return true;
- }
-};
-
-struct keep_details_t
-{
- bool keep_price;
- bool keep_date;
- bool keep_tag;
- bool only_actuals;
-
- explicit keep_details_t(bool _keep_price = false,
- bool _keep_date = false,
- bool _keep_tag = false,
- bool _only_actuals = false)
- : keep_price(_keep_price),
- keep_date(_keep_date),
- keep_tag(_keep_tag),
- only_actuals(_only_actuals)
- {
- TRACE_CTOR(keep_details_t, "bool, bool, bool, bool");
- }
- keep_details_t(const keep_details_t& other)
- : keep_price(other.keep_price), keep_date(other.keep_date),
- keep_tag(other.keep_tag), only_actuals(other.only_actuals) {
- TRACE_CTOR(keep_details_t, "copy");
- }
- ~keep_details_t() throw() {
- TRACE_DTOR(keep_details_t);
- }
-
- bool keep_all() const {
- return keep_price && keep_date && keep_tag && ! only_actuals;
- }
- bool keep_all(const commodity_t& comm) const {
- return (! comm.annotated ||
- (keep_price && keep_date && keep_tag && ! only_actuals));
- }
-
- bool keep_any() const {
- return keep_price || keep_date || keep_tag;
- }
- bool keep_any(const commodity_t& comm) const {
- return comm.annotated && (keep_price || keep_date || keep_tag);
- }
-};
-
-inline std::ostream& operator<<(std::ostream& out,
- const annotation_t& details) {
- details.print(out);
- return out;
-}
-
-/**
- * @brief Brief
- *
- * Long.
- */
-class annotated_commodity_t
- : public commodity_t,
- public equality_comparable<annotated_commodity_t,
- equality_comparable2<annotated_commodity_t, commodity_t,
- noncopyable> >
-{
-public:
- commodity_t * ptr;
- annotation_t details;
-
- explicit annotated_commodity_t(commodity_t * _ptr,
- const annotation_t& _details)
- : commodity_t(_ptr->parent_, _ptr->base), ptr(_ptr), details(_details) {
- TRACE_CTOR(annotated_commodity_t, "");
- annotated = true;
- }
- virtual ~annotated_commodity_t() {
- TRACE_DTOR(annotated_commodity_t);
- }
-
- virtual bool operator==(const commodity_t& comm) const;
- virtual bool operator==(const annotated_commodity_t& comm) const {
- return *this == static_cast<const commodity_t&>(comm);
- }
-
- virtual commodity_t& referent() {
- return *ptr;
- }
- virtual const commodity_t& referent() const {
- return *ptr;
- }
-
- virtual commodity_t& strip_annotations(const keep_details_t& what_to_keep);
- virtual void write_annotations(std::ostream& out) const;
-};
-
-inline annotated_commodity_t&
-as_annotated_commodity(commodity_t& commodity) {
- return downcast<annotated_commodity_t>(commodity);
-}
-inline const annotated_commodity_t&
-as_annotated_commodity(const commodity_t& commodity) {
- return downcast<const annotated_commodity_t>(commodity);
-}
-
-
-/**
- * @brief Brief
- *
- * Long.
- */
struct compare_amount_commodities {
bool operator()(const amount_t * left, const amount_t * right) const;
};
-/**
- * @brief Brief
- *
- * Long.
- */
-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.
- */
- typedef std::map<string, commodity_t *> commodities_map;
-
-public:
- commodities_map commodities;
-
- commodity_t * null_commodity;
- commodity_t * default_commodity;
-
- bool keep_base;
-
-public:
- boost::function<optional<amount_t>
- (commodity_t& commodity,
- const optional<datetime_t>& date,
- const optional<datetime_t>& moment,
- const optional<datetime_t>& last)> get_quote;
-
- explicit commodity_pool_t();
-
- ~commodity_pool_t() {
- TRACE_DTOR(commodity_pool_t);
- 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_or_create(const string& symbol);
-
- commodity_t * create(const string& symbol, const annotation_t& details);
- commodity_t * find(const string& symbol, const annotation_t& details);
- commodity_t * find_or_create(const string& symbol,
- const annotation_t& details);
-
- commodity_t * create(commodity_t& comm,
- const annotation_t& details,
- const string& mapping_key);
-
- commodity_t * find_or_create(commodity_t& comm,
- const annotation_t& details);
-
- commodity_t * parse_commodity_prices(const std::string& str,
- const bool add_prices = true,
- const optional<datetime_t>& moment = none);
-};
-
} // namespace ledger
#endif // _COMMODITY_H