ome-common 5.2.0-m2

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

NodeList.h
1 /*
2 * #%L
3 * OME-XERCES C++ library for working with Xerces C++.
4 * %%
5 * Copyright © 2006 - 2015 Open Microscopy Environment:
6 * - Massachusetts Institute of Technology
7 * - National Institutes of Health
8 * - University of Dundee
9 * - Board of Regents of the University of Wisconsin-Madison
10 * - Glencoe Software, Inc.
11 * %%
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions are met:
14 *
15 * 1. Redistributions of source code must retain the above copyright notice,
16 * this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 *
33 * The views and conclusions contained in the software and documentation are
34 * those of the authors and should not be interpreted as representing official
35 * policies, either expressed or implied, of any organization.
36 * #L%
37 */
38
39 #ifndef OME_COMMON_XML_DOM_NODELIST_H
40 #define OME_COMMON_XML_DOM_NODELIST_H
41
42 #include <ome/common/config.h>
43
44 #include <cassert>
45
46 #include <ome/common/xml/dom/Base.h>
47 #include <ome/common/xml/dom/Wrapper.h>
48
49 #include <xercesc/dom/DOMNodeList.hpp>
50
51 namespace ome
52 {
53 namespace common
54 {
55 namespace xml
56 {
57 namespace dom
58 {
59
60 class Node;
61
69 class NodeList : public Wrapper<xercesc::DOMNodeList, Base<xercesc::DOMNodeList> >
70 {
71 public:
73 typedef XMLSize_t size_type;
74
78 class iterator
79 {
80 private:
85 iterator();
86
94 iterator(xercesc::DOMNodeList *xmlnodelist,
95 size_type index);
96
97 public:
103 iterator(const iterator& rhs);
104
106 ~iterator();
107
113 Node&
114 operator* () noexcept;
115
121 Node *
122 operator-> () noexcept;
123
129 iterator&
130 operator-- ();
131
137 iterator&
138 operator++ ();
139
146 bool
147 operator == (const iterator& rhs) const noexcept;
148
155 bool
156 operator != (const iterator& rhs) const noexcept
157 {
158 return !(*this == rhs);
159 }
160
161 friend class NodeList;
162
163 private:
165 size_type index;
167 xercesc::DOMNodeList *xmlnodelist;
169 ome::compat::shared_ptr<Node> xmlnode;
170 };
171
175 NodeList ():
176 Wrapper<xercesc::DOMNodeList, Base<xercesc::DOMNodeList> >()
177 {
178 }
179
185 NodeList (const NodeList& nodelist):
186 Wrapper<xercesc::DOMNodeList, Base<xercesc::DOMNodeList> >(nodelist)
187 {
188 }
189
195 NodeList (xercesc::DOMNodeList *nodelist):
196 Wrapper<xercesc::DOMNodeList, Base<xercesc::DOMNodeList> >(static_cast<base_element_type *>(nodelist))
197 {
198 }
199
201 ~NodeList ()
202 {
203 }
204
210 size_type
211 size() const
212 {
213 size_type ret = 0;
214
215 if (this->get())
216 return (*this)->getLength();
217
218 return ret;
219 }
220
226 bool
227 empty() const
228 {
229 return size() == 0;
230 }
231
237 iterator
238 begin()
239 {
240 return iterator(this->get(), 0);
241 }
242
248 iterator
249 end()
250 {
251 return iterator();
252 }
253
260 Node
261 at(size_type index);
262 };
263
264 }
265 }
266 }
267 }
268
269 #endif // OME_COMMON_XML_DOM_NODELIST_H
270
271 /*
272 * Local Variables:
273 * mode:C++
274 * End:
275 */
ome::common::xml::dom::NodeList::NodeList
NodeList(const NodeList &nodelist)
Copy construct a NodeList.
Definition: NodeList.h:185
ome::common::xml::dom::NodeList::iterator::operator++
iterator & operator++()
Move the iterator forward one element.
Definition: NodeList.cpp:104
ome::common::xml::dom::Wrapper
Xerces DOM class wrapper.
Definition: Wrapper.h:72
ome::common::xml::dom::NodeList::~NodeList
~NodeList()
Destructor.
Definition: NodeList.h:201
ome::common::xml::dom::NodeList::at
Node at(size_type index)
Get the element at a particular index.
Definition: NodeList.cpp:127
ome::common::xml::dom::Node
DOM Node wrapper.
Definition: Node.h:68
ome::common::xml::dom::NodeList::iterator::xmlnode
ome::compat::shared_ptr< Node > xmlnode
Node at current position.
Definition: NodeList.h:169
ome::common::xml::dom::NodeList::size
size_type size() const
Get the size (length) of the NodeList.
Definition: NodeList.h:211
ome::common::xml::dom::NodeList::NodeList
NodeList(xercesc::DOMNodeList *nodelist)
Construct a NodeList from a xercesc::DOMNodeList * (unmanaged).
Definition: NodeList.h:195
ome::common::xml::dom::NodeList::empty
bool empty() const
Check if the NodeList is empty.
Definition: NodeList.h:227
ome::common::xml::dom::NodeList::size_type
XMLSize_t size_type
The NodeList size type.
Definition: NodeList.h:73
ome::common::xml::dom::NodeList::iterator::operator--
iterator & operator--()
Move the iterator backward one element.
Definition: NodeList.cpp:88
ome::common::xml::dom::NodeList::iterator::~iterator
~iterator()
Destructor.
Definition: NodeList.cpp:70
ome::common::xml::dom::NodeList::iterator::operator!=
bool operator!=(const iterator &rhs) const noexcept
Check the non-equality of two iterators.
Definition: NodeList.h:156
ome::common::xml::dom::NodeList::end
iterator end()
Get an iterator pointing to the past-the-end element in the NodeList.
Definition: NodeList.h:249
ome::common::xml::dom::NodeList::iterator::operator==
bool operator==(const iterator &rhs) const noexcept
Check the equality of two iterators.
Definition: NodeList.cpp:115
ome::common::xml::dom::NodeList::iterator
Iterator for a NodeList.
Definition: NodeList.h:78
ome
Definition: boolean.h:48
ome::common::xml::dom::Base
Base of the DOM wrapper hierarchy.
Definition: Base.h:76
ome::common::xml::dom::NodeList::iterator::index
size_type index
Index into the list.
Definition: NodeList.h:165
ome::common::xml::dom::Base< xercesc::DOMNodeList >::base_element_type
xercesc::DOMNodeList base_element_type
Base element type (root type of the wrapped type).
Definition: Base.h:82
ome::common::xml::dom::NodeList::iterator::operator->
Node * operator->() noexcept
Dereference the iterator.
Definition: NodeList.cpp:81
ome::common::xml::dom::NodeList::iterator::xmlnodelist
xercesc::DOMNodeList * xmlnodelist
List being iterated over.
Definition: NodeList.h:167
ome::common::xml::dom::NodeList::NodeList
NodeList()
Construct a NULL NodeList.
Definition: NodeList.h:175
ome::common::xml::dom::NodeList
DOM NodeList wrapper.
Definition: NodeList.h:69
ome::common::xml::dom::NodeList::iterator::operator*
Node & operator*() noexcept
Dereference the iterator.
Definition: NodeList.cpp:74
ome::common::xml::dom::NodeList::iterator::iterator
iterator()
Construct a null iterator.
Definition: NodeList.cpp:51
ome::common::xml::dom::NodeList::begin
iterator begin()
Get an iterator pointing to the first element in the NodeList.
Definition: NodeList.h:238