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

Set.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2014 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 public:
19 typedef Set<TYPE, LESS> this_type;
20 typedef std::set<TYPE, LESS> set_type;
21 typedef typename set_type::iterator iterator;
22 typedef typename set_type::const_iterator const_iterator;
23 typedef TYPE value_type;
24
25 virtual ~Set() {
26 }
27
28 protected:
29 boost::shared_ptr<set_type> setContainer;
30
31 public:
32 static this_type newInstance() {
33 this_type instance;
34 instance.setContainer = Lucene::newInstance<set_type>();
35 return instance;
36 }
37
38 template <class ITER>
39 static this_type newInstance(ITER first, ITER last) {
40 this_type instance;
41 instance.setContainer = Lucene::newInstance<set_type>(first, last);
42 return instance;
43 }
44
45 void reset() {
46 setContainer.reset();
47 }
48
49 int32_t size() const {
50 return (int32_t)setContainer->size();
51 }
52
53 bool empty() const {
54 return setContainer->empty();
55 }
56
57 void clear() {
58 setContainer->clear();
59 }
60
61 iterator begin() {
62 return setContainer->begin();
63 }
64
65 iterator end() {
66 return setContainer->end();
67 }
68
69 const_iterator begin() const {
70 return setContainer->begin();
71 }
72
73 const_iterator end() const {
74 return setContainer->end();
75 }
76
77 bool add(const TYPE& type) {
78 return setContainer->insert(type).second;
79 }
80
81 template <class ITER>
82 void addAll(ITER first, ITER last) {
83 setContainer->insert(first, last);
84 }
85
86 bool remove(const TYPE& type) {
87 return (setContainer->erase(type) > 0);
88 }
89
90 iterator find(const TYPE& type) {
91 return setContainer->find(type);
92 }
93
94 bool contains(const TYPE& type) const {
95 return (setContainer->find(type) != setContainer->end());
96 }
97
98 bool equals(const this_type& other) const {
99 return equals(other, std::equal_to<TYPE>());
100 }
101
102 template <class PRED>
103 bool equals(const this_type& other, PRED comp) const {
104 if (setContainer->size() != other.setContainer->size()) {
105 return false;
106 }
107 return std::equal(setContainer->begin(), setContainer->end(), other.setContainer->begin(), comp);
108 }
109
110 void swap(this_type& other) {
111 setContainer.swap(other->setContainer);
112 }
113
114 operator bool() const {
115 return setContainer.get() != NULL;
116 }
117
118 bool operator! () const {
119 return !setContainer;
120 }
121
122 bool operator== (const this_type& other) {
123 return (setContainer == other.setContainer);
124 }
125
126 bool operator!= (const this_type& other) {
127 return (setContainer != other.setContainer);
128 }
129 };
130
131 }
132
133 #endif
LuceneSync.h
Lucene::LuceneSync
Base class for all Lucene synchronised classes.
Definition: LuceneSync.h:15
Lucene::Set
Utility template class to handle set based collections that can be safely copied and shared.
Definition: Set.h:17
Lucene::Set::empty
bool empty() const
Definition: Set.h:53
Lucene::Set::operator!=
bool operator!=(const this_type &other)
Definition: Set.h:126
Lucene::Set::equals
bool equals(const this_type &other, PRED comp) const
Definition: Set.h:103
Lucene::Set::operator==
bool operator==(const this_type &other)
Definition: Set.h:122
Lucene::Set::reset
void reset()
Definition: Set.h:45
Lucene::Set::this_type
Set< TYPE, LESS > this_type
Definition: Set.h:19
Lucene::Set::const_iterator
set_type::const_iterator const_iterator
Definition: Set.h:22
Lucene::Set::end
const_iterator end() const
Definition: Set.h:73
Lucene::Set::operator!
bool operator!() const
Definition: Set.h:118
Lucene::Set::find
iterator find(const TYPE &type)
Definition: Set.h:90
Lucene::Set::setContainer
boost::shared_ptr< set_type > setContainer
Definition: Set.h:29
Lucene::Set::remove
bool remove(const TYPE &type)
Definition: Set.h:86
Lucene::Set::~Set
virtual ~Set()
Definition: Set.h:25
Lucene::Set::newInstance
static this_type newInstance()
Definition: Set.h:32
Lucene::Set::addAll
void addAll(ITER first, ITER last)
Definition: Set.h:82
Lucene::Set::end
iterator end()
Definition: Set.h:65
Lucene::Set::newInstance
static this_type newInstance(ITER first, ITER last)
Definition: Set.h:39
Lucene::Set::begin
iterator begin()
Definition: Set.h:61
Lucene::Set::contains
bool contains(const TYPE &type) const
Definition: Set.h:94
Lucene::Set::add
bool add(const TYPE &type)
Definition: Set.h:77
Lucene::Set::iterator
set_type::iterator iterator
Definition: Set.h:21
Lucene::Set::size
int32_t size() const
Definition: Set.h:49
Lucene::Set::clear
void clear()
Definition: Set.h:57
Lucene::Set::begin
const_iterator begin() const
Definition: Set.h:69
Lucene::Set::equals
bool equals(const this_type &other) const
Definition: Set.h:98
Lucene::Set::swap
void swap(this_type &other)
Definition: Set.h:110
Lucene::Set::set_type
std::set< TYPE, LESS > set_type
Definition: Set.h:20
Lucene::Set::value_type
TYPE value_type
Definition: Set.h:23
Lucene
Definition: AbstractAllTermDocs.h:12

clucene.sourceforge.net