GnuCash  5.6-150-g038405b370+
gnc-tokenizer.hpp
Go to the documentation of this file.
1 /********************************************************************\
2  * gnc-tokenizer.hpp - base class for converting a text file into a *
3  * two-dimensional vector of strings (table) *
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 
35 #ifndef GNC_TOKENIZER_HPP
36 #define GNC_TOKENIZER_HPP
37 
38 #include <config.h>
39 
40 #include <iostream>
41 #include <fstream> // fstream
42 #include <vector>
43 #include <string>
44 #include <memory>
45 
46 using StrVec = std::vector<std::string>;
47 
49 enum class GncImpFileFormat {
50  UNKNOWN,
51  CSV,
52  FIXED_WIDTH
53 };
54 
55 class GncTokenizerTest;
56 
58 {
59 friend GncTokenizerTest;
60 public:
61  GncTokenizer() = default; // default constructor
62  GncTokenizer(const GncTokenizer&) = default; // copy constructor
63  GncTokenizer& operator=(const GncTokenizer&) = default; // copy assignment
64  GncTokenizer(GncTokenizer&&) = default; // move constructor
65  GncTokenizer& operator=(GncTokenizer&&) = default; // move assignment
66  virtual ~GncTokenizer() = default; // destructor
67 
68  virtual void load_file(const std::string& path);
69  const std::string& current_file();
70  void encoding(const std::string& encoding);
71  const std::string& encoding();
72  virtual int tokenize() = 0;
73  const std::vector<StrVec>& get_tokens();
74 
75 protected:
76  std::string m_utf8_contents;
77  std::vector<StrVec> m_tokenized_contents;
78 
79 private:
80  std::string m_imp_file_str;
81  std::string m_raw_contents;
82  std::string m_enc_str;
83 };
84 
85 
86 // Function to instantiate specializations of the GncTokenizer
87 std::unique_ptr<GncTokenizer> gnc_tokenizer_factory(GncImpFileFormat fmt);
88 
89 #endif
GncImpFileFormat
Enumeration for file formats supported by this importer.