aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
ticpp.cpp
Go to the documentation of this file.
1 /*
2 http://code.google.com/p/ticpp/
3 Copyright (c) 2006 Ryan Pusztai, Ryan Mulder
4 
5 Permission is hereby granted, free of charge, to any person obtaining a copy of
6 this software and associated documentation files (the "Software"), to deal in
7 the Software without restriction, including without limitation the rights to
8 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 the Software, and to permit persons to whom the Software is furnished to do so,
10 subject to the following conditions:
11 
12 The above copyright notice and this permission notice shall be included in all
13 copies or substantial portions of the Software.
14 
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 */
22 #define TIXML_USE_TICPP
23 #ifdef TIXML_USE_TICPP
24 
25 #include "ticpp.h"
26 #include "ticpprc.h"
27 #include "tinyxml.h"
28 #include <sstream>
29 
30 using namespace ticpp;
31 
32 // In the following Visitor functions, casting away const should be safe, as the
33 // object can only be referred to by a const &
34 bool Visitor::VisitEnter(const TiXmlDocument& doc) {
35  return VisitEnter(Document(const_cast< TiXmlDocument* >(&doc)));
36 }
37 
38 bool Visitor::VisitExit(const TiXmlDocument& doc) {
39  return VisitEnter(Document(const_cast< TiXmlDocument* >(&doc)));
40 }
41 
42 bool Visitor::VisitEnter(const TiXmlElement& element,
43  const TiXmlAttribute* firstAttribute) {
44  if (0 != firstAttribute) {
45  Attribute attribute(const_cast< TiXmlAttribute* >(firstAttribute));
46  return VisitEnter(Element(const_cast< TiXmlElement* >(&element)), &attribute);
47  } else {
48  return VisitEnter(Element(const_cast< TiXmlElement* >(&element)), 0);
49  }
50 }
51 
52 bool Visitor::VisitExit(const TiXmlElement& element) {
53  return VisitExit(Element(const_cast< TiXmlElement* >(&element)));
54 }
55 
56 bool Visitor::Visit(const TiXmlDeclaration& declaration) {
57  return Visit(Declaration(const_cast< TiXmlDeclaration* >(&declaration)));
58 }
59 
60 bool Visitor::Visit(const TiXmlStylesheetReference& stylesheet) {
61  return Visit(
62  StylesheetReference(const_cast< TiXmlStylesheetReference* >(&stylesheet)));
63 }
64 
65 bool Visitor::Visit(const TiXmlText& text) {
66  return Visit(Text(const_cast< TiXmlText* >(&text)));
67 }
68 
69 bool Visitor::Visit(const TiXmlComment& comment) {
70  return Visit(Comment(const_cast< TiXmlComment* >(&comment)));
71 }
72 
73 bool Visitor::Visit(const TiXmlUnknown& x) { return TiXmlVisitor::Visit(x); }
74 
78 }
79 
81  SetTiXmlPointer(attribute);
83 }
84 
85 Attribute::Attribute(const std::string& name, const std::string& value) {
86  SetTiXmlPointer(new TiXmlAttribute(name, value));
88 }
89 
90 void Attribute::operator=(const Attribute& copy) {
91  // Dropping the reference to the old object
93 
94  // Pointing to the new Object
96 
97  // The internal tixml pointer changed in the above line
99 }
100 
102  : Base() {
103  // Dropping the reference to the old object
105 
106  // Pointing to the new Object
108 
109  // The internal tixml pointer changed in the above line
111 }
112 
114 
118 }
119 
122  return m_tiXmlPointer->Name();
123 }
124 
125 Attribute* Attribute::Next(bool throwIfNoAttribute) const {
128 
129  if (0 == attribute) {
130  if (throwIfNoAttribute) {
131  TICPPTHROW("No more attributes found")
132  } else {
133  return 0;
134  }
135  }
136 
137  Attribute* temp = new Attribute(attribute);
138  attribute->m_spawnedWrappers.push_back(temp);
139 
140  return temp;
141 }
142 
143 Attribute* Attribute::Previous(bool throwIfNoAttribute) const {
146 
147  if (0 == attribute) {
148  if (throwIfNoAttribute) {
149  TICPPTHROW("No more attributes found")
150  } else {
151  return 0;
152  }
153  }
154 
155  Attribute* temp = new Attribute(attribute);
156  attribute->m_spawnedWrappers.push_back(temp);
157 
158  return temp;
159 }
160 
161 void Attribute::IterateNext(const std::string&, Attribute** next) const {
162  *next = Next(false);
163 }
164 
165 void Attribute::IteratePrevious(const std::string&, Attribute** previous) const {
166  *previous = Previous(false);
167 }
168 
169 void Attribute::Print(FILE* file, int depth) const {
171  m_tiXmlPointer->Print(file, depth);
172 }
173 
175  m_tiXmlPointer = newPointer;
176  SetImpRC(newPointer);
177 }
178 
179 //*****************************************************************************
180 
182  bool throwIfNull,
183  bool rememberSpawnedWrapper) const {
184  if (0 == tiXmlNode) {
185  if (throwIfNull) {
186  TICPPTHROW("tiXmlNode is nullptr")
187  } else {
188  return 0;
189  }
190  }
191 
192  Node* temp;
193 
194  switch (tiXmlNode->Type()) {
195  case TiXmlNode::DOCUMENT:
196  temp = new Document(tiXmlNode->ToDocument());
197  break;
198 
199  case TiXmlNode::ELEMENT:
200  temp = new Element(tiXmlNode->ToElement());
201  break;
202 
203  case TiXmlNode::COMMENT:
204  temp = new Comment(tiXmlNode->ToComment());
205  break;
206 
207  case TiXmlNode::TEXT:
208  temp = new Text(tiXmlNode->ToText());
209  break;
210 
211  case TiXmlNode::DECLARATION:
212  temp = new Declaration(tiXmlNode->ToDeclaration());
213  break;
214 
215  case TiXmlNode::STYLESHEETREFERENCE:
216  temp = new StylesheetReference(tiXmlNode->ToStylesheetReference());
217  break;
218 
219  default:
220  TICPPTHROW("Type is unsupported")
221  }
222 
223  if (rememberSpawnedWrapper) {
224  tiXmlNode->m_spawnedWrappers.push_back(temp);
225  }
226 
227  return temp;
228 }
229 
231 
233 
234 Node* Node::Parent(bool throwIfNoParent) const {
236 
237  if ((0 == parent) && throwIfNoParent) {
238  TICPPTHROW("No parent exists");
239  }
240 
241  return NodeFactory(parent, false);
242 }
243 
244 Node* Node::FirstChild(bool throwIfNoChildren) const {
245  return FirstChild("", throwIfNoChildren);
246 }
247 
248 Node* Node::FirstChild(const std::string& value, bool throwIfNoChildren) const {
249  return FirstChild(value.c_str(), throwIfNoChildren);
250 }
251 
252 Node* Node::FirstChild(const char* value, bool throwIfNoChildren) const {
253  TiXmlNode* childNode;
254 
255  if (0 == strlen(value)) {
257  } else {
258  childNode = GetTiXmlPointer()->FirstChild(value);
259  }
260 
261  if ((0 == childNode) && throwIfNoChildren) {
262  TICPPTHROW("Child with the value of \"" << value << "\" not found");
263  }
264 
265  return NodeFactory(childNode, false);
266 }
267 
268 Node* Node::LastChild(bool throwIfNoChildren) const {
269  return LastChild("", throwIfNoChildren);
270 }
271 
272 Node* Node::LastChild(const std::string& value, bool throwIfNoChildren) const {
273  return LastChild(value.c_str(), throwIfNoChildren);
274 }
275 
276 Node* Node::LastChild(const char* value, bool throwIfNoChildren) const {
277  TiXmlNode* childNode;
278 
279  if (0 == strlen(value)) {
280  childNode = GetTiXmlPointer()->LastChild();
281  } else {
282  childNode = GetTiXmlPointer()->LastChild(value);
283  }
284 
285  if ((0 == childNode) && throwIfNoChildren) {
286  TICPPTHROW("Child with the value of \"" << value << "\" not found");
287  }
288 
289  return NodeFactory(childNode, false);
290 }
291 
292 Node* Node::IterateChildren(Node* previous) const {
293  TiXmlNode* pointer;
294 
295  if (0 == previous) {
297  } else {
299  }
300 
301  return NodeFactory(pointer, false);
302 }
303 
304 Node* Node::IterateChildren(const std::string& value, Node* previous) const {
305  TiXmlNode* pointer;
306 
307  if (0 == previous) {
308  pointer = GetTiXmlPointer()->IterateChildren(value, 0);
309  } else {
310  pointer =
311  GetTiXmlPointer()->IterateChildren(value, previous->GetTiXmlPointer());
312  }
313 
314  return NodeFactory(pointer, false);
315 }
316 
318  if (addThis.Type() == TiXmlNode::DOCUMENT) {
319  TICPPTHROW("Node is a Document and can't be inserted");
320  }
321 
322  TiXmlNode* pointer =
324 
325  if (0 == pointer) {
326  TICPPTHROW("Node can't be inserted");
327  }
328 
329  return NodeFactory(pointer);
330 }
331 
332 Node* Node::LinkEndChild(Node* childNode) {
333  if (childNode->Type() == TiXmlNode::DOCUMENT) {
334  TICPPTHROW("Node is a Document and can't be linked");
335  }
336 
337  // Increment reference count when adding to the tree
338  childNode->m_impRC->IncRef();
339 
341  TICPPTHROW("Node can't be linked");
342  }
343 
344  return childNode;
345 }
346 
347 Node* Node::InsertBeforeChild(Node* beforeThis, Node& addThis) {
348  if (addThis.Type() == TiXmlNode::DOCUMENT) {
349  TICPPTHROW("Node is a Document and can't be inserted");
350  }
351 
352  // Increment reference count when adding to the tree
353  addThis.m_impRC->IncRef();
354 
356  beforeThis->GetTiXmlPointer(), *addThis.GetTiXmlPointer());
357 
358  if (0 == pointer) {
359  TICPPTHROW("Node can't be inserted");
360  }
361 
362  return NodeFactory(pointer);
363 }
364 
365 Node* Node::InsertAfterChild(Node* afterThis, Node& addThis) {
366  if (addThis.Type() == TiXmlNode::DOCUMENT) {
367  TICPPTHROW("Node is a Document and can't be inserted");
368  }
369 
370  // Increment reference count when adding to the tree
371  addThis.m_impRC->IncRef();
372 
374  afterThis->GetTiXmlPointer(), *addThis.GetTiXmlPointer());
375 
376  if (0 == pointer) {
377  TICPPTHROW("Node can't be inserted");
378  }
379 
380  return NodeFactory(pointer);
381 }
382 
383 Node* Node::ReplaceChild(Node* replaceThis, Node& withThis) {
384  if (withThis.Type() == TiXmlNode::DOCUMENT) {
385  TICPPTHROW("Node is a Document and can't be inserted");
386  }
387 
388  // Increment reference count when adding to the tree
389  withThis.m_impRC->IncRef();
390 
392  replaceThis->GetTiXmlPointer(), *withThis.GetTiXmlPointer());
393 
394  if (0 == pointer) {
395  TICPPTHROW("Node can't be inserted");
396  }
397 
398  return NodeFactory(pointer);
399 }
400 
401 void Node::RemoveChild(Node* removeThis) {
403  TICPPTHROW("Node to remove (" << removeThis->Value()
404  << ") is not a child of this Node ("
405  << Value()
406  << ")")
407  }
408 }
409 
410 Node* Node::PreviousSibling(bool throwIfNoSiblings) const {
411  return PreviousSibling("", throwIfNoSiblings);
412 }
413 
414 Node* Node::PreviousSibling(const std::string& value,
415  bool throwIfNoSiblings) const {
416  return PreviousSibling(value.c_str(), throwIfNoSiblings);
417 }
418 
419 Node* Node::PreviousSibling(const char* value, bool throwIfNoSiblings) const {
420  TiXmlNode* sibling;
421 
422  if (0 == strlen(value)) {
424  } else {
426  }
427 
428  if ((0 == sibling) && throwIfNoSiblings) {
429  TICPPTHROW("No Siblings found with value, '" << value
430  << "', Prior to this Node ("
431  << Value()
432  << ")")
433  }
434 
435  return NodeFactory(sibling, false);
436 }
437 
438 Node* Node::NextSibling(bool throwIfNoSiblings) const {
439  return NextSibling("", throwIfNoSiblings);
440 }
441 
442 Node* Node::NextSibling(const std::string& value, bool throwIfNoSiblings) const {
443  return NextSibling(value.c_str(), throwIfNoSiblings);
444 }
445 
446 Node* Node::NextSibling(const char* value, bool throwIfNoSiblings) const {
447  TiXmlNode* sibling;
448 
449  if (0 == strlen(value)) {
451  } else {
452  sibling = GetTiXmlPointer()->NextSibling(value);
453  }
454 
455  if ((0 == sibling) && throwIfNoSiblings) {
456  TICPPTHROW("No Siblings found with value, '" << value << "', After this Node ("
457  << Value()
458  << ")")
459  }
460 
461  return NodeFactory(sibling, false);
462 }
463 
464 Element* Node::NextSiblingElement(bool throwIfNoSiblings) const {
465  return NextSiblingElement("", throwIfNoSiblings);
466 }
467 
468 Element* Node::NextSiblingElement(const std::string& value,
469  bool throwIfNoSiblings) const {
470  return NextSiblingElement(value.c_str(), throwIfNoSiblings);
471 }
472 
473 Element* Node::NextSiblingElement(const char* value,
474  bool throwIfNoSiblings) const {
475  TiXmlElement* sibling;
476 
477  if (0 == strlen(value)) {
479  } else {
481  }
482 
483  if (0 == sibling) {
484  if (throwIfNoSiblings) {
485  TICPPTHROW("No Element Siblings found with value, '"
486  << value
487  << "', After this Node ("
488  << Value()
489  << ")")
490  } else {
491  return 0;
492  }
493  }
494 
495  Element* temp = new Element(sibling);
496  sibling->m_spawnedWrappers.push_back(temp);
497 
498  return temp;
499 }
500 
501 Element* Node::FirstChildElement(bool throwIfNoChildren) const {
502  return FirstChildElement("", throwIfNoChildren);
503 }
504 
505 Element* Node::FirstChildElement(const std::string& value,
506  bool throwIfNoChildren) const {
507  return FirstChildElement(value.c_str(), throwIfNoChildren);
508 }
509 
510 Element* Node::FirstChildElement(const char* value, bool throwIfNoChildren) const {
511  TiXmlElement* element;
512 
513  if (0 == strlen(value)) {
515  } else {
517  }
518 
519  if (0 == element) {
520  if (throwIfNoChildren) {
521  TICPPTHROW("Element (" << Value()
522  << ") does NOT contain a child with the value of '"
523  << value
524  << "'")
525  } else {
526  return 0;
527  }
528  }
529 
530  Element* temp = new Element(element);
531  element->m_spawnedWrappers.push_back(temp);
532 
533  return temp;
534 }
535 
536 int Node::Type() const { return GetTiXmlPointer()->Type(); }
537 
538 Document* Node::GetDocument(bool throwIfNoDocument) const {
539  TiXmlDocument* doc = GetTiXmlPointer()->GetDocument();
540 
541  if (0 == doc) {
542  if (throwIfNoDocument) {
543  TICPPTHROW("This node (" << Value() << ") is not linked under a document")
544  } else {
545  return 0;
546  }
547  }
548 
549  Document* temp = new Document(doc);
550  doc->m_spawnedWrappers.push_back(temp);
551 
552  return temp;
553 }
554 
556 
558  TiXmlDocument* doc = GetTiXmlPointer()->ToDocument();
559 
560  if (0 == doc) {
561  TICPPTHROW("This node (" << Value() << ") is not a Document")
562  }
563 
564  Document* temp = new Document(doc);
565  doc->m_spawnedWrappers.push_back(temp);
566 
567  return temp;
568 }
569 
570 Element* Node::ToElement() const {
572 
573  if (0 == doc) {
574  TICPPTHROW("This node (" << Value() << ") is not a Element")
575  }
576 
577  Element* temp = new Element(doc);
578  doc->m_spawnedWrappers.push_back(temp);
579 
580  return temp;
581 }
582 
583 Comment* Node::ToComment() const {
585 
586  if (0 == doc) {
587  TICPPTHROW("This node (" << Value() << ") is not a Comment")
588  }
589 
590  Comment* temp = new Comment(doc);
591  doc->m_spawnedWrappers.push_back(temp);
592 
593  return temp;
594 }
595 
596 Text* Node::ToText() const {
598 
599  if (0 == doc) {
600  TICPPTHROW("This node (" << Value() << ") is not a Text")
601  }
602 
603  Text* temp = new Text(doc);
604  doc->m_spawnedWrappers.push_back(temp);
605 
606  return temp;
607 }
608 
611 
612  if (0 == doc) {
613  TICPPTHROW("This node (" << Value() << ") is not a Declaration")
614  }
615 
616  Declaration* temp = new Declaration(doc);
617  doc->m_spawnedWrappers.push_back(temp);
618 
619  return temp;
620 }
621 
624 
625  if (0 == doc) {
626  TICPPTHROW("This node (" << Value() << ") is not a StylesheetReference")
627  }
628 
630  doc->m_spawnedWrappers.push_back(temp);
631 
632  return temp;
633 }
634 
635 std::unique_ptr< Node > Node::Clone() const {
637 
638  if (0 == node) {
639  TICPPTHROW("Node could not be cloned");
640  }
641 
642  std::unique_ptr< Node > temp(NodeFactory(node, false, false));
643 
644  // Take ownership of the memory from TiXml
645  temp->m_impRC->InitRef();
646 
647  return temp;
648 }
649 
650 bool Node::Accept(TiXmlVisitor* visitor) const {
651  return GetTiXmlPointer()->Accept(visitor);
652 }
653 
654 //*****************************************************************************
655 
657  : NodeImp< TiXmlComment >(new TiXmlComment()) {
658  m_impRC->InitRef();
659 }
660 
662  : NodeImp< TiXmlComment >(comment) {}
663 
664 Comment::Comment(const std::string& comment)
665  : NodeImp< TiXmlComment >(new TiXmlComment()) {
666  m_impRC->InitRef();
667  m_tiXmlPointer->SetValue(comment);
668 }
669 
670 //*****************************************************************************
671 
673  : NodeImp< TiXmlText >(new TiXmlText("")) {
674  m_impRC->InitRef();
675 }
676 
677 Text::Text(const std::string& value)
678  : NodeImp< TiXmlText >(new TiXmlText(value)) {
679  m_impRC->InitRef();
680 }
681 
683  : NodeImp< TiXmlText >(text) {}
684 
685 //*****************************************************************************
686 
688  : NodeImp< TiXmlDocument >(new TiXmlDocument()) {
689  m_impRC->InitRef();
690 }
691 
694 
695 Document::Document(const char* documentName)
697  m_impRC->InitRef();
698 }
699 
700 Document::Document(const std::string& documentName)
702  m_impRC->InitRef();
703 }
704 
705 void Document::LoadFile(TiXmlEncoding encoding) {
706  if (!m_tiXmlPointer->LoadFile(encoding)) {
707  TICPPTHROW("Couldn't load " << m_tiXmlPointer->Value());
708  }
709 }
710 
711 void Document::SaveFile() const {
712  if (!m_tiXmlPointer->SaveFile()) {
713  TICPPTHROW("Couldn't save " << m_tiXmlPointer->Value());
714  }
715 }
716 
717 void Document::LoadFile(const std::string& filename, TiXmlEncoding encoding) {
718  if (!m_tiXmlPointer->LoadFile(filename.c_str(), encoding)) {
719  TICPPTHROW("Couldn't load " << filename);
720  }
721 }
722 
723 void Document::LoadFile(const char* filename, TiXmlEncoding encoding) {
724  if (!m_tiXmlPointer->LoadFile(filename, encoding)) {
725  TICPPTHROW("Couldn't load " << filename);
726  }
727 }
728 
729 void Document::SaveFile(const std::string& filename) const {
730  if (!m_tiXmlPointer->SaveFile(filename.c_str())) {
731  TICPPTHROW("Couldn't save " << filename);
732  }
733 }
734 
735 void Document::Parse(const std::string& xml,
736  bool throwIfParseError,
737  TiXmlEncoding encoding) {
738  m_tiXmlPointer->Parse(xml.c_str(), 0, encoding);
739 
740  if (throwIfParseError && m_tiXmlPointer->Error()) {
741  TICPPTHROW("Error parsing xml.");
742  }
743 }
744 
745 //*****************************************************************************
746 
749  "DefaultValueCausedByCreatingAnElementWithNoParameters")) {
750  m_impRC->InitRef();
751 }
752 
753 Element::Element(const std::string& value)
755  m_impRC->InitRef();
756 }
757 
758 Element::Element(const char* value)
760  m_impRC->InitRef();
761 }
762 
764  : NodeImp< TiXmlElement >(element) {}
765 
766 Attribute* Element::FirstAttribute(bool throwIfNoAttributes) const {
767  ValidatePointer();
768  TiXmlAttribute* attribute = m_tiXmlPointer->FirstAttribute();
769 
770  if ((0 == attribute) && throwIfNoAttributes) {
771  TICPPTHROW("This Element (" << Value() << ") has no attributes")
772  }
773 
774  if (0 == attribute) {
775  if (throwIfNoAttributes) {
776  TICPPTHROW("Element (" << Value() << ") has no attributes")
777  } else {
778  return 0;
779  }
780  }
781 
782  Attribute* temp = new Attribute(attribute);
783  attribute->m_spawnedWrappers.push_back(temp);
784 
785  return temp;
786 }
787 
788 Attribute* Element::LastAttribute(bool throwIfNoAttributes) const {
789  ValidatePointer();
790  TiXmlAttribute* attribute = m_tiXmlPointer->LastAttribute();
791 
792  if ((0 == attribute) && throwIfNoAttributes) {
793  TICPPTHROW("This Element (" << Value() << ") has no attributes")
794  }
795 
796  if (0 == attribute) {
797  if (throwIfNoAttributes) {
798  TICPPTHROW("Element (" << Value() << ") has no attributes")
799  } else {
800  return 0;
801  }
802  }
803 
804  Attribute* temp = new Attribute(attribute);
805  attribute->m_spawnedWrappers.push_back(temp);
806 
807  return temp;
808 }
809 
811  const std::string& defaultValue) const {
812  std::string value;
813 
814  if (!GetAttributeImp(name, &value)) {
815  return defaultValue;
816  }
817 
818  return value;
819 }
820 
822  return GetAttributeOrDefault(name, std::string());
823 }
824 
825 bool Element::HasAttribute(const std::string& name) const {
826  ValidatePointer();
827  return (0 != m_tiXmlPointer->Attribute(name.c_str()));
828 }
829 
830 void Element::RemoveAttribute(const std::string& name) {
831  ValidatePointer();
832  m_tiXmlPointer->RemoveAttribute(name.c_str());
833 }
834 
835 bool Element::GetAttributeImp(const std::string& name, std::string* value) const {
836  ValidatePointer();
837 
838  // Get value from TinyXML, if the attribute exists
839  const char* retVal = m_tiXmlPointer->Attribute(name.c_str());
840 
841  // TinyXML returns nullptr if the attribute doesn't exist
842  if (0 == retVal) {
843  return false;
844  } else {
845  *value = retVal;
846  return true;
847  }
848 }
849 
850 bool Element::GetTextImp(std::string* value) const {
851  ValidatePointer();
852 
853  // Get value from TinyXML, if the attribute exists
854  const char* retVal = m_tiXmlPointer->GetText();
855 
856  // TinyXML returns nullptr if the attribute doesn't exist
857  if (0 == retVal) {
858  return false;
859  } else {
860  *value = retVal;
861  return true;
862  }
863 }
864 
865 //*****************************************************************************
866 
869  m_impRC->InitRef();
870 }
871 
874 
875 Declaration::Declaration(const std::string& version,
876  const std::string& encoding,
877  const std::string& standalone)
880  m_impRC->InitRef();
881 }
882 
883 std::string Declaration::Version() const { return m_tiXmlPointer->Version(); }
884 
885 std::string Declaration::Encoding() const { return m_tiXmlPointer->Encoding(); }
886 
888  return m_tiXmlPointer->Standalone();
889 }
890 
891 //*****************************************************************************
892 
895  m_impRC->InitRef();
896 }
897 
899  TiXmlStylesheetReference* stylesheetReference)
901 
902 StylesheetReference::StylesheetReference(const std::string& type,
903  const std::string& href)
906  m_impRC->InitRef();
907 }
908 
909 std::string StylesheetReference::Type() const { return m_tiXmlPointer->Type(); }
910 
911 std::string StylesheetReference::Href() const { return m_tiXmlPointer->Href(); }
912 
913 //*****************************************************************************
914 
915 Exception::Exception(const std::string& details)
916  : m_details(details) {}
917 
918 Exception::~Exception() throw() {}
919 
920 const char* Exception::what() const throw() { return m_details.c_str(); }
921 
922 //*****************************************************************************
923 
924 TiCppRC::TiCppRC() {
925  // Spawn reference counter for this object
926  m_tiRC = new TiCppRCImp(this);
927 }
928 
929 void TiCppRC::DeleteSpawnedWrappers() {
930  std::vector< Base* >::reverse_iterator wrapper;
931 
932  for (wrapper = m_spawnedWrappers.rbegin(); wrapper != m_spawnedWrappers.rend();
933  ++wrapper) {
934  delete *wrapper;
935  }
936 
937  m_spawnedWrappers.clear();
938 }
939 
940 TiCppRC::~TiCppRC() {
941  DeleteSpawnedWrappers();
942 
943  // Set pointer held by reference counter to nullptr
944  this->m_tiRC->Nullify();
945 
946  // Decrement reference - so reference counter will delete itself if necessary
947  this->m_tiRC->DecRef();
948 }
949 
950 //*****************************************************************************
951 
952 TiCppRCImp::TiCppRCImp(TiCppRC* tiCppRC)
953  : m_count(1)
954  , m_tiCppRC(tiCppRC) {}
955 
956 void TiCppRCImp::IncRef() { m_count++; }
957 
958 void TiCppRCImp::DecRef() {
959  m_count--;
960 
961  if (0 == m_count) {
962  delete m_tiCppRC;
963  delete this;
964  }
965 }
966 
967 void TiCppRCImp::InitRef() { m_count = 1; }
968 
969 void TiCppRCImp::Nullify() { m_tiCppRC = 0; }
970 
971 TiCppRC* TiCppRCImp::Get() { return m_tiCppRC; }
972 
973 bool TiCppRCImp::IsNull() { return 0 == m_tiCppRC; }
974 
975 #endif // TIXML_USE_TICPP
Wrapper around TiXmlNode.
Definition: ticpp.h:460
std::unique_ptr< Node > Clone() const
Create an exact duplicate of this node and return it.
Definition: ticpp.cpp:635
void RemoveChild(Node *removeThis)
Delete a child of this node.
Definition: ticpp.cpp:401
TiXmlNode * FirstChild(const char *_value)
Definition: tinyxml.h:564
TiXmlNode * LastChild(const char *_value)
The last child of this node matching &#39;value&#39;. Will be null if there are no children.
Definition: tinyxml.h:581
Document(TiXmlDocument *document)
Constructor.
Definition: ticpp.cpp:692
An attribute is a name-value pair.
Definition: tinyxml.h:915
void operator=(const Attribute &copy)
Definition: ticpp.cpp:90
Node * FirstChild(const char *value, bool throwIfNoChildren=true) const
Definition: ticpp.cpp:252
If you call the Accept() method, it requires being passed a TiXmlVisitor class to handle callbacks...
Definition: tinyxml.h:144
Node * PreviousSibling(const char *value, bool throwIfNoSiblings=true) const
Definition: ticpp.cpp:419
Wrapper around TiXmlComment.
Definition: ticpp.h:1349
Node * PreviousSibling(bool throwIfNoSiblings=true) const
Navigate to a sibling node.
Definition: ticpp.cpp:410
void Clear()
Clear all Nodes below this.
Definition: ticpp.cpp:232
TiXmlElement * NextSiblingElement()
Definition: tinyxml.h:719
Comment(TiXmlComment *comment)
Constructor.
Definition: ticpp.cpp:661
Wrapper around TiXmlElement.
Definition: ticpp.h:1493
void IteratePrevious(const std::string &, Attribute **previous) const
Definition: ticpp.cpp:165
TiXmlNode * PreviousSibling(const char *_prev)
Definition: tinyxml.h:683
TiXmlNode * LastChild()
The last child of this node. Will be null if there are no children.
Definition: tinyxml.h:575
virtual TiXmlElement * ToElement()
Cast to a more defined type. Will return null if not of the requested type.
Definition: tinyxml.h:817
virtual bool Visit(const TiXmlUnknown &)
Visit an unknow node.
Definition: tinyxml.h:172
Comment * ToComment() const
Pointer conversion - replaces TiXmlNode::ToComment.
Definition: ticpp.cpp:583
Document * ToDocument() const
Pointer conversion - replaces TiXmlNode::ToDocument.
Definition: ticpp.cpp:557
Text(const std::string &value)
Constructor.
Definition: ticpp.cpp:677
StylesheetReference(const std::string &type, const std::string &href)
Constructor.
Definition: ticpp.cpp:902
virtual bool Visit(const TiXmlDeclaration &declaration)
Visit a declaration.
Definition: ticpp.cpp:56
#define TICPPTHROW(message)
This allows you to stream your exceptions in.
Definition: ticpp.h:92
virtual bool Visit(const TiXmlText &text)
Visit a text node.
Definition: ticpp.cpp:65
virtual bool Visit(const Text &)
Visit a text node.
Definition: ticpp.h:155
StylesheetReference()
Default Constructor.
Definition: ticpp.cpp:893
bool Accept(TiXmlVisitor *visitor) const
Accept a hierchical visit the nodes in the TinyXML DOM.
Definition: ticpp.cpp:650
Declaration(const std::string &version, const std::string &encoding, const std::string &standalone)
Constructor.
Definition: ticpp.cpp:875
Node * NextSibling(const std::string &value, bool throwIfNoSiblings=true) const
Navigate to a sibling node with the given value.
Definition: ticpp.cpp:442
bool NoChildren() const
Check if this node has no children.
Definition: ticpp.cpp:555
Attribute * Previous(bool throwIfNoAttribute=true) const
Get the previous sibling attribute in the DOM.
Definition: ticpp.cpp:143
virtual bool Visit(const Declaration &)
Visit a declaration.
Definition: ticpp.h:151
void ValidatePointer() const
Definition: ticpp.h:281
TiXmlElement * FirstChildElement(const char *_value)
Definition: tinyxml.h:752
TiXmlAttribute * Next()
Definition: tinyxml.h:993
void SetTiXmlPointer(TiXmlAttribute *newPointer)
Definition: ticpp.cpp:174
TiXmlNode * ReplaceChild(TiXmlNode *replaceThis, const TiXmlNode &withThis)
Replace a child of this node.
Definition: tinyxml.cpp:265
const std::string & ValueStr() const
Return Value() as a std::string.
Definition: tinyxml.h:524
TiXmlNode * NextSibling()
Definition: tinyxml.h:705
void SaveFile(const std::string &filename) const
Save a file using the given filename.
Definition: ticpp.cpp:729
TiXmlAttribute()
Construct an empty attribute.
Definition: tinyxml.h:920
Declaration()
Default Constructor.
Definition: ticpp.cpp:867
Document()
Default Constructor.
Definition: ticpp.cpp:687
TiXmlElement * NextSiblingElement(const char *_next)
Definition: tinyxml.h:729
bool GetTextImp(std::string *value) const
Definition: ticpp.cpp:850
TiXmlElement * FirstChildElement()
Definition: tinyxml.h:745
Node * LastChild(bool throwIfNoChildren=true) const
The last child of this node.
Definition: ticpp.cpp:268
std::string GetAttribute(const std::string &name) const
Gets an attribute of name from an element.
Definition: ticpp.cpp:821
virtual void Print(FILE *cfile, int depth) const
All TinyXml classes can print themselves to a filestream or the string class (TiXmlString in non-STL ...
Definition: tinyxml.h:1016
Attribute(const std::string &name, const std::string &value)
Construct an attribute with name and value.
Definition: ticpp.cpp:85
TiXmlNode * InsertEndChild(const TiXmlNode &addThis)
Add a new node related to this.
Definition: tinyxml.cpp:181
TiXmlNode * InsertBeforeChild(TiXmlNode *beforeThis, const TiXmlNode &addThis)
Add a new node related to this.
Definition: tinyxml.cpp:197
void LoadFile(TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
Load a file using the current document value.
Definition: ticpp.cpp:705
Wrapper around TiXmlText.
Definition: ticpp.h:1368
const std::string & ValueStr() const
Return the value of this attribute.
Definition: tinyxml.h:951
StylesheetReference * ToStylesheetReference() const
Pointer conversion - replaces TiXmlNode::ToStylesheetReference.
Definition: ticpp.cpp:622
TiXmlNode * PreviousSibling()
Definition: tinyxml.h:679
Element(const std::string &value)
Default Constructor.
Definition: ticpp.cpp:753
std::string Standalone() const
StandAlone.
Definition: ticpp.cpp:887
Node * FirstChild(const std::string &value, bool throwIfNoChildren=true) const
The first child of this node with the matching value.
Definition: ticpp.cpp:248
virtual TiXmlStylesheetReference * ToStylesheetReference()
Cast to a more defined type. Will return null if not of the requested type.
Definition: tinyxml.h:837
void LoadFile(const std::string &filename, TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
Load a file using the given filename.
Definition: ticpp.cpp:717
TiXmlNode * LinkEndChild(TiXmlNode *addThis)
Add a new node related to this.
Definition: tinyxml.cpp:153
void SaveFile() const
Save a file using the current document value.
Definition: ticpp.cpp:711
Document(const std::string &documentName)
Constructor.
Definition: ticpp.cpp:700
Text(TiXmlText *text)
Constructor.
Definition: ticpp.cpp:682
virtual TiXmlNode * GetTiXmlPointer() const =0
A stylesheet reference looks like this:
Definition: tinyxml.h:1543
Element * FirstChildElement(const std::string &value, bool throwIfNoChildren=true) const
The first child element of this node with the matching value.
Definition: ticpp.cpp:505
virtual bool Accept(TiXmlVisitor *visitor) const =0
Accept a hierchical visit the nodes in the TinyXML DOM.
In correct XML the declaration is the first entry in the file.
Definition: tinyxml.h:1469
Element * ToElement() const
Pointer conversion - replaces TiXmlNode::ToElement.
Definition: ticpp.cpp:570
std::string Value() const
Get the value of this node.
Definition: ticpp.cpp:230
std::string Href() const
Href.
Definition: ticpp.cpp:911
void Parse(const std::string &xml, bool throwIfParseError=true, TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
Parse the given xml data.
Definition: ticpp.cpp:735
Element()
Default Constructor.
Definition: ticpp.cpp:747
Any tag that tinyXml doesn&#39;t recognize is saved as an unknown.
Definition: tinyxml.h:1608
void IterateNext(const std::string &, Attribute **next) const
Definition: ticpp.cpp:161
TiXmlNode * NextSibling(const char *_next)
Definition: tinyxml.h:709
TiXmlNode * FirstChild()
Definition: tinyxml.h:555
virtual bool VisitEnter(const Element &, const Attribute *)
Visit an element.
Definition: ticpp.h:143
int Type() const
Query the type (as TiXmlNode::NodeType ) of this node.
Definition: ticpp.cpp:536
virtual bool VisitExit(const Element &)
Visit an element.
Definition: ticpp.h:148
Node * ReplaceChild(Node *replaceThis, Node &withThis)
Replace a child of this node.
Definition: ticpp.cpp:383
bool GetAttributeImp(const std::string &name, std::string *value) const
Definition: ticpp.cpp:835
const char * what() const
Override std::exception::what() to return m_details.
Definition: ticpp.cpp:920
void RemoveAttribute(const std::string &name)
Removes attribute from element.
Definition: ticpp.cpp:830
void IncRef()
Increment Reference Count.
Definition: ticpp.cpp:956
Node * IterateChildren(Node *previous) const
An alternate way to walk the children of a node.
Definition: ticpp.cpp:292
This is a ticpp exception class.
Definition: ticpp.h:74
Attribute * FirstAttribute(bool throwIfNoAttributes=true) const
Access the first attribute in this element.
Definition: ticpp.cpp:766
#define TIXML_USE_TICPP
Definition: ticpp.cpp:22
Wrapper around TiXmlDeclaration.
Definition: ticpp.h:1886
friend class TiXmlElement
Definition: tinyxml.h:1387
Wrapper around TiXmlBase.
Definition: ticpp.h:161
Text()
Constructor.
Definition: ticpp.cpp:672
Always the top level node.
Definition: tinyxml.h:1655
TiXmlEncoding
Definition: tinyxml.h:179
Node * IterateChildren(const std::string &value, Node *previous) const
This flavor of IterateChildren searches for children with a particular value.
Definition: ticpp.cpp:304
virtual bool Visit(const Comment &)
Visit a comment node.
Definition: ticpp.h:157
std::string Type() const
Type.
Definition: ticpp.cpp:909
TiXmlNode * InsertAfterChild(TiXmlNode *afterThis, const TiXmlNode &addThis)
Add a new node related to this.
Definition: tinyxml.cpp:231
Node * NextSibling(const char *value, bool throwIfNoSiblings=true) const
Definition: ticpp.cpp:446
virtual TiXmlDeclaration * ToDeclaration()
Cast to a more defined type. Will return null if not of the requested type.
Definition: tinyxml.h:833
Node * LastChild(const std::string &value, bool throwIfNoChildren=true) const
The last child of this node with the matching value.
Definition: ticpp.cpp:272
std::string GetAttributeOrDefault(const std::string &name, const std::string &defaultValue) const
Gets an attribute of name from an element, if it doesn&#39;t exist it will return the defaultValue...
Definition: ticpp.cpp:810
virtual TiXmlComment * ToComment()
Cast to a more defined type. Will return null if not of the requested type.
Definition: tinyxml.h:821
std::string Name() const
Get the value of this attribute.
Definition: ticpp.cpp:120
StylesheetReference(TiXmlStylesheetReference *stylesheetReference)
Constructor.
Definition: ticpp.cpp:898
Node * Parent(bool throwIfNoParent=true) const
The Parent of this Node.
Definition: ticpp.cpp:234
virtual bool VisitExit(const TiXmlDocument &doc)
Visit a document.
Definition: ticpp.cpp:38
std::string Encoding() const
Encoding.
Definition: ticpp.cpp:885
TiXmlNode * Parent()
One step up the DOM.
Definition: tinyxml.h:549
int Type() const
Query the type (as an enumerated value, above) of this node.
Definition: tinyxml.h:770
Element(TiXmlElement *element)
Constructor.
Definition: ticpp.cpp:763
TiXmlAttribute * m_tiXmlPointer
Definition: ticpp.h:299
Element * NextSiblingElement(bool throwIfNoSiblings=true) const
Navigate to a sibling element.
Definition: ticpp.cpp:464
Wrapper around TiXmlVisitor.
Definition: ticpp.h:112
Definition: ticpp.h:70
Element * FirstChildElement(const char *value, bool throwIfNoChildren=true) const
Definition: ticpp.cpp:510
TiXmlNode * IterateChildren(const TiXmlNode *previous)
Definition: tinyxml.h:618
TiXmlAttribute * Previous()
Definition: tinyxml.h:1000
The parent class for everything in the Document Object Model.
Definition: tinyxml.h:454
Comment(const std::string &comment)
Constructor.
Definition: ticpp.cpp:664
Node * PreviousSibling(const std::string &value, bool throwIfNoSiblings=true) const
Navigate to a sibling node with the given value.
Definition: ticpp.cpp:414
bool NoChildren() const
Returns true if this node has no children.
Definition: tinyxml.h:782
std::string Version() const
Version.
Definition: ticpp.cpp:883
void InitRef()
Set Reference Count to 1 - dangerous! - Use only if you are sure of the consequences.
Definition: ticpp.cpp:967
virtual bool Visit(const TiXmlComment &comment)
Visit a comment node.
Definition: ticpp.cpp:69
Node * NextSibling(bool throwIfNoSiblings=true) const
Navigate to a sibling node.
Definition: ticpp.cpp:438
Node * InsertEndChild(Node &addThis)
Adds a child past the LastChild.
Definition: ticpp.cpp:317
void LoadFile(const char *filename, TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
Load a file using the given filename.
Definition: ticpp.cpp:723
virtual bool Visit(const TiXmlStylesheetReference &stylesheet)
Visit a stylesheet reference.
Definition: ticpp.cpp:60
virtual void Print(FILE *file, int depth) const
All TinyXml classes can print themselves to a filestream.
Definition: ticpp.cpp:169
Text * ToText() const
Pointer conversion - replaces TiXmlNode::ToText.
Definition: ticpp.cpp:596
Node * InsertAfterChild(Node *afterThis, Node &addThis)
Adds a child after the specified child.
Definition: ticpp.cpp:365
Document(const char *documentName)
Constructor.
Definition: ticpp.cpp:695
Wrapper around TiXmlDocument.
Definition: ticpp.h:1404
std::string Value() const
Get the value of this attribute.
Definition: ticpp.cpp:115
Attribute * Next(bool throwIfNoAttribute=true) const
Get the next sibling attribute in the DOM.
Definition: ticpp.cpp:125
TiCppRCImp * m_impRC
Holds status of internal TiXmlPointer - use this to determine if object has been deleted already...
Definition: ticpp.h:267
Node * LastChild(const char *value, bool throwIfNoChildren=true) const
Definition: ticpp.cpp:276
bool RemoveChild(TiXmlNode *removeThis)
Delete a child of this node.
Definition: tinyxml.cpp:291
virtual bool VisitExit(const TiXmlElement &element)
Visit an element.
Definition: ticpp.cpp:52
Attribute()
Construct an empty attribute.
Definition: ticpp.cpp:75
Node * LinkEndChild(Node *childNode)
Adds a child past the LastChild.
Definition: ticpp.cpp:332
An XML comment.
Definition: tinyxml.h:1330
virtual bool VisitEnter(const TiXmlDocument &doc)
Visit a document.
Definition: ticpp.cpp:34
Element * FirstChildElement(bool throwIfNoChildren=true) const
The first child element of this node.
Definition: ticpp.cpp:501
void Clear()
Delete all the children of this node. Does not affect &#39;this&#39;.
Definition: tinyxml.cpp:139
void DecRef()
Decrement Reference Count.
Definition: ticpp.cpp:958
Node * FirstChild(bool throwIfNoChildren=true) const
The first child of this node.
Definition: ticpp.cpp:244
Wrapper around TiXmlStylesheetReference.
Definition: ticpp.h:1922
Attribute(const Attribute &copy)
Definition: ticpp.cpp:101
Element(const char *value)
Default Constructor.
Definition: ticpp.cpp:758
Node * InsertBeforeChild(Node *beforeThis, Node &addThis)
Adds a child before the specified child.
Definition: ticpp.cpp:347
Attribute * LastAttribute(bool throwIfNoAttributes=true) const
Access the last attribute in this element.
Definition: ticpp.cpp:788
Exception(const std::string &details)
Construct an exception with a message.
Definition: ticpp.cpp:915
virtual bool Visit(const TiXmlUnknown &)
Visit an unknow node.
Definition: ticpp.cpp:73
Comment()
Constructor.
Definition: ticpp.cpp:656
virtual bool VisitEnter(const Document &)
Visit a document.
Definition: ticpp.h:138
virtual TiXmlNode * Clone() const =0
Create an exact duplicate of this node and return it.
Attribute(TiXmlAttribute *attribute)
Definition: ticpp.cpp:80
Element * NextSiblingElement(const std::string &value, bool throwIfNoSiblings=true) const
Navigate to a sibling element with the given value.
Definition: ticpp.cpp:468
Declaration(TiXmlDeclaration *declaration)
Constructor.
Definition: ticpp.cpp:872
Node * NodeFactory(TiXmlNode *tiXmlNode, bool throwIfNull=true, bool rememberSpawnedWrapper=true) const
Definition: ticpp.cpp:181
Element * NextSiblingElement(const char *value, bool throwIfNoSiblings=true) const
Definition: ticpp.cpp:473
Declaration * ToDeclaration() const
Pointer conversion - replaces TiXmlNode::ToDeclaration.
Definition: ticpp.cpp:609
virtual TiXmlText * ToText()
Cast to a more defined type. Will return null if not of the requested type.
Definition: tinyxml.h:829
Wrapper around TiXmlAttribute.
Definition: ticpp.h:297
virtual bool VisitEnter(const TiXmlElement &element, const TiXmlAttribute *firstAttribute)
Visit an element.
Definition: ticpp.cpp:42
Document * GetDocument(bool throwIfNoDocument=true) const
Return a pointer to the Document this node lives in.
Definition: ticpp.cpp:538
The element is a container class.
Definition: tinyxml.h:1095
bool HasAttribute(const std::string &name) const
Returns true, if attribute exists.
Definition: ticpp.cpp:825
virtual bool Visit(const StylesheetReference &)
Visit a stylesheet reference.
Definition: ticpp.h:153