Spinning Topp Logo BlackTopp Studios
inc
xpathnodeset.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 _xmlxpathnodeset_h
57 #define _xmlxpathnodeset_h
58 
59 /// @file
60 /// @brief This file contains the defintion of the @ref Mezzanine::XML::XPathNodeSet
61 
62 #include "datatypes.h"
63 #include "XML/xpathnode.h"
64 
65 
66 
67 namespace Mezzanine
68 {
69  namespace XML
70  {
71  /// @brief A fixed sized collection of nodes that an XPathQuery can work on.
73  {
74  public:
75  /// @brief The different ways a collection may or may not be ordered.
77  {
78  TypeUnsorted, ///< Not ordered
79  TypeSorted, ///< Sorted by document order (ascending)
80  TypeSortedReverse ///< Sorted by document order (descending)
81  };
82 
83  /// @brief An iterator trait. Const iterator for XPathNodes.
84  typedef const XPathNode* const_iterator;
85 
86  /// @brief Default constructor. Constructs empty set.
87  XPathNodeSet();
88 
89  /// @param begin A const XPathNode iterator at the beginning of the set of nodes.
90  /// @param end A const XPathNode iterator at the end of the set of nodes.
91  /// @param Type What XPathNodeSet::CollectionType is being used, this defaults to XPathNodeSet::TypeUnsorted
92  /// @brief Constructs a set from iterator range.
93  /// @details Data is not checked for duplicates and is not sorted according to provided Type, so be careful.
94  XPathNodeSet(const_iterator begin, const_iterator end, CollectionType Type = TypeUnsorted);
95 
96  /// @brief Destructor
97  ~XPathNodeSet();
98 
99  /// @brief Copy constructor/assignment operator
100  /// @param ns The Target to copy.
101  XPathNodeSet(const XPathNodeSet& ns);
102 
103  /// @brief Assignment Operator.
104  /// @return A reference to the freshly assigned XPathNodeSet.
105  /// @param ns The XPathNodeSet to copy.
106  XPathNodeSet& operator=(const XPathNodeSet& ns);
107 
108  /// @brief Get collection Type.
109  /// @return CollectionType
110  CollectionType Type() const;
111 
112  // Get collection size
113  /// @brief Get collection size.
114  /// @return The number of XPathNode instances as a size_t in the set
115  size_t size() const;
116 
117  /// @brief Indexing operator.
118  /// @param index A size_t indicating which XPathNode you would like to retrieve
119  /// @return A const reference to the XPathNode you requested.
120  /// @warning Out of bounds errors are checked using assert. Exceptions will not be thrown, during debugging out of bounds access will abort the termination and in production code out of bounds accesses will cause undefined behavior.
121  const XPathNode& operator[](size_t index) const;
122 
123  /// @brief Get Beginning iterator.
124  /// @return A XPathNodeSet::const_iterator to the beginning of the collection.
125  const_iterator begin() const;
126 
127  /// @brief Get Ending iterator.
128  /// @return A XPathNodeSet::const_iterator to the end of the collection.
129  const_iterator end() const;
130 
131  /// @brief Sort the collection in ascending/descending order by document order.
132  /// @param reverse If true this sorts the collection in the opposite of document order.
133  void sort(bool reverse = false);
134 
135  /// @brief Get first node in the collection by document order.
136  /// @return The first node of the, in document order as an XPathNode.
137  XPathNode first() const;
138 
139  /// @brief Check if collection is empty.
140  /// @return True if the document is empty, false otherwise.
141  bool Empty() const;
142 
143  private:
144  /// @brief Current ordering of this set
145  CollectionType TypeOrder;
146 
147  /// @internal
148  /// @brief Used to initialize the begining of the collections structure.
149  XPathNode Storage;
150 
151  /// @internal
152  /// @brief The beginning of the collection
153  XPathNode* Begin;
154 
155  /// @internal
156  /// @brief The End of the collection
157  XPathNode* End;
158 
159  void _assign(const_iterator begin, const_iterator end);
160  };
161  }
162 } // /namespace Mezzanine
163 
164 
165 
166 #endif // Include guard
167 
168 
169 /*
170  *
171  * Software, Files, Libraries and all other items referenced in this clause refers only
172  * to the contents of this file and associated documentation.
173  *
174  * Copyright © 2006-2012 Arseny Kapoulkine
175  *
176  * Permission is hereby granted, free of charge, to any person
177  * obtaining a copy of this software and associated documentation
178  * files (the "Software"), to deal in the Software without
179  * restriction, including without limitation the rights to use,
180  * copy, modify, merge, publish, distribute, sublicense, and/or sell
181  * copies of the Software, and to permit persons to whom the
182  * Software is furnished to do so, subject to the following
183  * conditions:
184  *
185  * The above copyright notice and this permission notice shall be
186  * included in all copies or substantial portions of the Software.
187  *
188  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
189  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
190  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
191  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
192  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
193  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
194  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
195  * OTHER DEALINGS IN THE SOFTWARE.
196  */
const XPathNode * const_iterator
An iterator trait. Const iterator for XPathNodes.
Definition: xpathnodeset.h:84
A fixed sized collection of nodes that an XPathQuery can work on.
Definition: xpathnodeset.h:72
The definition of the Mezzanine::XML::XPathNode.
An XPath node which can store handles to a XML::Node or an XML::Attribute.
Definition: xpathnode.h:76
Sorted by document order (ascending)
Definition: xpathnodeset.h:79
All the definitions for datatypes as well as some basic conversion functions are defined here...
CollectionType
The different ways a collection may or may not be ordered.
Definition: xpathnodeset.h:76
#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