ome-common  5.5.0
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* ();
115 
121  Node *
122  operator-> ();
123 
129  iterator&
130  operator-- ();
131 
137  iterator&
138  operator++ ();
139 
146  bool
147  operator == (const iterator& rhs) const;
148 
155  bool
156  operator != (const iterator& rhs) const
157  {
158  return !(*this == rhs);
159  }
160 
162  friend class NodeList;
163 
164  private:
166  size_type index;
168  xercesc::DOMNodeList *xmlnodelist;
170  std::shared_ptr<Node> xmlnode;
171  };
172 
177  Wrapper<xercesc::DOMNodeList, Base<xercesc::DOMNodeList>>()
178  {
179  }
180 
186  NodeList (const NodeList& nodelist):
187  Wrapper<xercesc::DOMNodeList, Base<xercesc::DOMNodeList>>(nodelist)
188  {
189  }
190 
196  NodeList (xercesc::DOMNodeList *nodelist):
197  Wrapper<xercesc::DOMNodeList, Base<xercesc::DOMNodeList>>(static_cast<base_element_type *>(nodelist))
198  {
199  }
200 
203  {
204  }
205 
211  size_type
212  size() const
213  {
214  size_type ret = 0;
215 
216  if (this->get())
217  return (*this)->getLength();
218 
219  return ret;
220  }
221 
227  bool
228  empty() const
229  {
230  return size() == 0;
231  }
232 
238  iterator
240  {
241  return iterator(this->get(), 0);
242  }
243 
249  iterator
250  end()
251  {
252  return iterator();
253  }
254 
261  Node
262  at(size_type index);
263  };
264 
265  }
266  }
267  }
268 }
269 
270 #endif // OME_COMMON_XML_DOM_NODELIST_H
271 
272 /*
273  * Local Variables:
274  * mode:C++
275  * End:
276  */
NodeList(const NodeList &nodelist)
Copy construct a NodeList.
Definition: NodeList.h:186
iterator & operator++()
Move the iterator forward one element.
Definition: NodeList.cpp:104
Xerces DOM class wrapper.
Definition: Wrapper.h:72
~NodeList()
Destructor.
Definition: NodeList.h:202
Node at(size_type index)
Get the element at a particular index.
Definition: NodeList.cpp:127
DOM Node wrapper.
Definition: Node.h:70
std::shared_ptr< Node > xmlnode
Node at current position.
Definition: NodeList.h:170
NodeList(xercesc::DOMNodeList *nodelist)
Construct a NodeList from a xercesc::DOMNodeList * (unmanaged).
Definition: NodeList.h:196
bool empty() const
Check if the NodeList is empty.
Definition: NodeList.h:228
XMLSize_t size_type
The NodeList size type.
Definition: NodeList.h:73
iterator & operator--()
Move the iterator backward one element.
Definition: NodeList.cpp:88
~iterator()
Destructor.
Definition: NodeList.cpp:70
iterator end()
Get an iterator pointing to the past-the-end element in the NodeList.
Definition: NodeList.h:250
Iterator for a NodeList.
Definition: NodeList.h:78
Open Microscopy Environment C++.
Definition: base64.h:48
bool operator!=(const iterator &rhs) const
Check the non-equality of two iterators.
Definition: NodeList.h:156
Base of the DOM wrapper hierarchy.
Definition: Base.h:76
size_type index
Index into the list.
Definition: NodeList.h:166
size_type size() const
Get the size (length) of the NodeList.
Definition: NodeList.h:212
xercesc::DOMNodeList base_element_type
Base element type (root type of the wrapped type).
Definition: Base.h:82
bool operator==(const iterator &rhs) const
Check the equality of two iterators.
Definition: NodeList.cpp:115
xercesc::DOMNodeList * xmlnodelist
List being iterated over.
Definition: NodeList.h:168
NodeList()
Construct a NULL NodeList.
Definition: NodeList.h:176
DOM NodeList wrapper.
Definition: NodeList.h:69
iterator()
Construct a null iterator.
Definition: NodeList.cpp:51
iterator begin()
Get an iterator pointing to the first element in the NodeList.
Definition: NodeList.h:239
Node & operator*()
Dereference the iterator.
Definition: NodeList.cpp:74
Node * operator->()
Dereference the iterator.
Definition: NodeList.cpp:81