Skip to content

Commit

Permalink
Refactor pair into a tuple in preparation of extending it
Browse files Browse the repository at this point in the history
  • Loading branch information
gjanssens committed Feb 20, 2017
1 parent ffa68c6 commit 91df5ed
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/import-export/csv-imp/assistant-csv-trans-import.cpp
Expand Up @@ -1727,7 +1727,7 @@ static void gnc_csv_preview_update_assist (CsvImportTrans* info)
for (auto parse_line : info->parse_data->orig_lines)
{
// When previewing errors skip all lines that don't have errors
if (info->previewing_errors && parse_line.second.empty())
if (info->previewing_errors && std::get<1>(parse_line).empty())
continue;

GtkTreeIter iter;
Expand All @@ -1736,14 +1736,14 @@ static void gnc_csv_preview_update_assist (CsvImportTrans* info)
/* Row Color column */
gtk_list_store_set (store, &iter, 0, NULL, -1);

for (auto cell_str_it = parse_line.first.cbegin(); cell_str_it != parse_line.first.cend(); cell_str_it++)
for (auto cell_str_it = std::get<0>(parse_line).cbegin(); cell_str_it != std::get<0>(parse_line).cend(); cell_str_it++)
{
/* Set the value of the proper column in the list store. */
uint pos = cell_str_it - parse_line.first.cbegin() + 1;
uint pos = cell_str_it - std::get<0>(parse_line).cbegin() + 1;
gtk_list_store_set (store, &iter, pos, cell_str_it->c_str(), -1);
}
/* Add the optional error messages in the last column of the store */
gtk_list_store_set (store, &iter, ncols + 1, parse_line.second.c_str(), -1);
gtk_list_store_set (store, &iter, ncols + 1, std::get<1>(parse_line).c_str(), -1);
}
gtk_tree_view_set_model (info->treeview, GTK_TREE_MODEL(store));

Expand Down
15 changes: 8 additions & 7 deletions src/import-export/csv-imp/gnc-tx-import.cpp
Expand Up @@ -307,7 +307,7 @@ void GncTxImport::parse (bool guessColTypes)
orig_lines.clear();
for (auto tokenized_line : tokenizer->get_tokens())
{
orig_lines.push_back (std::make_pair (tokenized_line, std::string()));
orig_lines.push_back (std::make_tuple (tokenized_line, std::string()));
auto length = tokenized_line.size();
if (length > max_cols)
max_cols = length;
Expand Down Expand Up @@ -771,7 +771,7 @@ int GncTxImport::parse_to_trans (Account* account,
if (!redo_errors) /* If we're redoing errors, we save freeing until the end. */
{
for (auto orig_line : orig_lines)
orig_line.second.clear();
std::get<1>(orig_line).clear();

/* FIXME handle memory leak here!
* Existing transactions in the map should probably removed before emptying the map
Expand All @@ -798,18 +798,19 @@ int GncTxImport::parse_to_trans (Account* account,
++orig_lines_it, odd_line = !odd_line)
{
prop_map_t trans_props;
auto orig_line = *orig_lines_it;

/* Skip current line if:
1. only looking for lines with error AND no error on current line
OR
2. looking for all lines AND
skip_rows is enabled AND
current line is an odd line */
if ((redo_errors && orig_lines_it->second.empty()) ||
if ((redo_errors && std::get<1>(orig_line).empty()) ||
(!redo_errors && skip_rows && odd_line))
continue;

auto line = orig_lines_it->first;
auto line = std::get<0>(orig_line);
GncCsvTransLine* trans_line = NULL;

/* Convert this import line into a map of transaction/split properties. */
Expand Down Expand Up @@ -861,7 +862,7 @@ int GncTxImport::parse_to_trans (Account* account,
parse_errors = loop_err = true;
std::string error_message {_(gnc_csv_col_type_strs[*col_types_it])};
error_message += _(" column could not be understood.");
orig_lines_it->second = std::move(error_message);
std::get<1>(orig_line) = std::move(error_message);
break;
}
}
Expand All @@ -884,7 +885,7 @@ int GncTxImport::parse_to_trans (Account* account,
// Oops - the user didn't select an Account column *and* we didn't get a default value either!
// Note if you get here this suggests a bug in the code!
parse_errors = true;
orig_lines_it->second = _("No account column selected and no default account specified either.");
std::get<1>(orig_line) = _("No account column selected and no default account specified either.");
continue;
}
}
Expand All @@ -895,7 +896,7 @@ int GncTxImport::parse_to_trans (Account* account,
if (trans_line == NULL)
{
parse_errors = true;
orig_lines_it->second = error_message;
std::get<1>(orig_line) = error_message;
g_free (error_message);
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions src/import-export/csv-imp/gnc-tx-import.hpp
Expand Up @@ -93,8 +93,8 @@ extern const gchar* currency_format_user[];
extern const int num_date_formats;
extern const gchar* date_format_user[];

/** Pair to hold a tokenized line of input and an optional error string */
using parse_line_t = std::pair<StrVec, std::string>;
/** Tuple to hold a tokenized line of input and an optional error string */
using parse_line_t = std::tuple<StrVec, std::string>;

/** The actual TxImport class
* It's intended to use in the following sequence of actions:
Expand Down

0 comments on commit 91df5ed

Please sign in to comment.