GnuCash c935c2f+
Loading...
Searching...
No Matches
gnc-imp-props-price.hpp
1/********************************************************************\
2 * gnc-imp-props-price.hpp - encapsulate price properties for use *
3 * in the csv importer *
4 * *
5 * This program is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU General Public License as *
7 * published by the Free Software Foundation; either version 2 of *
8 * the License, or (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License*
16 * along with this program; if not, contact: *
17 * *
18 * Free Software Foundation Voice: +1-617-542-5942 *
19 * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
20 * Boston, MA 02110-1301, USA gnu@gnu.org *
21 * *
22\********************************************************************/
23
24#ifndef GNC_PRICE_PROPS_HPP
25#define GNC_PRICE_PROPS_HPP
26
27#include <platform.h>
28#if PLATFORM(WINDOWS)
29#include <windows.h>
30#endif
31
32#include <glib/gi18n.h>
33#include "gnc-pricedb.h"
34#include "gnc-commodity.h"
35
36#include <string>
37#include <map>
38#include <memory>
39#include <optional>
40#include <gnc-datetime.hpp>
41#include <gnc-numeric.hpp>
42
47enum class GncPricePropType {
48 NONE,
49 DATE,
50 AMOUNT,
51 FROM_SYMBOL,
52 FROM_NAMESPACE,
53 TO_CURRENCY,
54 PRICE_PROPS = TO_CURRENCY
55};
56
57enum Result { FAILED, ADDED, DUPLICATED, REPLACED };
58
63extern std::map<GncPricePropType, const char*> gnc_price_col_type_strs;
64
69{
70 test_price_prop_type_str( const char* name ) : m_name(name) {}
71 bool operator()( const std::pair<GncPricePropType, const char*>& v ) const
72 {
73 return !g_strcmp0(v.second, m_name);
74 }
75private:
76 const char *m_name;
77};
78
79gnc_commodity* parse_commodity_price_comm (const std::string& symbol_str, const std::string& namespace_str);
80bool parse_namespace (const std::string& namespace_str);
81GncNumeric parse_amount_price (const std::string &str, int currency_format);
82
84{
85public:
86 GncImportPrice (int date_format, int currency_format) : m_date_format{date_format},
87 m_currency_format{currency_format}{};
88
89 void set (GncPricePropType prop_type, const std::string& value, bool enable_test_empty);
90 void set_date_format (int date_format) { m_date_format = date_format ;}
91 void set_currency_format (int currency_format) { m_currency_format = currency_format ;}
92 void reset (GncPricePropType prop_type);
93 std::string verify_essentials (void);
94 Result create_price (QofBook* book, GNCPriceDB *pdb, bool over);
95
96 gnc_commodity* get_from_commodity () { if (m_from_commodity) return *m_from_commodity; else return nullptr; }
97 void set_from_commodity (gnc_commodity* comm) { if (comm) m_from_commodity = comm; else m_from_commodity.reset(); }
98
99 gnc_commodity* get_to_currency () { if (m_to_currency) return *m_to_currency; else return nullptr; }
100 void set_to_currency (gnc_commodity* curr) { if (curr) m_to_currency = curr; else m_to_currency.reset(); }
101
102 std::string errors();
103
104private:
105 int m_date_format;
106 int m_currency_format;
107 std::optional<GncDate> m_date;
108 std::optional<GncNumeric> m_amount;
109 std::optional<gnc_commodity*> m_from_commodity;
110 std::optional<std::string> m_from_namespace;
111 std::optional<std::string> m_from_symbol;
112 std::optional<gnc_commodity*> m_to_currency;
113
114 std::map<GncPricePropType, std::string> m_errors;
115};
116
117#endif
The primary numeric class for representing amounts and values.
Commodity handling public routines.
a simple price database for gnucash
QofBook reference.
Definition qofbook-p.hpp:47
Functor to check if the above map has an element of which the value equals name.