OpenCog Framework  Branch: master, revision 6f0b7fc776b08468cf1b74aa9db028f387b4f0c0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
StringIndex.h
Go to the documentation of this file.
1 /*
2  * opencog/atomspace/StringIndex.h
3  *
4  * Copyright (C) 2008 Linas Vepstas <linasvepstas@gmail.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License v3 as
8  * published by the Free Software Foundation and including the exceptions
9  * at http://opencog.org/wiki/Licenses
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program; if not, write to:
18  * Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21 
22 #ifndef _OPENCOG_STRINGINDEX_H
23 #define _OPENCOG_STRINGINDEX_H
24 
25 #include <cstddef>
26 #include <map>
27 
29 
30 namespace opencog
31 {
41 {
42  private:
43  std::map<std::string, Atom*> idx;
44 
45  public:
46  void insert(const std::string& str, Atom* a)
47  {
48  idx.insert(std::pair<std::string, Atom*>(str, a));
49  }
50  Atom* get(const std::string& str) const
51  {
52  std::map<std::string, Atom*>::const_iterator it;
53  it = idx.find(str);
54  if (it != idx.end()) return it->second;
55  return NULL;
56  }
57  void remove(const std::string& str)
58  {
59  idx.erase(str);
60  }
61  size_t size(void) const
62  {
63  return idx.size();
64  }
65 };
66 
68 } //namespace opencog
69 
70 #endif // _OPENCOG_STRINGINDEX_H
size_t size(void) const
Definition: StringIndex.h:61
void insert(const std::string &str, Atom *a)
Definition: StringIndex.h:46
std::map< std::string, Atom * > idx
Definition: StringIndex.h:43