From 9efbdc15cf979da22c6d66209e8d5e5a63fa1f75 Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Wed, 15 Feb 2023 18:30:17 +0100 Subject: [PATCH] CsvImp - use std::optional instead of boost::optional --- .../csv-imp/gnc-imp-props-price.cpp | 19 +++--- .../csv-imp/gnc-imp-props-price.hpp | 18 ++--- .../csv-imp/gnc-imp-props-tx.cpp | 58 ++++++++-------- .../csv-imp/gnc-imp-props-tx.hpp | 66 +++++++++---------- .../csv-imp/gnc-imp-settings-csv.hpp | 2 +- .../csv-imp/gnc-import-price.cpp | 8 +-- .../csv-imp/gnc-import-price.hpp | 6 +- .../import-export/csv-imp/gnc-import-tx.cpp | 7 +- .../import-export/csv-imp/gnc-import-tx.hpp | 6 +- 9 files changed, 96 insertions(+), 94 deletions(-) diff --git a/gnucash/import-export/csv-imp/gnc-imp-props-price.cpp b/gnucash/import-export/csv-imp/gnc-imp-props-price.cpp index c9e29f8bdf..5df745d19c 100644 --- a/gnucash/import-export/csv-imp/gnc-imp-props-price.cpp +++ b/gnucash/import-export/csv-imp/gnc-imp-props-price.cpp @@ -34,6 +34,7 @@ #include #include +#include #include #include #include @@ -160,17 +161,17 @@ void GncImportPrice::set (GncPricePropType prop_type, const std::string& value, switch (prop_type) { case GncPricePropType::DATE: - m_date = boost::none; + m_date.reset(); m_date = GncDate(value, GncDate::c_formats[m_date_format].m_fmt); // Throws if parsing fails break; case GncPricePropType::AMOUNT: - m_amount = boost::none; + m_amount.reset(); m_amount = parse_amount_price (value, m_currency_format); // Throws if parsing fails break; case GncPricePropType::FROM_SYMBOL: - m_from_symbol = boost::none; + m_from_symbol.reset(); if (value.empty()) throw std::invalid_argument (_("'From Symbol' can not be empty.")); @@ -190,7 +191,7 @@ void GncImportPrice::set (GncPricePropType prop_type, const std::string& value, break; case GncPricePropType::FROM_NAMESPACE: - m_from_namespace = boost::none; + m_from_namespace.reset(); if (value.empty()) throw std::invalid_argument (_("'From Namespace' can not be empty.")); @@ -213,7 +214,7 @@ void GncImportPrice::set (GncPricePropType prop_type, const std::string& value, break; case GncPricePropType::TO_CURRENCY: - m_to_currency = boost::none; + m_to_currency.reset(); comm = parse_commodity_price_comm (value, GNC_COMMODITY_NS_CURRENCY); // Throws if parsing fails if (comm) { @@ -274,13 +275,13 @@ void GncImportPrice::reset (GncPricePropType prop_type) std::string GncImportPrice::verify_essentials (void) { /* Make sure this price has the minimum required set of properties defined */ - if (m_date == boost::none) + if (!m_date) return _("No date column."); - else if (m_amount == boost::none) + else if (!m_amount) return _("No amount column."); - else if (m_to_currency == boost::none) + else if (!m_to_currency) return _("No 'Currency to'."); - else if (m_from_commodity == boost::none) + else if (!m_from_commodity) return _("No 'Commodity from'."); else if (gnc_commodity_equal (*m_from_commodity, *m_to_currency)) return _("'Commodity From' can not be the same as 'Currency To'."); diff --git a/gnucash/import-export/csv-imp/gnc-imp-props-price.hpp b/gnucash/import-export/csv-imp/gnc-imp-props-price.hpp index 9d2a4a9d6f..8263cef65f 100644 --- a/gnucash/import-export/csv-imp/gnc-imp-props-price.hpp +++ b/gnucash/import-export/csv-imp/gnc-imp-props-price.hpp @@ -36,7 +36,7 @@ #include #include #include -#include +#include #include #include @@ -94,22 +94,22 @@ public: Result create_price (QofBook* book, GNCPriceDB *pdb, bool over); gnc_commodity* get_from_commodity () { if (m_from_commodity) return *m_from_commodity; else return nullptr; } - void set_from_commodity (gnc_commodity* comm) { if (comm) m_from_commodity = comm; else m_from_commodity = boost::none; } + void set_from_commodity (gnc_commodity* comm) { if (comm) m_from_commodity = comm; else m_from_commodity.reset(); } gnc_commodity* get_to_currency () { if (m_to_currency) return *m_to_currency; else return nullptr; } - void set_to_currency (gnc_commodity* curr) { if (curr) m_to_currency = curr; else m_to_currency = boost::none; } + void set_to_currency (gnc_commodity* curr) { if (curr) m_to_currency = curr; else m_to_currency.reset(); } std::string errors(); private: int m_date_format; int m_currency_format; - boost::optional m_date; - boost::optional m_amount; - boost::optional m_from_commodity; - boost::optional m_from_namespace; - boost::optional m_from_symbol; - boost::optional m_to_currency; + std::optional m_date; + std::optional m_amount; + std::optional m_from_commodity; + std::optional m_from_namespace; + std::optional m_from_symbol; + std::optional m_to_currency; bool created = false; std::map m_errors; diff --git a/gnucash/import-export/csv-imp/gnc-imp-props-tx.cpp b/gnucash/import-export/csv-imp/gnc-imp-props-tx.cpp index 354d2b6c89..81ca20076e 100644 --- a/gnucash/import-export/csv-imp/gnc-imp-props-tx.cpp +++ b/gnucash/import-export/csv-imp/gnc-imp-props-tx.cpp @@ -233,13 +233,13 @@ void GncPreTrans::set (GncTransPropType prop_type, const std::string& value) switch (prop_type) { case GncTransPropType::UNIQUE_ID: - m_differ = boost::none; + m_differ.reset(); if (!value.empty()) m_differ = value; break; case GncTransPropType::DATE: - m_date = boost::none; + m_date.reset(); if (!value.empty()) m_date = GncDate(value, GncDate::c_formats[m_date_format].m_fmt); // Throws if parsing fails else if (!m_multi_split) @@ -249,13 +249,13 @@ void GncPreTrans::set (GncTransPropType prop_type, const std::string& value) break; case GncTransPropType::NUM: - m_num = boost::none; + m_num.reset(); if (!value.empty()) m_num = value; break; case GncTransPropType::DESCRIPTION: - m_desc = boost::none; + m_desc.reset(); if (!value.empty()) m_desc = value; else if (!m_multi_split) @@ -265,7 +265,7 @@ void GncPreTrans::set (GncTransPropType prop_type, const std::string& value) break; case GncTransPropType::NOTES: - m_notes = boost::none; + m_notes.reset(); if (!value.empty()) m_notes = value; break; @@ -276,7 +276,7 @@ void GncPreTrans::set (GncTransPropType prop_type, const std::string& value) break; case GncTransPropType::VOID_REASON: - m_void_reason = boost::none; + m_void_reason.reset(); if (!value.empty()) m_void_reason = value; break; @@ -433,19 +433,19 @@ void GncPreSplit::set (GncTransPropType prop_type, const std::string& value) switch (prop_type) { case GncTransPropType::ACTION: - m_action = boost::none; + m_action.reset(); if (!value.empty()) m_action = value; break; case GncTransPropType::TACTION: - m_taction = boost::none; + m_taction.reset(); if (!value.empty()) m_taction = value; break; case GncTransPropType::ACCOUNT: - m_account = boost::none; + m_account.reset(); if (value.empty()) throw std::invalid_argument (_("Account value can't be empty.")); if ((acct = gnc_csv_account_map_search (value.c_str())) || @@ -456,7 +456,7 @@ void GncPreSplit::set (GncTransPropType prop_type, const std::string& value) break; case GncTransPropType::TACCOUNT: - m_taccount = boost::none; + m_taccount.reset(); if (value.empty()) throw std::invalid_argument (_("Transfer account value can't be empty.")); @@ -468,44 +468,44 @@ void GncPreSplit::set (GncTransPropType prop_type, const std::string& value) break; case GncTransPropType::MEMO: - m_memo = boost::none; + m_memo.reset(); if (!value.empty()) m_memo = value; break; case GncTransPropType::TMEMO: - m_tmemo = boost::none; + m_tmemo.reset(); if (!value.empty()) m_tmemo = value; break; case GncTransPropType::AMOUNT: - m_amount = boost::none; + m_amount.reset(); m_amount = parse_monetary (value, m_currency_format); // Will throw if parsing fails break; case GncTransPropType::AMOUNT_NEG: - m_amount_neg = boost::none; + m_amount_neg.reset(); m_amount_neg = parse_monetary (value, m_currency_format); // Will throw if parsing fails break; case GncTransPropType::VALUE: - m_value = boost::none; + m_value.reset(); m_value = parse_monetary (value, m_currency_format); // Will throw if parsing fails break; case GncTransPropType::VALUE_NEG: - m_value_neg = boost::none; + m_value_neg.reset(); m_value_neg = parse_monetary (value, m_currency_format); // Will throw if parsing fails break; case GncTransPropType::TAMOUNT: - m_tamount = boost::none; + m_tamount.reset(); m_tamount = parse_monetary (value, m_currency_format); // Will throw if parsing fails break; case GncTransPropType::TAMOUNT_NEG: - m_tamount_neg = boost::none; + m_tamount_neg.reset(); m_tamount_neg = parse_monetary (value, m_currency_format); // Will throw if parsing fails break; @@ -513,29 +513,29 @@ void GncPreSplit::set (GncTransPropType prop_type, const std::string& value) /* Note while a price is not stricly a currency, it will likely use * the same decimal point as currencies in the csv file, so parse * using the same parser */ - m_price = boost::none; + m_price.reset(); m_price = parse_monetary (value, m_currency_format); // Will throw if parsing fails break; case GncTransPropType::REC_STATE: - m_rec_state = boost::none; + m_rec_state.reset(); m_rec_state = parse_reconciled (value); // Throws if parsing fails break; case GncTransPropType::TREC_STATE: - m_trec_state = boost::none; + m_trec_state.reset(); m_trec_state = parse_reconciled (value); // Throws if parsing fails break; case GncTransPropType::REC_DATE: - m_rec_date = boost::none; + m_rec_date.reset(); if (!value.empty()) m_rec_date = GncDate (value, GncDate::c_formats[m_date_format].m_fmt); // Throws if parsing fails break; case GncTransPropType::TREC_DATE: - m_trec_date = boost::none; + m_trec_date.reset(); if (!value.empty()) m_trec_date = GncDate (value, GncDate::c_formats[m_date_format].m_fmt); // Throws if parsing fails @@ -681,10 +681,10 @@ StrVec GncPreSplit::verify_essentials() */ static void trans_add_split (Transaction* trans, Account* account, GncNumeric amount, GncNumeric value, - const boost::optional& action, - const boost::optional& memo, - const boost::optional& rec_state, - const boost::optional& rec_date) + const std::optional& action, + const std::optional& memo, + const std::optional& rec_state, + const std::optional& rec_date) { QofBook* book = xaccTransGetBook (trans); auto split = xaccMallocSplit (book); @@ -740,7 +740,7 @@ void GncPreSplit::create_split (std::shared_ptr draft_trans) if (m_amount_neg) amount -= *m_amount_neg; - boost::optional tamount; + std::optional tamount; if (m_tamount || m_tamount_neg) { tamount = GncNumeric(); @@ -876,7 +876,7 @@ void GncPreSplit::set_account (Account* acct) if (acct) m_account = acct; else - m_account = boost::none; + m_account.reset(); UpdateCrossSplitCounters(); } diff --git a/gnucash/import-export/csv-imp/gnc-imp-props-tx.hpp b/gnucash/import-export/csv-imp/gnc-imp-props-tx.hpp index 095aa43223..f9d094e0c0 100644 --- a/gnucash/import-export/csv-imp/gnc-imp-props-tx.hpp +++ b/gnucash/import-export/csv-imp/gnc-imp-props-tx.hpp @@ -38,7 +38,7 @@ #include #include #include -#include +#include #include #include @@ -138,15 +138,15 @@ struct DraftTransaction ~DraftTransaction () { if (trans) { xaccTransDestroy (trans); trans = nullptr; } } Transaction* trans; - boost::optional m_price; - boost::optional m_taction; - boost::optional m_tmemo; - boost::optional m_tamount; - boost::optional m_taccount; - boost::optional m_trec_state; - boost::optional m_trec_date; + std::optional m_price; + std::optional m_taction; + std::optional m_tmemo; + std::optional m_tamount; + std::optional m_taccount; + std::optional m_trec_state; + std::optional m_trec_date; - boost::optional void_reason; + std::optional void_reason; }; class GncPreTrans @@ -177,7 +177,7 @@ public: * @returns true if this object is considered to be part of the parent, false otherwise. */ bool is_part_of (std::shared_ptr parent); - boost::optional get_void_reason() { return m_void_reason; } + std::optional get_void_reason() { return m_void_reason; } ErrMap errors(); void reset_cross_split_counters(); @@ -190,13 +190,13 @@ public: private: int m_date_format; bool m_multi_split; - boost::optional m_differ; - boost::optional m_date; - boost::optional m_num; - boost::optional m_desc; - boost::optional m_notes; + std::optional m_differ; + std::optional m_date; + std::optional m_num; + std::optional m_desc; + std::optional m_notes; gnc_commodity *m_currency; - boost::optional m_void_reason; + std::optional m_void_reason; bool created = false; @@ -241,23 +241,23 @@ private: std::shared_ptr m_pre_trans; int m_date_format; int m_currency_format; - boost::optional m_action; - boost::optional m_account; - boost::optional m_amount; - boost::optional m_amount_neg; - boost::optional m_value; - boost::optional m_value_neg; - boost::optional m_price; - boost::optional m_memo; - boost::optional m_rec_state; - boost::optional m_rec_date; - boost::optional m_taction; - boost::optional m_taccount; - boost::optional m_tamount; - boost::optional m_tamount_neg; - boost::optional m_tmemo; - boost::optional m_trec_state; - boost::optional m_trec_date; + std::optional m_action; + std::optional m_account; + std::optional m_amount; + std::optional m_amount_neg; + std::optional m_value; + std::optional m_value_neg; + std::optional m_price; + std::optional m_memo; + std::optional m_rec_state; + std::optional m_rec_date; + std::optional m_taction; + std::optional m_taccount; + std::optional m_tamount; + std::optional m_tamount_neg; + std::optional m_tmemo; + std::optional m_trec_state; + std::optional m_trec_date; bool created = false; ErrMap m_errors; diff --git a/gnucash/import-export/csv-imp/gnc-imp-settings-csv.hpp b/gnucash/import-export/csv-imp/gnc-imp-settings-csv.hpp index 92a277ba8f..39b48e65ff 100644 --- a/gnucash/import-export/csv-imp/gnc-imp-settings-csv.hpp +++ b/gnucash/import-export/csv-imp/gnc-imp-settings-csv.hpp @@ -34,7 +34,7 @@ #include #include -#include +#include #include #include "gnc-tokenizer.hpp" diff --git a/gnucash/import-export/csv-imp/gnc-import-price.cpp b/gnucash/import-export/csv-imp/gnc-import-price.cpp index 8368b921c6..ee3cb0b714 100644 --- a/gnucash/import-export/csv-imp/gnc-import-price.cpp +++ b/gnucash/import-export/csv-imp/gnc-import-price.cpp @@ -37,13 +37,13 @@ #include #include #include +#include #include #include #include #include #include -#include #include "gnc-import-price.hpp" #include "gnc-imp-props-price.hpp" @@ -247,8 +247,8 @@ void GncPriceImport::encoding (const std::string& encoding) std::string GncPriceImport::encoding () { return m_settings.m_encoding; } -void GncPriceImport::update_skipped_lines(boost::optional start, boost::optional end, - boost::optional alt, boost::optional errors) +void GncPriceImport::update_skipped_lines(std::optional start, std::optional end, + std::optional alt, std::optional errors) { if (start) m_settings.m_skip_start_lines = *start; @@ -511,7 +511,7 @@ std::string GncPriceImport::verify () verify_column_selections (error_msg); - update_skipped_lines (boost::none, boost::none, boost::none, boost::none); + update_skipped_lines (std::nullopt, std::nullopt, std::nullopt, std::nullopt); auto have_line_errors = false; for (auto line : m_parsed_lines) diff --git a/gnucash/import-export/csv-imp/gnc-import-price.hpp b/gnucash/import-export/csv-imp/gnc-import-price.hpp index 56af0852c7..4ada98ca9b 100644 --- a/gnucash/import-export/csv-imp/gnc-import-price.hpp +++ b/gnucash/import-export/csv-imp/gnc-import-price.hpp @@ -37,11 +37,11 @@ #include #include #include +#include #include "gnc-tokenizer.hpp" #include "gnc-imp-props-price.hpp" #include "gnc-imp-settings-csv-price.hpp" -#include /* A set of currency formats that the user sees. */ extern const int num_currency_formats_price; @@ -106,8 +106,8 @@ public: void encoding (const std::string& encoding); std::string encoding (); - void update_skipped_lines (boost::optional start, boost::optional end, - boost::optional alt, boost::optional errors); + void update_skipped_lines (std::optional start, std::optional end, + std::optional alt, std::optional errors); uint32_t skip_start_lines (); uint32_t skip_end_lines (); bool skip_alt_lines (); diff --git a/gnucash/import-export/csv-imp/gnc-import-tx.cpp b/gnucash/import-export/csv-imp/gnc-import-tx.cpp index 4d5f0ba88a..9b5eee8e05 100644 --- a/gnucash/import-export/csv-imp/gnc-import-tx.cpp +++ b/gnucash/import-export/csv-imp/gnc-import-tx.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -264,8 +265,8 @@ void GncTxImport::encoding (const std::string& encoding) std::string GncTxImport::encoding () { return m_settings.m_encoding; } -void GncTxImport::update_skipped_lines(boost::optional start, boost::optional end, - boost::optional alt, boost::optional errors) +void GncTxImport::update_skipped_lines(std::optional start, std::optional end, + std::optional alt, std::optional errors) { if (start) m_settings.m_skip_start_lines = *start; @@ -562,7 +563,7 @@ std::string GncTxImport::verify (bool with_acct_errors) verify_column_selections (error_msg); - update_skipped_lines (boost::none, boost::none, boost::none, boost::none); + update_skipped_lines (std::nullopt, std::nullopt, std::nullopt, std::nullopt); auto have_line_errors = false; for (auto line : m_parsed_lines) diff --git a/gnucash/import-export/csv-imp/gnc-import-tx.hpp b/gnucash/import-export/csv-imp/gnc-import-tx.hpp index 6bb2afc898..aee84ae15a 100644 --- a/gnucash/import-export/csv-imp/gnc-import-tx.hpp +++ b/gnucash/import-export/csv-imp/gnc-import-tx.hpp @@ -38,11 +38,11 @@ #include #include #include +#include #include "gnc-tokenizer.hpp" #include "gnc-imp-props-tx.hpp" #include "gnc-imp-settings-csv-tx.hpp" -#include /* A set of currency formats that the user sees. */ @@ -121,8 +121,8 @@ public: void encoding (const std::string& encoding); std::string encoding (); - void update_skipped_lines (boost::optional start, boost::optional end, - boost::optional alt, boost::optional errors); + void update_skipped_lines (std::optional start, std::optional end, + std::optional alt, std::optional errors); uint32_t skip_start_lines (); uint32_t skip_end_lines (); bool skip_alt_lines ();