GnuCash
5.6-150-g038405b370+
|
The actual TxImport class It's intended to use in the following sequence of actions: More...
#include <gnc-import-tx.hpp>
Public Member Functions | |
GncTxImport (GncImpFileFormat format=GncImpFileFormat::UNKNOWN) | |
Constructor for GncTxImport. | |
~GncTxImport () | |
Destructor for GncTxImport. | |
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 previously set file format was different and a filename was already set. More... | |
GncImpFileFormat | file_format () |
void | multi_split (bool multi_split) |
Toggles the multi-split state of the importer and will subsequently sanitize the column_types list. More... | |
bool | multi_split () |
void | base_account (Account *base_account) |
Sets a base account. More... | |
Account * | base_account () |
void | currency_format (int currency_format) |
int | currency_format () |
void | date_format (int date_format) |
int | date_format () |
void | encoding (const std::string &encoding) |
Converts raw file data using a new encoding. More... | |
std::string | encoding () |
void | update_skipped_lines (std::optional< uint32_t > start, std::optional< uint32_t > end, std::optional< bool > alt, std::optional< bool > errors) |
uint32_t | skip_start_lines () |
uint32_t | skip_end_lines () |
bool | skip_alt_lines () |
bool | skip_err_lines () |
void | separators (std::string separators) |
std::string | separators () |
void | settings (const CsvTransImpSettings &settings) |
bool | save_settings () |
void | settings_name (std::string name) |
std::string | settings_name () |
void | load_file (const std::string &filename) |
Loads a file into a GncTxImport. More... | |
void | tokenize (bool guessColTypes) |
Splits a file into cells. More... | |
std::string | verify (bool with_acct_errors) |
void | create_transactions () |
This function will attempt to convert all tokenized lines into transactions using the column types the user has set. More... | |
bool | check_for_column_type (GncTransPropType type) |
void | set_column_type (uint32_t position, GncTransPropType type, bool force=false) |
std::vector< GncTransPropType > | column_types () |
std::set< std::string > | accounts () |
Data Fields | |
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. More... | |
std::multimap< time64, std::shared_ptr< DraftTransaction > > | m_transactions |
map of transaction objects created from parsed_lines and column_types, ordered by date | |
The actual TxImport class It's intended to use in the following sequence of actions:
Definition at line 104 of file gnc-import-tx.hpp.
void GncTxImport::base_account | ( | Account * | base_account | ) |
Sets a base account.
This is the account all import data relates to. As such at least one split of each transaction that will be generated will be in this account. When a base account is set, there can't be an account column selected in the import data. In multi-split mode the user has to select an account column so in that mode the base_account can't be set.
base_account | Pointer to an account or NULL. |
Definition at line 177 of file gnc-import-tx.cpp.
void GncTxImport::create_transactions | ( | ) |
This function will attempt to convert all tokenized lines into transactions using the column types the user has set.
Creates a list of transactions from parsed data.
The parsed data will first be validated. If any errors are found in lines that are marked for processing (ie not marked to skip) this function will throw an error.
skip_errors | true skip over lines with errors |
throws | std::invalid_argument if data validation or processing fails. |
Definition at line 716 of file gnc-import-tx.cpp.
void GncTxImport::encoding | ( | const std::string & | encoding | ) |
Converts raw file data using a new encoding.
This function must be called after load_file only if load_file guessed the wrong encoding.
encoding | Encoding that data should be translated using |
Definition at line 248 of file gnc-import-tx.cpp.
void GncTxImport::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 previously set file format was different and a filename was already set.
format | the new format to set |
std::ifstream::failure | if file reloading fails |
Definition at line 87 of file gnc-import-tx.cpp.
void GncTxImport::load_file | ( | const std::string & | filename | ) |
Loads a file into a GncTxImport.
This is the first function that must be called after creating a new GncTxImport. As long as this function didn't run successfully, the importer can't proceed.
filename | Name of the file that should be opened |
may | throw std::ifstream::failure on any io error |
Definition at line 369 of file gnc-import-tx.cpp.
void GncTxImport::multi_split | ( | bool | multi_split | ) |
Toggles the multi-split state of the importer and will subsequently sanitize the column_types list.
All types that don't make sense in the new state are reset to type GncTransPropType::NONE. Additionally the interpretation of the columns with transaction properties changes when changing multi-split mode. So this function will force a reparsing of the transaction properties (if there are any) by resetting the first column with a transaction property it encounters.
multi_split | Boolean value with desired state (multi-split vs two-split). |
Definition at line 145 of file gnc-import-tx.cpp.
void GncTxImport::tokenize | ( | bool | guessColTypes | ) |
Splits a file into cells.
This requires having an encoding that works (see GncTxImport::convert_encoding). Tokenizing related options should be set to the user's selections before calling this function. Notes: - this function must be called with guessColTypes set to true once before calling it with guessColTypes set to false.
guessColTypes | true to guess what the types of columns are based on the cell contents |
std::range_error | if tokenizing failed |
Definition at line 397 of file gnc-import-tx.cpp.
std::vector<parse_line_t> GncTxImport::m_parsed_lines |
source file parsed into a two-dimensional array of strings.
Per line also holds possible error messages and objects with extracted transaction and split properties.
Definition at line 163 of file gnc-import-tx.hpp.