NCBI C++ ToolKit
string_history.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: string_history.cpp 39666 2017-10-25 16:01:13Z katargir $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Roman Katargin
27  *
28  */
29 
30 #include <ncbi_pch.hpp>
31 
32 #include <corelib/ncbistd.hpp>
33 
37 
39 
41 
42 static const char* kStringHistory = "StringHistory";
43 
44 CStringHistory::CStringHistory(size_t maxSize, const char* regPath)
45  : m_Initialized(false), m_MaxSize(maxSize), m_RegPath(regPath)
46 {
47 }
48 
50 {
51  if (m_Initialized)
52  return;
53 
54  _ASSERT(!m_RegPath.empty());
55  if (m_RegPath.empty())
56  return;
57 
59 
60  list<string> history;
61  view.GetStringList(kStringHistory, history);
62  ITERATE(list<string>, it, history)
63  push_back(ToWxString(*it));
64  m_Initialized = true;
65 }
66 
68 {
69  if (!m_Initialized)
70  return;
71 
72  _ASSERT(!m_RegPath.empty());
73  if (m_RegPath.empty())
74  return;
75 
77 
78  list<string> history;
79  ITERATE(list<wxString>, it, *this)
80  history.push_back(ToStdString(*it));
81  view.Set(kStringHistory, history);
82 }
83 
85 {
86  if (!m_Initialized)
87  Load();
88 
89  return new CContTextCompleter<list<wxString> >(*this);
90 }
91 
92 void CStringHistory::AddString(const wxString& str)
93 {
94  if (!m_Initialized)
95  Load();
96  if (str.empty())
97  return;
98 
99  for (iterator it = this->begin(); it != this->end();) {
100  if (*it == str)
101  it = erase(it);
102  else
103  ++it;
104  }
105 
106  push_front(str);
107  if (size() > m_MaxSize)
108  resize(m_MaxSize);
109 
110  Save();
111 }
112 
#define false
Definition: bool.h:36
CRegistryWriteView GetWriteView(const string &section)
get a read-write view at a particular level.
Definition: registry.cpp:462
static CGuiRegistry & GetInstance()
access the application-wide singleton
Definition: registry.cpp:400
CRegistryReadView GetReadView(const string &section) const
get a read-only view at a particular level.
Definition: registry.cpp:428
class CRegistryReadView provides a nested hierarchical view at a particular key.
Definition: reg_view.hpp:58
void GetStringList(const string &key, list< string > &val) const
Definition: reg_view.cpp:268
void Set(const string &key, int val)
access a named key at this level, with no recursion
Definition: reg_view.cpp:533
CStringHistory(size_t maxSize, const char *regPath)
void AddString(const wxString &str)
wxTextCompleter * CreateCompleter()
Include a standard set of the NCBI C++ Toolkit most basic headers.
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
constexpr auto push_front(T, list< As... >) noexcept -> list< T, As... >
const struct ncbi::grid::netcache::search::fields::SIZE size
void resize(vector< SMethodDef > &container)
static const char * str(char *buf, int n)
Definition: stats.c:84
static const char * kStringHistory
#define _ASSERT
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
Modified on Thu Feb 29 12:19:41 2024 by modify_doxy.py rev. 669887