Browse Source

Added a reset_search function.

stable
Maximilian Stiefel 7 years ago
parent
commit
f13ff8932b
  1. 22
      dict/dict_imp.cc
  2. 11
      dict/dict_int.h

22
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<search_t>(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<search_t>(pair);
}
}
std::string dict::langs2str(const lang_t& lt)
{
// TODO: Add new languages here.

11
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. ü.

Loading…
Cancel
Save