MIRA
XMLDomReflect.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 by
3  * MetraLabs GmbH (MLAB), GERMANY
4  * and
5  * Neuroinformatics and Cognitive Robotics Labs (NICR) at TU Ilmenau, GERMANY
6  * All rights reserved.
7  *
8  * Contact: info@mira-project.org
9  *
10  * Commercial Usage:
11  * Licensees holding valid commercial licenses may use this file in
12  * accordance with the commercial license agreement provided with the
13  * software or, alternatively, in accordance with the terms contained in
14  * a written agreement between you and MLAB or NICR.
15  *
16  * GNU General Public License Usage:
17  * Alternatively, this file may be used under the terms of the GNU
18  * General Public License version 3.0 as published by the Free Software
19  * Foundation and appearing in the file LICENSE.GPL3 included in the
20  * packaging of this file. Please review the following information to
21  * ensure the GNU General Public License version 3.0 requirements will be
22  * met: http://www.gnu.org/copyleft/gpl.html.
23  * Alternatively you may (at your option) use any later version of the GNU
24  * General Public License if such license has been publicly approved by
25  * MLAB and NICR (or its successors, if any).
26  *
27  * IN NO EVENT SHALL "MLAB" OR "NICR" BE LIABLE TO ANY PARTY FOR DIRECT,
28  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
29  * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLAB" OR
30  * "NICR" HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * "MLAB" AND "NICR" SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
33  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
34  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
35  * ON AN "AS IS" BASIS, AND "MLAB" AND "NICR" HAVE NO OBLIGATION TO
36  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
37  */
38 
49 #ifndef _MIRA_XMLDOMREFLECT_H_
50 #define _MIRA_XMLDOMREFLECT_H_
51 
55 
56 namespace mira {
57 
59 
60 MIRA_SPLIT_REFLECT(XMLDom)
61 
62 
66 template <typename Reflector>
67 void reflectRead(Reflector& r, XMLDom& xml)
68 {
69  std::string s = xml.saveToString();
70  r.delegate(s, REFLECT_CTRLFLAG_TEMP_TRACKING);
71 }
72 
74 template <typename Reflector>
75 void reflectWrite(Reflector& r, XMLDom& xml)
76 {
77  std::string s;
78  r.delegate(s, REFLECT_CTRLFLAG_TEMP_TRACKING);
79  xml.loadFromString(s);
80 }
81 
87 inline void reflect(XMLSerializer& r, XMLDom& xml)
88 {
89  XMLDom::iterator node = r.getNode();
90  for(XMLDom::const_iterator it = xml.root().begin(); it!=xml.root().end(); ++it)
91  {
92  XMLDom::iterator newnode = node.add_child("dummy");
93  newnode.replace(it);
94  }
95 }
96 
102 inline void reflect(XMLDeserializer& r, XMLDom& xml)
103 {
104  XMLDom::iterator rt = xml.root();
105  // replace root to ensure complete transfer of source info (uri/line)
106  rt.replace(r.getNode());
107  // the name of the source node is the xml member's name in the parent object
108  // rename back to 'root' for well-defined xml
109  rt.setName("root");
110 }
111 
112 template <typename SerializerTag>
113 class IsTransparentSerializable<XMLDom, SerializerTag> : public std::true_type {};
114 
115 template <>
116 class IsTransparentSerializable<XMLDom, XMLSerializerTag> : public std::false_type {};
117 
119 
120 }
121 
122 #endif
This object can use object tracking internally, but the object tracking system&#39;s state remains unchan...
Definition: ReflectControlFlags.h:82
void reflectWrite(Reflector &r, Buffer< T, Allocator > &c)
Specialization of the non-intrusive reflect for Buffer.
Definition: Buffer.h:581
const_sibling_iterator root() const
Return a const sibling_iterator to the root node of the XML document.
Definition: XMLDom.h:1213
A STL conform wrapper for libxml2 to read XML files as DOM.
Definition: XMLDom.h:73
Type trait that indicates whether a type should be serialized "transparently", i.e.
Definition: IsTransparentSerializable.h:81
#define MIRA_SPLIT_REFLECT(Type)
Macro that inserts a reflect() method consisting of just a call to splitReflect() (splitting to refle...
Definition: SplitReflect.h:150
const_sibling_iterator end() const
Get the const end node sibling_iterator.
Definition: XMLDom.h:542
Definition: XMLSerializer.h:121
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
XMLDom::iterator getNode()
Accessor for special serialize/deserialize methods below.
Definition: XMLSerializer.h:267
Provides type trait that indicates whether a type should be serialized "transparently".
Provides MIRA_SPLIT_REFLECT macros.
Const sibling_iterator for iterating over xml nodes that have the same parent (siblings) ...
Definition: XMLDom.h:671
Serializer for serializing objects in XML format.
Definition: XMLSerializer.h:119
const_sibling_iterator begin() const
Get the const sibling_iterator to the first sub node.
Definition: XMLDom.h:516
void reflect(Reflector &r, LogRecord &record)
Non-intrusive reflector for LogRecord.
Definition: LoggingCore.h:137
Iterator for iterating over xml nodes that have the same parent (sibligs)
Definition: XMLDom.h:758
void reflectRead(Reflector &r, Buffer< T, Allocator > &c)
Specialization of the non-intrusive reflect for Buffer.
Definition: Buffer.h:565
XMLSerializer and XMLDeserializer.
XMLDom::sibling_iterator add_child(const std::string &name, const NameSpace &ns=NameSpace())
Add a sub node to this node.
void loadFromString(const std::string &buffer)
Load and parse an XML document from memory.
void setName(const std::string &name)
Change the node&#39;s name.
XMLDom::sibling_iterator replace(const XMLDom::const_sibling_iterator &node)
Replaces this node by a recursive copy of iNode.
std::string saveToString(const std::string &encoding="UTF-8") const
Save the XML document to a string.
XMLDom::const_iterator getNode()
Definition: XMLSerializer.h:591
Deserializer for serializing objects from XML format.
Definition: XMLSerializer.h:313