From f13ff8932bd2e9a349cd4b81c280f39483cfb7d6 Mon Sep 17 00:00:00 2001 From: Maximilian Stiefel Date: Sun, 15 Apr 2018 17:44:17 +0200 Subject: [PATCH] Added a reset_search function. --- dict/dict_imp.cc | 22 +++++++++++++++++++++- dict/dict_int.h | 11 ++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/dict/dict_imp.cc b/dict/dict_imp.cc index a6001a5..e014031 100644 --- a/dict/dict_imp.cc +++ b/dict/dict_imp.cc @@ -2,6 +2,12 @@ namespace dictcc { + + dict::dict() + { + setlocale(LC_ALL, ""); + } + const std::string dict::URL_HTTPS = "https://"; const std::string dict::URL_REST = ".dict.cc/?s="; const std::string dict::QUERYA = "c1Arr = new Array"; @@ -68,7 +74,7 @@ namespace dictcc l0.resize(min); l1.resize(min); } - // Make pair and return shared pointer to it. + // Make pair and make shared ptr if necessary. auto pair = std::make_pair(l0, l1); if (d_translations == nullptr) { d_translations = std::make_shared(pair); @@ -79,6 +85,20 @@ namespace dictcc return d_translations; } + void dict::reset_search(void) + { + // Initialize the word lists so they are not empty. + str_list_t l0(1, ""), l1(1, ""); + auto pair = std::make_pair(l0, l1); + if (d_translations != nullptr) + { + *d_translations = pair; + } else { + // Apparently, the pointer has not been initialized yet. + d_translations = std::make_shared(pair); + } + } + std::string dict::langs2str(const lang_t& lt) { // TODO: Add new languages here. diff --git a/dict/dict_int.h b/dict/dict_int.h index 07075e8..7a2bc77 100644 --- a/dict/dict_int.h +++ b/dict/dict_int.h @@ -36,10 +36,10 @@ namespace dictcc private: /*! \brief Translations found by the search for a string. */ - search_ptr_t d_translations; + search_ptr_t d_translations = nullptr; /*! \brief Additional information e.g. different forms of a verb. */ - search_ptr_t d_additional; + search_ptr_t d_additional = nullptr; curlpp::Easy d_request; curlpp::Cleanup d_cleaner; lang_t d_langs; @@ -52,13 +52,18 @@ namespace dictcc std::string d_suburl; protected: - dict(){setlocale(LC_ALL, "");} + dict(); public: virtual ~dict(){} public: + /*! \brief Perform a search and create a smart pointer object. + */ search_ptr_t search(std::string word); + /*! \brief Make sure there are two empty word lists. + */ + void reset_search(void); static std::string langs2str(const lang_t& lt); static lang_t str2langs(const std::string& str); /*! \brief Help function: Get the size of a string in chars containing multibyte characters e.g. ΓΌ.