Robotics Library  0.7.0
NodeSet.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2009, Markus Rickert
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 //
8 // * Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and/or other materials provided with the distribution.
13 //
14 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 // POSSIBILITY OF SUCH DAMAGE.
25 //
26 
27 #ifndef RL_XML_NODESET_H
28 #define RL_XML_NODESET_H
29 
30 #include <memory>
31 #include <stdexcept>
32 #include <libxml/xpath.h>
33 
34 #include "Node.h"
35 
36 namespace rl
37 {
38  namespace xml
39  {
40  class NodeSet
41  {
42  public:
43  explicit NodeSet(::xmlNodeSetPtr nodeSet) :
44  nodeSet(nodeSet, ::xmlXPathFreeNodeSet)
45  {
46  }
47 
48  explicit NodeSet(const ::std::shared_ptr< ::xmlNodeSet>& nodeSet) :
50  {
51  }
52 
54  {
55  }
56 
57  Node at(const int& i) const
58  {
59  if (i < 0 || i >= this->size())
60  {
61  throw ::std::out_of_range("rl::xml::Node::at() out of range");
62  }
63 
64  return Node(this->nodeSet->nodeTab[i]);
65  }
66 
67  bool empty() const
68  {
69  return 0 == this->size();
70  }
71 
72  ::xmlNodeSetPtr get() const
73  {
74  return this->nodeSet.get();
75  }
76 
77  int max_size() const
78  {
79  return this->nodeSet->nodeMax;
80  }
81 
82  ::xmlNodeSet& operator*() const
83  {
84  return *this->nodeSet;
85  }
86 
87  Node operator[](const int& i) const
88  {
89  return Node(this->nodeSet->nodeTab[i]);
90  }
91 
92  int size() const
93  {
94  return this->nodeSet->nodeNr;
95  }
96 
97  protected:
98 
99  private:
100  ::std::shared_ptr< ::xmlNodeSet> nodeSet;
101  };
102  }
103 }
104 
105 #endif // RL_XML_NODESET_H
rl::xml::NodeSet::operator*
::xmlNodeSet & operator*() const
Definition: NodeSet.h:82
rl::xml::NodeSet::size
int size() const
Definition: NodeSet.h:92
rl::xml::NodeSet::NodeSet
NodeSet(::xmlNodeSetPtr nodeSet)
Definition: NodeSet.h:43
rl::xml::NodeSet::max_size
int max_size() const
Definition: NodeSet.h:77
rl::xml::NodeSet::nodeSet
::std::shared_ptr< ::xmlNodeSet > nodeSet
Definition: NodeSet.h:100
rl::xml::Node
Definition: Node.h:46
Node.h
rl::xml::NodeSet::NodeSet
NodeSet(const ::std::shared_ptr< ::xmlNodeSet > &nodeSet)
Definition: NodeSet.h:48
rl::xml::NodeSet::at
Node at(const int &i) const
Definition: NodeSet.h:57
rl::xml::NodeSet::get
::xmlNodeSetPtr get() const
Definition: NodeSet.h:72
rl::xml::NodeSet::operator[]
Node operator[](const int &i) const
Definition: NodeSet.h:87
rl::xml::NodeSet
Definition: NodeSet.h:41
rl::xml::NodeSet::empty
bool empty() const
Definition: NodeSet.h:67
rl
Robotics Library.
Definition: AnalogInput.cpp:30
rl::xml::NodeSet::~NodeSet
~NodeSet()
Definition: NodeSet.h:53