GnuCash  5.6-150-g038405b370+
gnc-import-price.hpp
Go to the documentation of this file.
1 /********************************************************************\
2  * gnc-import-price.hpp - import prices from csv files *
3  * *
4  * This program is free software; you can redistribute it and/or *
5  * modify it under the terms of the GNU General Public License as *
6  * published by the Free Software Foundation; either version 2 of *
7  * the License, or (at your option) any later version. *
8  * *
9  * This program is distributed in the hope that it will be useful, *
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12  * GNU General Public License for more details. *
13  * *
14  * You should have received a copy of the GNU General Public License*
15  * along with this program; if not, contact: *
16  * *
17  * Free Software Foundation Voice: +1-617-542-5942 *
18  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
19  * Boston, MA 02110-1301, USA gnu@gnu.org *
20 \********************************************************************/
21 
30 #ifndef GNC_PRICE_IMPORT_HPP
31 #define GNC_PRICE_IMPORT_HPP
32 
33 #include "config.h"
34 #include "gnc-commodity.h"
35 
36 #include <vector>
37 #include <set>
38 #include <map>
39 #include <memory>
40 #include <optional>
41 #include <cstdint>
42 
43 #include "gnc-tokenizer.hpp"
44 #include "gnc-imp-props-price.hpp"
46 
47 /* A set of currency formats that the user sees. */
48 extern const int num_currency_formats_price;
49 extern const gchar* currency_format_user_price[];
50 
57  PL_INPUT,
58  PL_ERROR,
59  PL_PREPRICE,
60  PL_SKIP
61 };
62 
67 using parse_line_t = std::tuple<StrVec,
68  std::string,
69  std::shared_ptr<GncImportPrice>,
70  bool>;
71 struct ErrorListPrice;
72 
83 {
84 public:
85  // Constructor - Destructor
86  GncPriceImport(GncImpFileFormat format = GncImpFileFormat::UNKNOWN);
88 
89  void file_format(GncImpFileFormat format);
90  GncImpFileFormat file_format();
91 
92  void over_write (bool over);
93  bool over_write ();
94 
95  void from_commodity (gnc_commodity *from_commodity);
96  gnc_commodity *from_commodity ();
97 
98  void to_currency (gnc_commodity *to_currency);
99  gnc_commodity *to_currency ();
100 
101  void currency_format (int currency_format);
102  int currency_format ();
103 
104  void date_format (int date_format);
105  int date_format ();
106 
107  void encoding (const std::string& encoding);
108  std::string encoding ();
109 
110  void update_skipped_lines (std::optional<uint32_t> start, std::optional<uint32_t> end,
111  std::optional<bool> alt, std::optional<bool> errors);
112  uint32_t skip_start_lines ();
113  uint32_t skip_end_lines ();
114  bool skip_alt_lines ();
115  bool skip_err_lines ();
116 
117  void separators (std::string separators);
118  std::string separators ();
119 
120  void settings (const CsvPriceImpSettings& settings);
121  bool save_settings ();
122 
123  void settings_name (std::string name);
124  std::string settings_name ();
125 
126 
127  void load_file (const std::string& filename);
128 
129  void tokenize (bool guessColTypes);
130 
131  std::string verify();
132 
136  void create_prices ();
137  bool check_for_column_type (GncPricePropType type);
138  void set_column_type_price (uint32_t position, GncPricePropType type, bool force = false);
139  std::vector<GncPricePropType> column_types_price ();
140 
141  std::unique_ptr<GncTokenizer> m_tokenizer;
142  std::vector<parse_line_t> m_parsed_lines;
145  int m_prices_added;
146  int m_prices_duplicated;
147  int m_prices_replaced;
148 
149 private:
154  void create_price (std::vector<parse_line_t>::iterator& parsed_line);
155 
156  void verify_column_selections (ErrorListPrice& error_msg);
157 
158  /* Internal helper function to force reparsing of columns subject to format changes */
159  void reset_formatted_column (std::vector<GncPricePropType>& col_types);
160 
161  /* Two internal helper functions that should only be called from within
162  * set_column_type_price for consistency (otherwise error messages may not be (re)set)
163  */
164  void update_price_props (uint32_t row, uint32_t col, GncPricePropType prop_type);
165 
166  CsvPriceImpSettings m_settings;
167  bool m_skip_errors;
168  bool m_over_write;
169 };
170 
171 
172 #endif
void create_prices()
This function will attempt to convert all tokenized lines into prices using the column types the user...
GncPriceImport(GncImpFileFormat format=GncImpFileFormat::UNKNOWN)
Constructor for GncPriceImport.
The actual PriceImport class It&#39;s intended to use in the following sequence of actions: ...
~GncPriceImport()
Destructor for GncPriceImport.
parse_line_cols
An enum describing the columns found in a parse_line_t.
std::tuple< StrVec, std::string, std::shared_ptr< GncImportPrice >, bool > parse_line_t
Tuple to hold.
void tokenize(bool guessColTypes)
Splits a file into cells.
std::unique_ptr< GncTokenizer > m_tokenizer
Will handle file loading/encoding conversion/splitting into fields.
std::vector< parse_line_t > m_parsed_lines
source file parsed into a two-dimensional array of strings.
void to_currency(gnc_commodity *to_currency)
Sets a to currency.
Class convert a file into vector of string vectors.
GncImpFileFormat
Enumeration for file formats supported by this importer.
void from_commodity(gnc_commodity *from_commodity)
Sets a from commodity.
void file_format(GncImpFileFormat format)
Sets the file format for the file to import, which may cause the file to be reloaded as well if the p...
void load_file(const std::string &filename)
Loads a file into a GncPriceImport.
void encoding(const std::string &encoding)
Converts raw file data using a new encoding.
Commodity handling public routines.
CSV Import Settings.