Robotics Library  0.6.2
Path.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_PATH_H_
28 #define _RL_XML_PATH_H_
29 
30 #include <string>
31 #include <boost/shared_array.hpp>
32 #include <boost/shared_ptr.hpp>
33 #include <libxml/xpath.h>
34 
35 #include "Document.h"
36 #include "Node.h"
37 #include "Object.h"
38 
39 namespace rl
40 {
41  namespace xml
42  {
43  class Path
44  {
45  public:
46  Path(const Document& doc) :
47  context(xmlXPathNewContext(doc()), xmlXPathFreeContext),
48  doc(doc())
49  {
50  }
51 
52  virtual ~Path()
53  {
54  }
55 
56  Object eval(const ::std::string& expression)
57  {
58  this->context->node = NULL;
59 
60  return Object(
61  xmlXPathEvalExpression(
62  reinterpret_cast< const xmlChar* >(expression.c_str()),
63  this->context.get()
64  )
65  );
66  }
67 
68  Object eval(const ::std::string& expression, const Node& node)
69  {
70  this->context->node = node();
71 
72  return Object(
73  xmlXPathEvalExpression(
74  reinterpret_cast< const xmlChar* >(expression.c_str()),
75  this->context.get()
76  )
77  );
78  }
79 
80  xmlXPathContextPtr operator()() const
81  {
82  return this->context.get();
83  }
84 
85  protected:
86 
87  private:
88  ::boost::shared_ptr< xmlXPathContext > context;
89 
90  xmlDocPtr doc;
91  };
92  }
93 }
94 
95 #endif // _RL_XML_PATH_H_
rl::xml::Path::doc
xmlDocPtr doc
Definition: Path.h:90
rl::xml::Path::~Path
virtual ~Path()
Definition: Path.h:52
rl::xml::Path::eval
Object eval(const ::std::string &expression)
Definition: Path.h:56
rl::xml::Path::context
::boost::shared_ptr< xmlXPathContext > context
Definition: Path.h:88
rl::xml::Document
Definition: Document.h:44
rl::xml::Path::operator()
xmlXPathContextPtr operator()() const
Definition: Path.h:80
rl::xml::Object
Definition: Object.h:41
rl::xml::Node
Definition: Node.h:45
rl::xml::Path::Path
Path(const Document &doc)
Definition: Path.h:46
Node.h
rl::xml::Path
Definition: Path.h:44
rl::xml::Path::eval
Object eval(const ::std::string &expression, const Node &node)
Definition: Path.h:68
Object.h
Document.h
rl
Definition: Ati.cpp:35