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


Loading...
Searching...
No Matches
Set.h
Go to the documentation of this file.
1
2// 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
13namespace Lucene {
14
16template < class TYPE, class LESS = std::less<TYPE> >
17class Set : public LuceneSync {
18public:
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
28protected:
29 boost::shared_ptr<set_type> setContainer;
30
31public:
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
62 return setContainer->begin();
63 }
64
66 return setContainer->end();
67 }
68
70 return setContainer->begin();
71 }
72
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
Base class for all Lucene synchronised classes.
Definition LuceneSync.h:15
Utility template class to handle set based collections that can be safely copied and shared.
Definition Set.h:17
bool empty() const
Definition Set.h:53
bool operator!=(const this_type &other)
Definition Set.h:126
bool equals(const this_type &other, PRED comp) const
Definition Set.h:103
bool operator==(const this_type &other)
Definition Set.h:122
void reset()
Definition Set.h:45
Set< TYPE, LESS > this_type
Definition Set.h:19
set_type::const_iterator const_iterator
Definition Set.h:22
const_iterator end() const
Definition Set.h:73
bool operator!() const
Definition Set.h:118
iterator find(const TYPE &type)
Definition Set.h:90
boost::shared_ptr< set_type > setContainer
Definition Set.h:29
bool remove(const TYPE &type)
Definition Set.h:86
virtual ~Set()
Definition Set.h:25
static this_type newInstance()
Definition Set.h:32
void addAll(ITER first, ITER last)
Definition Set.h:82
iterator end()
Definition Set.h:65
static this_type newInstance(ITER first, ITER last)
Definition Set.h:39
iterator begin()
Definition Set.h:61
bool contains(const TYPE &type) const
Definition Set.h:94
bool add(const TYPE &type)
Definition Set.h:77
set_type::iterator iterator
Definition Set.h:21
int32_t size() const
Definition Set.h:49
void clear()
Definition Set.h:57
const_iterator begin() const
Definition Set.h:69
bool equals(const this_type &other) const
Definition Set.h:98
void swap(this_type &other)
Definition Set.h:110
std::set< TYPE, LESS > set_type
Definition Set.h:20
TYPE value_type
Definition Set.h:23
Definition AbstractAllTermDocs.h:12

clucene.sourceforge.net