Lucene++ - a full-featured, c++ search engine
API Documentation


 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Set.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2011 Alan Wright. All rights reserved.
3 // Distributable under the terms of either the Apache License (Version 2.0)
4 // or the GNU Lesser General Public License.
6 
7 #ifndef SET_H
8 #define SET_H
9 
10 #include <set>
11 #include "LuceneSync.h"
12 
13 namespace Lucene
14 {
16  template < class TYPE, class LESS = std::less<TYPE> >
17  class Set : public LuceneSync
18  {
19  public:
21  typedef std::set< TYPE, LESS, LuceneAllocator<TYPE> > set_type;
22  typedef typename set_type::iterator iterator;
23  typedef typename set_type::const_iterator const_iterator;
24  typedef TYPE value_type;
25 
26  virtual ~Set()
27  {
28  }
29 
30  protected:
31  boost::shared_ptr<set_type> setContainer;
32 
33  public:
35  {
36  this_type instance;
37  instance.setContainer = Lucene::newInstance<set_type>();
38  return instance;
39  }
40 
41  template <class ITER>
42  static this_type newInstance(ITER first, ITER last)
43  {
44  this_type instance;
45  instance.setContainer = Lucene::newInstance<set_type>(first, last);
46  return instance;
47  }
48 
49  void reset()
50  {
51  setContainer.reset();
52  }
53 
54  int32_t size() const
55  {
56  return (int32_t)setContainer->size();
57  }
58 
59  bool empty() const
60  {
61  return setContainer->empty();
62  }
63 
64  void clear()
65  {
66  setContainer->clear();
67  }
68 
70  {
71  return setContainer->begin();
72  }
73 
75  {
76  return setContainer->end();
77  }
78 
80  {
81  return setContainer->begin();
82  }
83 
85  {
86  return setContainer->end();
87  }
88 
89  bool add(const TYPE& type)
90  {
91  return setContainer->insert(type).second;
92  }
93 
94  template <class ITER>
95  void addAll(ITER first, ITER last)
96  {
97  setContainer->insert(first, last);
98  }
99 
100  bool remove(const TYPE& type)
101  {
102  return (setContainer->erase(type) > 0);
103  }
104 
105  iterator find(const TYPE& type)
106  {
107  return setContainer->find(type);
108  }
109 
110  bool contains(const TYPE& type) const
111  {
112  return (setContainer->find(type) != setContainer->end());
113  }
114 
115  bool equals(const this_type& other) const
116  {
117  return equals(other, std::equal_to<TYPE>());
118  }
119 
120  template <class PRED>
121  bool equals(const this_type& other, PRED comp) const
122  {
123  if (setContainer->size() != other.setContainer->size())
124  return false;
125  return std::equal(setContainer->begin(), setContainer->end(), other.setContainer->begin(), comp);
126  }
127 
128  void swap(this_type& other)
129  {
130  setContainer.swap(other->setContainer);
131  }
132 
133  operator bool() const
134  {
135  return setContainer;
136  }
137 
138  bool operator! () const
139  {
140  return !setContainer;
141  }
142 
143  bool operator== (const this_type& other)
144  {
145  return (setContainer == other.setContainer);
146  }
147 
148  bool operator!= (const this_type& other)
149  {
150  return (setContainer != other.setContainer);
151  }
152  };
153 }
154 
155 #endif

clucene.sourceforge.net