MIRA
XMLSerializer.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 
47 #ifndef _MIRA_XMLSERIALIZER_H_
48 #define _MIRA_XMLSERIALIZER_H_
49 
50 #include <iostream>
51 #include <list>
52 #include <algorithm>
53 
54 #ifndef Q_MOC_RUN
55 #include <boost/algorithm/string.hpp>
56 #include <boost/range/algorithm.hpp>
57 #include <boost/range/algorithm_ext/erase.hpp>
58 #endif
59 
63 
64 #include <xml/XMLDom.h>
65 
66 namespace mira {
67 
69 
71 namespace Private {
72 
73 inline std::string replaceSpaces(const std::string& s)
74 {
75  return boost::replace_all_copy(s, " ", "_");
76 }
77 
78 inline std::string replaceSpecialChars(const std::string& s)
79 {
80  std::string result = boost::replace_all_copy(s, " ", "_");
81  boost::remove_erase_if(result, boost::is_any_of("[]"));
82  return result;
83 }
84 
85 } // namespace
86 
88 
120 
121 class XMLSerializer : public Serializer<XMLSerializer>
122 {
124 
125 public:
127 
130  {
131  STANDARD = 0x00,
132  NO_COMMENTS = 0x01,
133  COMPRESSED = 0x02,
134  };
135 
136  MIRA_ENUM_TO_FLAGS_INCLASS(OutputFormat) // generate logical operators for enum values
137 
138 
145  mRoot(iXmlDom.root()), mNode(iXmlDom.root()), mOutputFormat(format)
146  {
147  }
148 
156  mRoot(iRoot), mNode(iRoot), mOutputFormat(format)
157  {
158  }
159 
161 
162  template <typename T>
163  VersionType version(VersionType version, const T* caller = NULL)
164  {
165  return this->version<T>(version, false);
166  }
167 
168  MIRA_DEPRECATED("Please call as version<MyType>(v) or version(v, this)",
170  {
171  // add version - backward compatible variant if no caller type provided
172  return versionLegacy(version);
173  }
174 
175  template <typename T>
177  {
178  return this->version<T>(version, true);
179  }
180 
181 private:
182 
183  template <typename T>
184  VersionType version(VersionType version, bool acceptDesiredVersion)
185  {
186  version = this->template queryDesiredClassVersion<T>(version, acceptDesiredVersion);
187 
188  int vf = this->forcedSerializeVersion();
189  if ((vf == 0) || (vf == 1))
190  return versionLegacy(version);
191 
192  // add version
193  mNode.add_child("version").add_attribute("type", typeName<T>())
194  .add_content(toString((int)version));
195  return version;
196  }
197 
198  VersionType versionLegacy(VersionType version)
199  {
200  mNode.add_attribute("version", toString((int)version) );
201  return version;
202  }
203 
204 public:
205 
206  template<typename T>
207  void atomic(T& member)
208  {
209  const ReflectMemberMeta& meta = getCurrentMemberMeta();
210  if (mOutputFormat & COMPRESSED)
211  mNode.add_attribute(Private::replaceSpecialChars(meta.id), toString(member,12));
212  else
213  {
214  if(!(mOutputFormat & NO_COMMENTS) && meta.comment!=NULL && strlen(meta.comment)>0)
215  mNode.add_comment(meta.comment);
216  mNode.add_child(Private::replaceSpaces(meta.name)).add_content(toString(member,12));
217  }
218  }
219 
220  template<typename T>
221  void object(T& member)
222  {
223  const ReflectMemberMeta& meta = getCurrentMemberMeta();
224 
225  // create a new node
226  if(!(mOutputFormat & NO_COMMENTS) && meta.comment!=NULL && strlen(meta.comment)>0)
227  mNode.add_comment(meta.comment);
228  XMLDom::iterator i = mNode.add_child(Private::replaceSpaces(meta.name));
229 
230  // enter the new node
231  mNode = i;
232 
233  if(!mPointerClass.empty()) {
234  mNode.add_attribute("class", mPointerClass);
235  mPointerClass.clear();
236  }
237 
239 
240  // leave the node
241  mNode = mNode.parent();
242  assert(mNode!=mRoot.end());
243 
244  }
245 
246  // Stores a reference to a previously serialized object using the "ref" attribute.
247  void pointerReference(int referencedObjectID) {
248  const char* name = getCurrentMemberMeta().name;
249  mNode.add_child(Private::replaceSpaces(name)).add_attribute("ref", this->getHumanReadableFullID(referencedObjectID));
250  }
251 
252  // Stores the class type the "class" attribute.
253  void pointerWithClassType(const std::string& type) {
254  mPointerClass = type;
255  //mNode.add_attribute("class", type);
256  }
257 
258  // Stores a NULL pointer using the "nullptr" attribute.
259  void pointerNull() {
260  const char* name = getCurrentMemberMeta().name;
261  mNode.add_child(Private::replaceSpaces(name)).add_attribute("nullptr", "true");
262  }
263 
264 public:
265 
267  XMLDom::iterator getNode() { return mNode; }
268 
269 private:
270 
272  XMLDom::iterator mRoot;
273 
274  // iterator to the current node
275  XMLDom::iterator mNode;
276 
277  std::string mPointerClass;
278 
279  OutputFormat mOutputFormat;
280 
281 };
282 
284 
314 {
316 public:
317 
322  XMLDeserializer(const XMLDom& iXmlDom) :
323  mRoot(iXmlDom.root()), mNode(iXmlDom.root())
324  {
325  }
326 
332  mRoot(iRoot), mNode(iRoot)
333  {
334  }
335 
336 
339  template <typename T>
340  void deserialize(const std::string& name, T& value)
341  {
342  mDeserializeFromThisNode=false;
343  mNextFindIteratorStack.clear();
344  pushFindStack();
345  try {
346  Base::deserialize(name,value);
347  } catch (Exception& ex) {
348  MIRA_RETHROW(ex, "in tag starting at: " << mNode.uri() << "(" << mNode.line() << ")");
349  }
350  popFindStack();
351  }
352 
357  template <typename T>
358  void deserializeFromNode(const char* name, T& value)
359  {
360  mDeserializeFromThisNode=true;
361  mNextFindIteratorStack.clear();
362  pushFindStack();
363  try {
364  Base::deserialize(name,value);
365  } catch (Exception& ex) {
366  MIRA_RETHROW(ex, "in tag starting at: " << mNode.uri()
367  << "(" << mNode.line() << ")");
368  }
369  popFindStack();
370  }
371 
373 
374  template <typename T>
375  VersionType version(VersionType expectedVersion, const T* caller = NULL)
376  {
377  // obtain version
378 
379  int vf = this->forcedDeserializeVersion();
380  if ((vf == 0) || (vf == 1))
381  return versionLegacy(expectedVersion);
382 
383  std::string type = typeName<T>();
384  for (int n = 0; true; ++n) {
385  XMLDom::const_sibling_iterator versionNode = mNode.find("version", n);
386  if (versionNode == mNode.cend()) {
387  if (mNode.has_attribute("version")) {
388  MIRA_LOG(WARNING) << "Failed finding version for type '" << type << "', "
389  "but read an anonymous version attribute instead. "
390  "Please update your config xml ("
391  << mNode.uri() << " , line " << mNode.line() << ").";
392 
393  VersionType version = mNode.get_attribute<int>("version");
394  checkVersion<T>(version, expectedVersion);
395  return version;
396  }
397  return 0;
398  }
399 
400  // 'version' elements without 'type' attribute are ignored here, allowing
401  // to still use 'version' as part of the actual data
402  if (versionNode.get_attribute<std::string>("type", "") == type) {
403  VersionType version = fromString<int>(*versionNode.content_begin());
404  checkVersion<T>(version, expectedVersion);
405  return version;
406  }
407  }
408  }
409 
410  MIRA_DEPRECATED("Please call as version<MyType>(v) or version(v, this)",
411  VersionType version(VersionType expectedVersion))
412  {
413  // obtain version - backward compatible variant if no caller type provided
414  return versionLegacy(expectedVersion);
415  }
416 
417  template <typename T>
418  VersionType version(VersionType expectedVersion, AcceptDesiredVersion, const T* caller = NULL)
419  {
420  return this->version<T>(expectedVersion);
421  }
422 
423 private:
424 
425  VersionType versionLegacy(VersionType expectedVersion)
426  {
427  VersionType version = mNode.get_attribute<int>("version", 0);
428  checkVersion<void>(version, expectedVersion);
429  return version;
430  }
431 
432  template <typename T>
433  void checkVersion(VersionType version, VersionType expectedVersion)
434  {
435  if (version > expectedVersion) {
436  MIRA_LOG(WARNING) << "Trying to deserialize XML data of a newer version (" << (int)version <<
437  ") of type " << typeName<T>() << " into an older version (" << (int)expectedVersion << ").";
438  }
439  }
440 
441 public:
442 
443  template<typename T>
444  void atomic(T& member)
445  {
446  Base::atomic(member);
447 
448  if(mAtomicFromAttribute.empty())
449  member = fromString<T>(*mNode.content_begin());
450  else // try to get the value from the attribute
451  // (which should exists, since this is checked in invokeMemberOverwrite)
452  member = mNode.get_attribute<T>(mAtomicFromAttribute); //uses fromString<T> internally
453  }
454 
455  void beginTag(const ReflectMemberMeta& meta)
456  {
457  if(meta.name!=NULL) {
458  if(!mAtomicFromAttribute.empty()) {
459  MIRA_THROW(XIO, "Cannot deserialize '" << mAtomicFromAttribute <<
460  "' from an attribute as it is a complex type, that "
461  "must be stored as an XML node.");
462  }
463 
464  XMLDom::const_iterator i = findNext(Private::replaceSpaces(meta.name));
465  if(i!=mNode.end()) {
466  // found it, so set it as current node
467  mNode = i;
468  } else {
469  // node not found
470  MIRA_THROW(XMemberNotFound, "Node '"
471  << Private::replaceSpaces(meta.name)
472  << "' is missing"); // hence we have to abort with an exception
473  }
474  pushFindStack();
475  }
476  }
477 
478  void endTag(const ReflectMemberMeta& meta)
479  {
480  if(meta.name!=NULL) {
481  assert(mNode!=mRoot); // we will never go above the root node.
482  popFindStack();
483  mNode = mNode.parent();
484  assert(mNode!=mRoot.end());
485  }
486  }
487 
488  /*
489  * Overwrites Deserializer::pointer.
490  * This method checks, if there is a pointer reference specified
491  * (the ref attribute is present). If so, it reads the referenced full id
492  * of the previously stored object and uses resolveReference() to get the
493  * pointer to that previously deserialized object.
494  * Otherwise it calls pointer() of the Deserializer base class to
495  * deserialize the full object.
496  */
497  template<typename T>
498  void pointer(T* &pointer)
499  {
500  // do we have a null pointer?
501  if(mNode.get_attribute<std::string>("nullptr","false") == "true") {
502  pointer = NULL;
503  return;
504  }
505 
506  // do we have a reference?
507  std::string ref = mNode.get_attribute<std::string>("ref","");
508  if(ref.size()>0) {
509  // we have a reference, so resolve it
510  pointer = resolveReference<T>(ref);
511  return;
512  }
513 
514  // we have a "normal" pointer, so deserialize it
515  Base::pointer(pointer);
516  }
517 
518  std::string pointerClassType()
519  {
520  return mNode.get_attribute<std::string>("class","");
521  }
522 
523  // hijack the invokeOverwrite method for adding a starting and closing tag
524  // around the serialized data
525  template<typename T>
526  void invokeMemberOverwrite(T& member, const ReflectMemberMeta& meta)
527  {
528  bool fromThisNode = mDeserializeFromThisNode;
529  bool fromAttribute = false;
530 
531  if(!fromThisNode) {
532  try {
533  beginTag(meta);
534  } catch(XMemberNotFound& ex) {
535  // member of value not found, if it is an atomic type
536  // we can still try to get the value from an attribute with
537  // the same name
538  // (however, the following reserved attributes are
539  // not allowed: version, nullptr, ref, class)
540  std::string id = Private::replaceSpecialChars(meta.id);
541  try {
542  if(id!="version" &&
543  id!="nullptr" &&
544  id!="ref" &&
545  id!="class")
546  {
547  // check if the attribute exists
548  if(!mNode.has_attribute(id)) {
549  MIRA_THROW(XMemberNotFound, "Node (or attribute) '" << id <<
550  "' is missing");
551  }
552  mAtomicFromAttribute = id;
553  fromAttribute = true;
554  } else {
555  // otherwise rethrow the exception since we cannot do anything
556  throw;
557  }
558  }
559  catch(Exception& ex) {
560  MIRA_RETHROW(ex, "in tag starting at: " << mNode.uri() << "(" << mNode.line() << ")");
561  }
562 
563  }
564  }
565 
566  mDeserializeFromThisNode=false;
567 
568  try {
569  Base::invokeMemberOverwrite(member, meta);
570  } catch(...) {
571  // make sure our find stack is correctly unwound and the correct
572  // node in the XML file is maintained if an exception
573  // is thrown somewhere in our child nodes (fixes #536)
574  mAtomicFromAttribute.clear();
575  if(!fromThisNode && !fromAttribute) {
576  endTag(meta); // finish this tag and ...
577  rewindFindIterator(meta.getName()); // ... 'undo' read so we can re-try in a handler and ...
578  }
579  throw; // ... rethrow
580  }
581 
582  // hm, this cleanup code is a duplicate of the above cleanup
583  // code in the event of an exception
584  mAtomicFromAttribute.clear();
585  if(!fromThisNode && !fromAttribute)
586  endTag(meta);
587  }
588 
589 public: // accessors for special serialize/deserialize methods below
590 
591  XMLDom::const_iterator getNode() { return mNode; }
592 
593 private:
594 
597 
600 
601  bool mDeserializeFromThisNode;
602 
608  std::string mAtomicFromAttribute;
609 
610 private:
611  // Necessary to allow multiple nodes with the same name.
612  // Here we store the iterators of previous searches for
613  // a certain nodes, the next search will then continue
614  // after the previous found iterator.
615  // Those iterators must be stored in a stack for each
616  // level of the XML tree.
617  typedef std::map<std::string, XMLDom::const_iterator> NextFindIteratorMap;
618  std::list<NextFindIteratorMap> mNextFindIteratorStack;
619 
620  XMLDom::const_iterator findNext(const std::string& name)
621  {
622  assert(mNextFindIteratorStack.size()>=1);
623  NextFindIteratorMap& m = mNextFindIteratorStack.back();
624 
625  XMLDom::const_iterator i = mNode.end();
626  XMLDom::const_iterator j = mNode.begin();
627 
628  // check if we have searched for the name already
629  NextFindIteratorMap::iterator p = m.find(name);
630  if(p!=m.end()) {
631  // we already searched for name
632  // so continue search from successor of previous find
633  j = p->second;
634  ++j;
635  }
636  i = find(j, mNode.end(), name);
637 
638  // if we found something, save the position for next search
639  if(i!=mNode.end())
640  m[name] = i;
641 
642  return i;
643  }
644 
645  // is called when we enter a new node
646  void pushFindStack()
647  {
648  mNextFindIteratorStack.push_back(NextFindIteratorMap());
649  }
650 
651  // is called when we leave a node
652  void popFindStack()
653  {
654  mNextFindIteratorStack.pop_back();
655  }
656 
657  void rewindFindIterator(const std::string& name)
658  {
659  assert(mNextFindIteratorStack.size()>=1);
660  NextFindIteratorMap& m = mNextFindIteratorStack.back();
661 
662  NextFindIteratorMap::iterator p = m.find(name);
663  if(p==m.end())
664  return;
665 
666  if (m[name] == mNode.begin())
667  m.erase(name);
668  else
669  --(m[name]);
670  }
671 
672 
673 };
674 
676 
677 // specializations for STL containers
678 
679 namespace serialization { // our private namespace
680 
682 
690 template<typename Collection>
691 struct ReflectCollectionCount<XMLSerializer, Collection>
692 {
693  static void reflect(XMLSerializer& r, uint32& ioCount)
694  {
695  // do nothing
696  }
697 };
698 
699 template<typename Collection, bool HasKeyType = true, bool HasMappedType = true>
700 struct CheckKeyCount
701 {
702  static void check(XMLDom::const_iterator node, uint32 itemCount)
703  {
704  // nothing to do here if Collection is not a map (default)
705  }
706 };
707 
708 // if Collection has a definition for key_type and mapped_type (other than void), assume it is a map
709 // -> expect a <key> tag for each <item> tag
710 // (key_type alone is not sufficient as it also exists e.g. in std::set)
711 template<typename Collection>
712 struct CheckKeyCount<Collection,
713  (bool)!std::is_void_v<typename Collection::key_type>,
714  (bool)!std::is_void_v<typename Collection::mapped_type>>
715 {
716  struct IsKey {
717  bool operator()(const XMLDom::Attribute& attr) {
718  return boost::algorithm::starts_with(attr.first, "key");
719  }
720  };
721 
722  static void check(XMLDom::const_iterator node, uint32 itemCount)
723  {
724  uint32 keyCount = (uint32)std::count(node.begin(), node.end(), "key");
725 
726  if (keyCount == 0) {
727  // there might be attributes instead
728  keyCount = (uint32)std::count_if(node.attribute_cbegin(), node.attribute_cend(),
729  IsKey());
730  }
731  if (keyCount != itemCount) {
732  MIRA_THROW(XIO, "Node for map (or map-like collection) has " << keyCount
733  << " <key> tags and " << itemCount << " <item> tags.");
734  }
735  }
736 };
737 
744 template<typename Collection>
745 struct ReflectCollectionCount<XMLDeserializer, Collection>
746 {
747  struct IsItem {
748  bool operator()(const XMLDom::Attribute& attr) {
749  return boost::algorithm::starts_with(attr.first, "item");
750  }
751  };
752 
753  static void reflect(XMLDeserializer& r, uint32& ioCount)
754  {
755  XMLDom::const_iterator node = r.getNode();
756 
757  // count the "item" nodes
758  ioCount = (uint32)std::count(node.begin(), node.end(), "item");
759 
760  if (ioCount == 0) {
761  // there might be attributes instead
762  ioCount = (uint32)std::count_if(node.attribute_cbegin(), node.attribute_cend(),
763  IsItem());
764  }
765 
766  CheckKeyCount<Collection>::check(node, ioCount);
767  }
768 };
769 
770 template<typename Reflector, typename Container> struct ReflectReadMapItems;
771 
776 template<typename Container>
777 struct ReflectReadMapItems<XMLSerializer, Container>
778 {
779  typedef typename Container::value_type value_type;
780  typedef typename Container::key_type key_type;
781 
782  static void reflect(XMLSerializer& r, Container& c)
783  {
784  // store each item
785  int id=0;
786  foreach(value_type& p, c)
787  {
788  key_type& nonconstkey = const_cast<key_type&>(p.first);
789  // no tracking on this one, see ReflectReadMapPair
790  MIRA_MEMBER_WITH_ID(r, "key", "key["+toString(id)+"]", nonconstkey, "",
792 
793  // the values can be reflected/deserialized with tracking
794  MIRA_PROPERTY_WITH_ID(r, "item", "item["+toString(id)+"]", p.second, "");
795 
796  ++id;
797  }
798  }
799 };
800 
801 template<typename Reflector, typename Container> struct ReflectWriteMapItems;
802 
807 template<typename Container>
808 struct ReflectWriteMapItems<XMLDeserializer, Container>
809 {
810  typedef typename Container::iterator iterator;
811  typedef typename Container::value_type value_type;
812  typedef typename Container::key_type key_type;
813  typedef typename Container::mapped_type mapped_type;
814 
815  static void reflect(XMLDeserializer& r, Container& c, uint32 count)
816  {
817  iterator hint = c.begin();
818 
819  // reflect key
820  key_type key;
821 
822  for(uint32 id=0; id<count; ++id) {
823 
824  if(IsPointerOrSharedPointer<key_type>::value) {
825  MIRA_MEMBER_WITH_ID(r, "key", "key["+toString(id)+"]", key, "");
826  } else {
827  // we have to deserialize the key to a temp object, cannot restore references to it !!!
828  MIRA_MEMBER_WITH_ID(r, "key", "key["+toString(id)+"]", key, "", REFLECT_CTRLFLAG_TEMP_TRACKING);
829  }
830 
831  // insert a dummy value with the key
832  iterator it = c.insert(hint, value_type(key, mapped_type()));
833  hint = it; // the iterator will be insertion hint for next element
834 
835  // reflect the value directly into the map item
836  // the values can be reflected/deserialized with tracking
837  MIRA_PROPERTY_WITH_ID(r, "item", "item["+toString(id)+"]", it->second, "");
838  }
839  }
840 };
841 
843 
844 } // namespace
845 
847 
849 
850 } // namespace
851 
852 #endif
This object can use object tracking internally, but the object tracking system&#39;s state remains unchan...
Definition: ReflectControlFlags.h:82
T get_attribute(const std::string &name) const
Return an attribute value cast to a given type.
Definition: XMLDom.h:633
Provides type trait that indicates whether a type is a pointer type or a shared pointer.
A STL conform DOM reader/writer for XML.
Container::iterator iterator
Definition: StlCollections.h:393
void object(T &member)
Is called for each complex object.
Definition: RecursiveMemberReflector.h:301
A STL conform wrapper for libxml2 to read XML files as DOM.
Definition: XMLDom.h:73
std::string getName() const
Definition: ReflectMemberMeta.h:82
const_sibling_iterator end() const
Get the const end node sibling_iterator.
Definition: XMLDom.h:542
MIRA_DEPRECATED("Please call as version<MyType>(v) or version(v, this)", VersionType version(VersionType expectedVersion))
Definition: XMLSerializer.h:410
Contains the Serializer template, a base class for all serializers.
std::string pointerClassType()
Definition: XMLSerializer.h:518
#define MIRA_PROPERTY_WITH_ID(reflector, name, id, var,...)
Definition: ReflectorInterface.h:1009
typename ReflectorInterface< XMLSerializer >::AcceptDesiredVersion AcceptDesiredVersion
Definition: AbstractReflector.h:195
void deserialize(const std::string &name, T &value)
overwritten from Deserializer, to handle exceptions and to add additional information about file name...
Definition: XMLSerializer.h:340
Definition: XMLSerializer.h:121
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
void member(const char *name, T &member, const char *comment, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: RecursiveMemberReflector.h:862
OutputFormat format
Definition: XMLSerializer.h:144
const std::string & getHumanReadableFullID(int objectID) const
Returns the full human readable object id / name for the given internal objectID. ...
Definition: Serializer.h:456
XMLDom::iterator getNode()
Accessor for special serialize/deserialize methods below.
Definition: XMLSerializer.h:267
VersionType version(VersionType version, AcceptDesiredVersion, const T *caller=NULL)
Definition: XMLSerializer.h:176
Is a special reflector that is used for serialization.
Definition: Serializer.h:126
XMLDeserializer(const XMLDom::const_iterator &iRoot)
Create a new XML deserialization on top of the passed XMLDom iterator node.
Definition: XMLSerializer.h:331
#define MIRA_LOG(level)
Use this macro to log data.
Definition: LoggingCore.h:529
STL namespace.
#define MIRA_RETHROW(ex, msg)
Macro for rethrowing an exception with file and line information and for adding additional informatio...
Definition: Exception.h:148
No comments are written to output document.
Definition: XMLSerializer.h:132
Stores meta information for each member.
Definition: ReflectMemberMeta.h:64
const_content_iterator content_begin() const
Get the const iterator to the first content.
Definition: XMLDom.h:557
const char * name
The name (as specified in the XML file).
Definition: ReflectMemberMeta.h:67
sibling_iterator end()
Get the end node sibling_iterator.
VersionType version(VersionType version, const T *caller=NULL)
Definition: XMLSerializer.h:163
uint8 VersionType
Definition: ReflectorInterface.h:72
#define MIRA_THROW(ex, msg)
Macro for throwing an exception.
Definition: Exception.h:82
std::string toString(const T &value, int precision=-1)
Converts any data type to string (the data type must support the stream << operator).
Definition: ToString.h:256
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 ReflectMemberMeta & getCurrentMemberMeta() const
Returns the meta-information of the current member that is reflected.
Definition: RecursiveMemberReflector.h:459
XMLDom::sibling_iterator & add_content(const std::string &content)
Add content to this node.
static void reflect(Reflector &r, uint32 &ioCount)
Definition: ReflectCollection.h:71
std::pair< std::string, std::string > Attribute
An XML attribute.
Definition: XMLDom.h:86
static void reflect(Reflector &r, Container &c)
Definition: StlCollections.h:343
static void reflect(Reflector &r, Container &c, uint32 count)
Definition: StlCollections.h:395
XMLDom::sibling_iterator & add_attribute(const Attribute &attribute)
Add an attribute to this node.
PropertyHint type(const std::string &t)
Sets the attribute "type" to the specified value.
Definition: PropertyHint.h:295
Default format.
Definition: XMLSerializer.h:131
Contains base class for all deserializers.
void endTag(const ReflectMemberMeta &meta)
Definition: XMLSerializer.h:478
Container::value_type value_type
Definition: StlCollections.h:341
OutputFormat
Flags for XML output format.
Definition: XMLSerializer.h:129
const_sibling_iterator begin() const
Get the const sibling_iterator to the first sub node.
Definition: XMLDom.h:516
void pointerNull()
Definition: XMLSerializer.h:259
void invokeMemberOverwrite(T &member, const ReflectMemberMeta &meta)
Definition: XMLSerializer.h:526
const_sibling_iterator cend() const
Get the const end node sibling_iterator.
XMLDom::sibling_iterator & add_comment(const std::string &comment)
Add a comment to this node.
void pointer(T *&pointer)
Definition: XMLSerializer.h:498
Iterator for iterating over xml nodes that have the same parent (sibligs)
Definition: XMLDom.h:758
const char * comment
Additional user comments.
Definition: ReflectMemberMeta.h:76
void object(T &member)
Definition: XMLSerializer.h:221
Base class for exceptions.
Definition: Exception.h:199
Base::VersionType VersionType
Definition: Serializer.h:154
serialization::VersionType VersionType
Definition: XMLSerializer.h:372
VersionType version(VersionType expectedVersion, const T *caller=NULL)
Definition: XMLSerializer.h:375
typename ReflectorInterface< XMLSerializer >::VersionType VersionType
Definition: AbstractReflector.h:165
static int forcedSerializeVersion()
Returns either the version number from value of environment variable &#39;MIRA_FORCE_SERIALIZE_VERSION&#39;, or -1 (= do not force a version).
Definition: Serializer.h:145
void pointerWithClassType(const std::string &type)
Definition: XMLSerializer.h:253
const_sibling_iterator const_iterator
Definition: XMLDom.h:1113
Definition: LoggingCore.h:76
void atomic(T &member)
Definition: XMLSerializer.h:444
sibling_iterator parent()
Get the parent node sibling_iterator for this node.
VersionType version(VersionType expectedVersion, AcceptDesiredVersion, const T *caller=NULL)
Definition: XMLSerializer.h:418
#define MIRA_MEMBER_WITH_ID(reflector, name, id, var,...)
Macro that should be used to reflect a member if a manually specified ID is used. ...
Definition: ReflectorInterface.h:1003
atomic members are written as attributes instead of childs
Definition: XMLSerializer.h:133
void deserializeFromNode(const char *name, T &value)
In contrast to the deserialize() method this method will use the node that was specified in the const...
Definition: XMLSerializer.h:358
XMLDom::sibling_iterator add_child(const std::string &name, const NameSpace &ns=NameSpace())
Add a sub node to this node.
void atomic(T &member)
Definition: XMLSerializer.h:207
XMLDeserializer(const XMLDom &iXmlDom)
Create a new XML deserialization on top of the passed XMLDom document.
Definition: XMLSerializer.h:322
MIRA_DEPRECATED("Please call as version<MyType>(v) or version(v, this)", VersionType version(VersionType version))
Definition: XMLSerializer.h:168
void beginTag(const ReflectMemberMeta &meta)
Definition: XMLSerializer.h:455
MIRA_ENUM_TO_FLAGS_INCLASS(OutputFormat) XMLSerializer(XMLDom &iXmlDom
Create a new XML serialization on top of the passed XMLDom document.
const char * id
The id (used for containers where the name is identical, in all other cases the id usually is equal t...
Definition: ReflectMemberMeta.h:73
void pointerReference(int referencedObjectID)
Definition: XMLSerializer.h:247
XMLDom::const_iterator getNode()
Definition: XMLSerializer.h:591
XMLSerializerTag Tag
Definition: XMLSerializer.h:126
Deserializer for serializing objects from XML format.
Definition: XMLSerializer.h:313
const_sibling_iterator find(const std::string &name, std::size_t nth=0) const
Find the nth subnode with a given name.