Spinning Topp Logo BlackTopp Studios
inc
nodeiterator.h
Go to the documentation of this file.
1 // © Copyright 2010 - 2016 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 /*
41  *
42  * Software, Files, Libraries and all other items referenced in this clause refers only
43  * to the contents of this file and associated documentation.
44  *
45  * Pugixml parser - version 1.0
46  * --------------------------------------------------------
47  * Copyright © 2006-2012, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com)
48  * Report bugs and download new versions at http://pugixml.org/
49  *
50  * This library is distributed under the MIT License. See notice at the end
51  * of this file.
52  *
53  * This work is based on the pugxml parser, which is:
54  * Copyright © 2003, by Kristen Wegner (kristen@tima.net)
55  */
56 #ifndef _xmlnodeiterator_h
57 #define _xmlnodeiterator_h
58 
59 /// @file
60 /// @brief Contains the defintion of the @ref Mezzanine::XML::NodeIterator and @ref Mezzanine::XML::NamedNodeIterator class.
61 
62 #include "datatypes.h"
63 #include "node.h"
64 #include "swig.h"
65 
66 
67 
68 namespace Mezzanine
69 {
70  namespace XML
71  {
72 
73  /// @brief Child node iterator (a bidirectional iterator over a collection of @ref Node)
74  /// @details Node::begin() and Node::attributes_begin() return iterators that point to the first node/attribute, respectively; Node::end() and Node::attributes_end() return past-the-end iterator for node/attribute list, respectively - this iterator can't be dereferenced, but decrementing it results in an iterator pointing to the last element in the list (except for empty lists, where decrementing past-the-end iterator results in undefined behavior). Past-the-end iterator is commonly used as a termination value for iteration loops. If you want to get an iterator that points to an existing handle, you can construct the iterator with the handle as a single constructor argument, like so: xml_node_iterator(node). For xml_attribute_iterator, you'll have to provide both an attribute and its parent node.\n\n
75  /// Node::begin() and Node::end() return equal iterators if called on null Node; such iterators can't be dereferenced. Node::attributes_begin() and Node::attributes_end() behave the same way. For correct iterator usage this means that child node/attribute collections of null nodes appear to be empty.\n\n
76  /// Both types of iterators have bidirectional iterator semantics (i.e. they can be incremented and decremented, but efficient random access is not supported) and support all usual iterator operations - comparison, dereference, etc. The iterators are invalidated if the node/attribute objects they're pointing to are removed from the tree; adding nodes/attributes does not invalidate any iterators.
78  {
79  friend class Node;
80 
81  private:
82 
83  /// @brief internal
84  /// @brief The current @ref Node this iterator points to.
85  mutable Node TargetNode;
86 
87  /// @internal
88  /// @brief The node that contains this collection of nodes. Used in error situations.
89  Node ParentNode;
90 
91  /// @brief Internal Constructor, almost a copy construtor
92  /// @param ref Some of the internal data from another @ref NodeIterator specifically the Node it points to.
93  /// @param ParentNode Some of the interal data from another @ref NodeIterator specifically the parent of the Node it points to.
94  NodeIterator(NodeStruct* ref, NodeStruct* ParentNode);
95 
96  public:
97  /// @brief An Iterator trait
98  typedef ptrdiff_t difference_type;
99 
100  /// @brief An Iterator trait
101  typedef Node value_type;
102 
103  /// @brief An Iterator trait
104  typedef Node* pointer;
105 
106  /// @brief An Iterator trait
107  typedef Node& reference;
108 
109  /// @brief An Iterator trait
110  typedef std::bidirectional_iterator_tag iterator_category;
111 
112  /// @brief Default Constructor, makes a blank iterator
113  NodeIterator();
114 
115  /// @brief Construct an iterator which points to the specified node
116  /// @param node A Node that this iterator will point to.
117  NodeIterator(const Node& node);
118 
119  /// @brief Compares this NodeIterator to another NodeIterator for equality
120  /// @param rhs The Right Hand Side NodeIterator
121  /// @return True if the internal data stored in Node this NodeIterator refers to is the same as the metadata in the other NodeIterator's Node, false otherwise.
122  bool operator==(const NodeIterator& rhs) const;
123 
124  /// @brief Compares this NodeIterator to another NodeIterator for inequality
125  /// @param rhs The Right Hand Side NodeIterator.
126  /// @return False if the internal data stored in Node this NodeIterator refers to is the same as the metadata in the other NodeIterator's Node, True otherwise.
127  bool operator!=(const NodeIterator& rhs) const;
128 
129  /// @brief Deferences this Iterator
130  /// @return a Node reference to the node pointed at by this NodeIterator.
131  Node& operator*() const;
132 
133  /// @brief Get the pointer the Node this points to.
134  /// @return A pointer to the Node this NodeIterator references.
135  Node* operator->() const;
136 
137  /// @brief Increment the iterator to the next member of the container.
138  /// @return Returns a const NodeIterator.
139  const NodeIterator& operator++();
140 
141  /// @brief Increment the iterator to the next member of the container.
142  /// @return Returns a NodeIterator.
143  NodeIterator operator++(int);
144 
145  /// @brief Decrement the iterator to the next member of the container.
146  /// @return Returns a const NodeIterator.
147  const NodeIterator& operator--();
148 
149  /// @brief Decrement the iterator to the next member of the container.
150  /// @return Returns a NodeIterator.
151  NodeIterator operator--(int);
152  };
153 
154  // Named node range helper
155  /// @brief Child node iterator (a forward iterator over a collection of @ref Node) only iterates over nodes with a given name.
156  /// @details Node::begin() and Node::attributes_begin() return iterators that point to the first node/attribute, respectively; Node::end() and Node::attributes_end() return past-the-end iterator for node/attribute list, respectively - this iterator can't be dereferenced, but decrementing it results in an iterator pointing to the last element in the list (except for empty lists, where decrementing past-the-end iterator results in undefined behavior). Past-the-end iterator is commonly used as a termination value for iteration loops. If you want to get an iterator that points to an existing handle, you can construct the iterator with the handle as a single constructor argument, like so: xml_node_iterator(node). For xml_attribute_iterator, you'll have to provide both an attribute and its parent node.\n\n
157  /// Node::begin() and Node::end() return equal iterators if called on null Node; such iterators can't be dereferenced. Node::attributes_begin() and Node::attributes_end() behave the same way. For correct iterator usage this means that child node/attribute collections of null nodes appear to be empty.\n\n
158  /// Both types of iterators have bidirectional iterator semantics (i.e. they can be incremented and decremented, but efficient random access is not supported) and support all usual iterator operations - comparison, dereference, etc. The iterators are invalidated if the node/attribute objects they're pointing to are removed from the tree; adding nodes/attributes does not invalidate any iterators.
160  {
161  public:
162  /// @brief An Iterator trait
163  typedef ptrdiff_t difference_type;
164 
165  /// @brief An Iterator trait
166  typedef Node value_type;
167 
168  /// @brief An Iterator trait
169  typedef Node* pointer;
170 
171  /// @brief An Iterator trait
172  typedef Node& reference;
173 
174  /// @brief An Iterator trait
175  typedef std::forward_iterator_tag iterator_category;
176 
177  /// @brief Default constructor
179 
180  /// @brief Construct an iterator which points to the specified node
181  NamedNodeIterator(const Node& node, const Char8* Name );
182 
183  /// @brief Compares this NamedNodeIterator to another NamedNodeIterator for equality
184  /// @param rhs The Right Hand Side NamedNodeIterator.
185  /// @return False if the internal data stored in Node this NamedNodeIterator refers to is the same as the metadata in the other NamedNodeIterator's Node, True otherwise.
186  bool operator==(const NamedNodeIterator& rhs) const;
187 
188  /// @brief Compares this NamedNodeIterator to another NamedNodeIterator for inequality
189  /// @param rhs The Right Hand Side NamedNodeIterator.
190  /// @return False if the internal data stored in Node this NamedNodeIterator refers to is the same as the metadata in the other NamedNodeIterator's Node, True otherwise.
191  bool operator!=(const NamedNodeIterator& rhs) const;
192 
193  /// @brief Deferences this Iterator
194  /// @return a Node reference to the node pointed at by this NamedNodeIterator.
195  Node& operator*() const;
196 
197  /// @brief Get the pointer the Node this points to.
198  /// @return A pointer to the Node this NamedNodeIterator references.
199  Node* operator->() const;
200 
201  /// @brief Increment the iterator to the next member of the container.
202  /// @return Returns a const NodeIterator.
203  const NamedNodeIterator& operator++();
204 
205  /// @brief Increment the iterator to the next member of the container.
206  /// @return Returns a NodeIterator.
207  NamedNodeIterator operator++(int);
208 
209  private:
210  /// @brief The Current @ref Node being pointed to by this iterator.
211  mutable Node TargetNode;
212 
213  /// @brief The Name any nodet his points to will assume.
214  const Char8* TargetName;
215  };
216 
217  }
218 }// /namespace Mezzanine
219 
220 
221 
222 #endif // Include guard
223 
224 /*
225  *
226  * Software, Files, Libraries and all other items referenced in this clause refers only
227  * to the contents of this file and associated documentation.
228  *
229  * Copyright © 2006-2012 Arseny Kapoulkine
230  *
231  * Permission is hereby granted, free of charge, to any person
232  * obtaining a copy of this software and associated documentation
233  * files (the "Software"), to deal in the Software without
234  * restriction, including without limitation the rights to use,
235  * copy, modify, merge, publish, distribute, sublicense, and/or sell
236  * copies of the Software, and to permit persons to whom the
237  * Software is furnished to do so, subject to the following
238  * conditions:
239  *
240  * The above copyright notice and this permission notice shall be
241  * included in all copies or substantial portions of the Software.
242  *
243  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
244  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
245  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
246  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
247  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
248  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
249  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
250  * OTHER DEALINGS IN THE SOFTWARE.
251  */
This defines the Mezzanine::XML::Node one of the central XML classes.
Node * pointer
An Iterator trait.
Definition: nodeiterator.h:104
All the definitions for datatypes as well as some basic conversion functions are defined here...
Node value_type
An Iterator trait.
Definition: nodeiterator.h:101
char Char8
A datatype to represent one character.
Definition: datatypes.h:169
ptrdiff_t difference_type
An Iterator trait.
Definition: nodeiterator.h:98
std::forward_iterator_tag iterator_category
An Iterator trait.
Definition: nodeiterator.h:175
Child node iterator (a bidirectional iterator over a collection of Node)
Definition: nodeiterator.h:77
A light-weight handle for manipulating nodes in DOM tree.
Definition: node.h:89
Mezzanine::Vector3 operator*(const btVector3 &Vec, const Mezzanine::Vector3 &lhs)
Right Hand Multiplication Operator for Bullet Vectors with a Mezzanine::Vector3.
Definition: vector3.cpp:651
Child node iterator (a forward iterator over a collection of Node) only iterates over nodes with a gi...
Definition: nodeiterator.h:159
ptrdiff_t difference_type
An Iterator trait.
Definition: nodeiterator.h:163
Node * pointer
An Iterator trait.
Definition: nodeiterator.h:169
#define MEZZ_LIB
Some platforms require special decorations to denote what is exported/imported in a share library...
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
std::bidirectional_iterator_tag iterator_category
An Iterator trait.
Definition: nodeiterator.h:110
Used to give commands specifically to the SWIG preprocessor.
Node & reference
An Iterator trait.
Definition: nodeiterator.h:172
Node value_type
An Iterator trait.
Definition: nodeiterator.h:166
Node & reference
An Iterator trait.
Definition: nodeiterator.h:107