Xalan-C++ API Reference  1.12.0
XalanSet.hpp
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #if !defined(XALANSET_HEADER_GUARD_1357924680)
20 #define XALANSET_HEADER_GUARD_1357924680
21 
22 
23 
24 // Base include file. Must be first.
27 
28 
29 
31 
32 
33 
34 namespace XALAN_CPP_NAMESPACE {
35 
36 
37 
38 template <class Value, class MapIterator>
40 {
41  typedef Value value_type;
42 
43  typedef Value& reference;
44  typedef Value* pointer;
45 
46  typedef ptrdiff_t difference_type;
47  typedef std::bidirectional_iterator_tag iterator_category;
48 
49  XalanSetIterator(const MapIterator& iter) :
50  m_mapIterator(iter)
51  {
52  }
53 
55  {
56  return m_mapIterator->first;
57  };
58 
59  bool operator==(const XalanSetIterator& theRhs) const
60  {
61  return theRhs.m_mapIterator == m_mapIterator;
62  }
63 
64  bool operator!=(const XalanSetIterator& theRhs) const
65  {
66  return !(theRhs == *this);
67  }
68 
70  {
71  ++m_mapIterator;
72 
73  return *this;
74  }
75 
77  {
78  XalanSetIterator orig(m_mapIterator);
79 
80  ++(*this);
81 
82  return orig;
83  }
84 
85 protected:
86 
87  MapIterator m_mapIterator;
88 };
89 
90 
91 /**
92  * Xalan set implementation.
93  *
94  * Set relies on the XalanMap hashtable. Users must ensure the right key
95  * traits specialization is aviable to define the proper hash functor.
96  */
97 template <class Value>
98 class XalanSet
99 {
100 public:
101 
102  typedef Value value_type;
103 
104  typedef size_t size_type;
105 
107 
110 
111  XalanSet(MemoryManager& theMemoryManager) :
112  m_map(theMemoryManager)
113  {
114  }
115 
117  const XalanSet& other,
118  MemoryManager& theMemoryManager) :
119  m_map(other.m_map, theMemoryManager)
120  {
121  }
122 
123  MemoryManager&
125  {
126  return m_map.getMemoryManager();
127  }
128 
129  const_iterator
130  begin() const
131  {
132  return m_map.begin();
133  }
134 
135  const_iterator
136  end() const
137  {
138  return m_map.end();
139  }
140 
141  size_type
142  size() const {
143  return m_map.size();
144  }
145 
146  size_type
147  count(const value_type& value) const
148  {
149  return find(value) != end() ? 1 : 0;
150  }
151 
152  const_iterator
153  find(const value_type& value) const
154  {
155  return m_map.find(value);
156  }
157 
158  void
159  insert(const value_type& value)
160  {
161  m_map.insert(value, true);
162  }
163 
164  size_type
165  erase(const value_type& value)
166  {
167  return m_map.erase(value);
168  }
169 
170  void
172  {
173  m_map.clear();
174  }
175 
176 private:
177 
178  SetMapType m_map;
179 };
180 
181 
182 
183 }
184 
185 #endif // XALANSET_HEADER_GUARD_1357924680
xalanc::XalanSet::value_type
Value value_type
Definition: XalanSet.hpp:102
xalanc::XalanSet
Xalan set implementation.
Definition: XalanSet.hpp:98
XALAN_CPP_NAMESPACE
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
Definition: XalanVersion.hpp:76
xalanc::XalanSet::end
const_iterator end() const
Definition: XalanSet.hpp:136
xalanc::XalanSetIterator::operator!=
bool operator!=(const XalanSetIterator &theRhs) const
Definition: XalanSet.hpp:64
xalanc::XalanSet::erase
size_type erase(const value_type &value)
Definition: XalanSet.hpp:165
xalanc::XalanSet::insert
void insert(const value_type &value)
Definition: XalanSet.hpp:159
xalanc::XalanSetIterator::XalanSetIterator
XalanSetIterator(const MapIterator &iter)
Definition: XalanSet.hpp:49
xalanc::XalanSet::count
size_type count(const value_type &value) const
Definition: XalanSet.hpp:147
xalanc::XPath
Definition: XPath.hpp:67
xalanc::XalanSetIterator::difference_type
ptrdiff_t difference_type
Definition: XalanSet.hpp:46
xalanc::XalanSet::find
const_iterator find(const value_type &value) const
Definition: XalanSet.hpp:153
xalanc::size_type
size_t size_type
Definition: XalanMap.hpp:46
xalanc::XalanSetIterator::operator==
bool operator==(const XalanSetIterator &theRhs) const
Definition: XalanSet.hpp:59
xalanc::XalanSetIterator::reference
Value & reference
Definition: XalanSet.hpp:43
xalanc::XalanSet::iterator
XalanSetIterator< value_type, typename SetMapType::iterator > iterator
Definition: XalanSet.hpp:108
xalanc::XalanSetIterator::operator++
XalanSetIterator operator++(int)
Definition: XalanSet.hpp:76
xalanc::XalanSet::clear
void clear()
Definition: XalanSet.hpp:171
xalanc::XalanSet::size_type
size_t size_type
Definition: XalanSet.hpp:104
xalanc::XalanSetIterator::pointer
Value * pointer
Definition: XalanSet.hpp:44
xalanc::XalanSet::begin
const_iterator begin() const
Definition: XalanSet.hpp:130
XalanMemoryManagement.hpp
xalanc::XalanSetIterator::iterator_category
std::bidirectional_iterator_tag iterator_category
Definition: XalanSet.hpp:47
xalanc::XalanSet::XalanSet
XalanSet(const XalanSet &other, MemoryManager &theMemoryManager)
Definition: XalanSet.hpp:116
xalanc::XalanSetIterator
Definition: XalanSet.hpp:39
xalanc::XalanMap< value_type, bool >
XalanMap.hpp
xalanc::XalanSet::SetMapType
XalanMap< value_type, bool > SetMapType
Definition: XalanSet.hpp:106
xalanc::XalanSetIterator::value_type
Value value_type
Definition: XalanSet.hpp:41
PlatformDefinitions.hpp
xalanc::XalanSet::const_iterator
XalanSetIterator< const value_type, typename SetMapType::const_iterator > const_iterator
Definition: XalanSet.hpp:109
xalanc::XalanSetIterator::operator*
reference operator*() const
Definition: XalanSet.hpp:54
xalanc::XalanSet::size
size_type size() const
Definition: XalanSet.hpp:142
xalanc::XalanSet::XalanSet
XalanSet(MemoryManager &theMemoryManager)
Definition: XalanSet.hpp:111
xalanc::XalanSetIterator::m_mapIterator
MapIterator m_mapIterator
Definition: XalanSet.hpp:87
xalanc::XalanSetIterator::operator++
XalanSetIterator operator++()
Definition: XalanSet.hpp:69
xalanc::XalanSet::getMemoryManager
MemoryManager & getMemoryManager()
Definition: XalanSet.hpp:124