OpenCog Framework  Branch: master, revision 6f0b7fc776b08468cf1b74aa9db028f387b4f0c0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TypeIndex.h
Go to the documentation of this file.
1 /*
2  * opencog/atomspace/TypeIndex.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_TYPEINDEX_H
23 #define _OPENCOG_TYPEINDEX_H
24 
25 #include <set>
26 #include <vector>
27 
28 #include <opencog/atomspace/Atom.h>
32 
33 namespace opencog
34 {
53 {
54  private:
55  size_t num_types;
56  public:
57  TypeIndex(void);
58  void resize(void);
59  void insertAtom(Atom* a)
60  {
61  insert(a->getType(), a);
62  }
63  void removeAtom(Atom* a)
64  {
65  remove(a->getType(), a);
66  }
67  size_t getNumAtomsOfType(Type type, bool subclass) const;
68 
69  class iterator
70  : public std::iterator<std::forward_iterator_tag, Handle>
71  {
72  friend class TypeIndex;
73  public:
74  iterator(Type, bool);
76  iterator& operator++(int);
78  bool operator==(iterator);
79  bool operator!=(iterator);
80  Handle operator*(void);
81  private:
83  bool subclass;
84  std::vector<UnorderedAtomSet>::const_iterator s;
85  std::vector<UnorderedAtomSet>::const_iterator send;
87  UnorderedAtomSet::const_iterator se;
88  };
89 
90  iterator begin(Type, bool) const;
91  iterator end(void) const;
92 };
93 
95 } //namespace opencog
96 
97 #endif // _OPENCOG_TYPEINDEX_H
void resize(void)
Definition: TypeIndex.cc:33
void insertAtom(Atom *a)
Definition: TypeIndex.h:59
UnorderedAtomSet::const_iterator se
Definition: TypeIndex.h:87
void removeAtom(Atom *a)
Definition: TypeIndex.h:63
iterator & operator=(iterator)
Definition: TypeIndex.cc:105
Type getType() const
Definition: Atom.h:197
iterator begin(Type, bool) const
Definition: TypeIndex.cc:66
std::vector< UnorderedAtomSet >::const_iterator s
Definition: TypeIndex.h:84
size_t getNumAtomsOfType(Type type, bool subclass) const
Definition: TypeIndex.cc:39
void insert(size_t i, Atom *a)
iterator end(void) const
Definition: TypeIndex.cc:89
unsigned short Type
type of Atoms, represented as short integer (16 bits)
Definition: types.h:40
std::vector< UnorderedAtomSet >::const_iterator send
Definition: TypeIndex.h:85