aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
ticpp.cpp
Go to the documentation of this file.
1/*
2http://code.google.com/p/ticpp/
3Copyright (c) 2006 Ryan Pusztai, Ryan Mulder
4
5Permission is hereby granted, free of charge, to any person obtaining a copy of
6this software and associated documentation files (the "Software"), to deal in
7the Software without restriction, including without limitation the rights to
8use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9the Software, and to permit persons to whom the Software is furnished to do so,
10subject to the following conditions:
11
12The above copyright notice and this permission notice shall be included in all
13copies or substantial portions of the Software.
14
15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20CONNECTION 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
30using 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 &
35 return VisitEnter(Document(const_cast< TiXmlDocument* >(&doc)));
36}
37
39 return VisitEnter(Document(const_cast< TiXmlDocument* >(&doc)));
40}
41
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
52bool Visitor::VisitExit(const TiXmlElement& element) {
53 return VisitExit(Element(const_cast< TiXmlElement* >(&element)));
54}
55
56bool Visitor::Visit(const TiXmlDeclaration& declaration) {
57 return Visit(Declaration(const_cast< TiXmlDeclaration* >(&declaration)));
58}
59
61 return Visit(
62 StylesheetReference(const_cast< TiXmlStylesheetReference* >(&stylesheet)));
63}
64
65bool Visitor::Visit(const TiXmlText& text) {
66 return Visit(Text(const_cast< TiXmlText* >(&text)));
67}
68
69bool Visitor::Visit(const TiXmlComment& comment) {
70 return Visit(Comment(const_cast< TiXmlComment* >(&comment)));
71}
72
73bool Visitor::Visit(const TiXmlUnknown& x) { return TiXmlVisitor::Visit(x); }
74
79
81 SetTiXmlPointer(attribute);
82 m_impRC->IncRef();
83}
84
85Attribute::Attribute(const std::string& name, const std::string& value) {
86 SetTiXmlPointer(new TiXmlAttribute(name, value));
87 m_impRC->InitRef();
88}
89
91 // Dropping the reference to the old object
92 this->m_impRC->DecRef();
93
94 // Pointing to the new Object
96
97 // The internal tixml pointer changed in the above line
98 this->m_impRC->IncRef();
99}
100
102 : Base() {
103 // Dropping the reference to the old object
104 if (m_impRC!=nullptr) m_impRC->DecRef();
105
106 // Pointing to the new Object
108
109 // The internal tixml pointer changed in the above line
110 m_impRC->IncRef();
111}
112
114
115std::string Attribute::Value() const {
117 return m_tiXmlPointer->ValueStr();
118}
119
120std::string Attribute::Name() const {
122 return m_tiXmlPointer->Name();
123}
124
125Attribute* Attribute::Next(bool throwIfNoAttribute) const {
127 TiXmlAttribute* attribute = m_tiXmlPointer->Next();
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
143Attribute* Attribute::Previous(bool throwIfNoAttribute) const {
145 TiXmlAttribute* attribute = m_tiXmlPointer->Previous();
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
161void Attribute::IterateNext(const std::string&, Attribute** next) const {
162 *next = Next(false);
163}
164
165void Attribute::IteratePrevious(const std::string&, Attribute** previous) const {
166 *previous = Previous(false);
167}
168
169void 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()) {
196 temp = new Document(tiXmlNode->ToDocument());
197 break;
198
200 temp = new Element(tiXmlNode->ToElement());
201 break;
202
204 temp = new Comment(tiXmlNode->ToComment());
205 break;
206
207 case TiXmlNode::TEXT:
208 temp = new Text(tiXmlNode->ToText());
209 break;
210
212 temp = new Declaration(tiXmlNode->ToDeclaration());
213 break;
214
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
230std::string Node::Value() const { return GetTiXmlPointer()->ValueStr(); }
231
233
234Node* Node::Parent(bool throwIfNoParent) const {
235 TiXmlNode* parent = GetTiXmlPointer()->Parent();
236
237 if ((0 == parent) && throwIfNoParent) {
238 TICPPTHROW("No parent exists");
239 }
240
241 return NodeFactory(parent, false);
242}
243
244Node* Node::FirstChild(bool throwIfNoChildren) const {
245 return FirstChild("", throwIfNoChildren);
246}
247
248Node* Node::FirstChild(const std::string& value, bool throwIfNoChildren) const {
249 return FirstChild(value.c_str(), throwIfNoChildren);
250}
251
252Node* Node::FirstChild(const char* value, bool throwIfNoChildren) const {
253 TiXmlNode* childNode;
254
255 if (0 == strlen(value)) {
256 childNode = GetTiXmlPointer()->FirstChild();
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
268Node* Node::LastChild(bool throwIfNoChildren) const {
269 return LastChild("", throwIfNoChildren);
270}
271
272Node* Node::LastChild(const std::string& value, bool throwIfNoChildren) const {
273 return LastChild(value.c_str(), throwIfNoChildren);
274}
275
276Node* 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
292Node* Node::IterateChildren(Node* previous) const {
293 TiXmlNode* pointer;
294
295 if (0 == previous) {
296 pointer = GetTiXmlPointer()->IterateChildren(0);
297 } else {
298 pointer = GetTiXmlPointer()->IterateChildren(previous->GetTiXmlPointer());
299 }
300
301 return NodeFactory(pointer, false);
302}
303
304Node* 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
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
340 if (0 == GetTiXmlPointer()->LinkEndChild(childNode->GetTiXmlPointer())) {
341 TICPPTHROW("Node can't be linked");
342 }
343
344 return childNode;
345}
346
347Node* 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
365Node* 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
383Node* 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
401void Node::RemoveChild(Node* removeThis) {
402 if (!GetTiXmlPointer()->RemoveChild(removeThis->GetTiXmlPointer())) {
403 TICPPTHROW("Node to remove (" << removeThis->Value()
404 << ") is not a child of this Node ("
405 << Value()
406 << ")")
407 }
408}
409
410Node* Node::PreviousSibling(bool throwIfNoSiblings) const {
411 return PreviousSibling("", throwIfNoSiblings);
412}
413
414Node* Node::PreviousSibling(const std::string& value,
415 bool throwIfNoSiblings) const {
416 return PreviousSibling(value.c_str(), throwIfNoSiblings);
417}
418
419Node* Node::PreviousSibling(const char* value, bool throwIfNoSiblings) const {
420 TiXmlNode* sibling;
421
422 if (0 == strlen(value)) {
423 sibling = GetTiXmlPointer()->PreviousSibling();
424 } else {
425 sibling = GetTiXmlPointer()->PreviousSibling(value);
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
438Node* Node::NextSibling(bool throwIfNoSiblings) const {
439 return NextSibling("", throwIfNoSiblings);
440}
441
442Node* Node::NextSibling(const std::string& value, bool throwIfNoSiblings) const {
443 return NextSibling(value.c_str(), throwIfNoSiblings);
444}
445
446Node* Node::NextSibling(const char* value, bool throwIfNoSiblings) const {
447 TiXmlNode* sibling;
448
449 if (0 == strlen(value)) {
450 sibling = GetTiXmlPointer()->NextSibling();
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
464Element* Node::NextSiblingElement(bool throwIfNoSiblings) const {
465 return NextSiblingElement("", throwIfNoSiblings);
466}
467
468Element* Node::NextSiblingElement(const std::string& value,
469 bool throwIfNoSiblings) const {
470 return NextSiblingElement(value.c_str(), throwIfNoSiblings);
471}
472
474 bool throwIfNoSiblings) const {
475 TiXmlElement* sibling;
476
477 if (0 == strlen(value)) {
478 sibling = GetTiXmlPointer()->NextSiblingElement();
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
501Element* Node::FirstChildElement(bool throwIfNoChildren) const {
502 return FirstChildElement("", throwIfNoChildren);
503}
504
505Element* Node::FirstChildElement(const std::string& value,
506 bool throwIfNoChildren) const {
507 return FirstChildElement(value.c_str(), throwIfNoChildren);
508}
509
510Element* Node::FirstChildElement(const char* value, bool throwIfNoChildren) const {
511 TiXmlElement* element;
512
513 if (0 == strlen(value)) {
514 element = GetTiXmlPointer()->FirstChildElement();
515 } else {
516 element = GetTiXmlPointer()->FirstChildElement(value);
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
536int Node::Type() const { return GetTiXmlPointer()->Type(); }
537
538Document* Node::GetDocument(bool throwIfNoDocument) const {
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
555bool Node::NoChildren() const { return GetTiXmlPointer()->NoChildren(); }
556
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;
569
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}
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}
597 TiXmlText* doc = GetTiXmlPointer()->ToText();
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 }
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
635std::unique_ptr< Node > Node::Clone() const {
636 TiXmlNode* node = GetTiXmlPointer()->Clone();
637
638 if (0 == node) {
639 TICPPTHROW("Node could not be cloned");
640 }
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
650bool 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
664Comment::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
677Text::Text(const std::string& value)
678 : NodeImp< TiXmlText >(new TiXmlText(value)) {
679 m_impRC->InitRef();
680}
681
683 : NodeImp< TiXmlText >(text) {}
684
685//*****************************************************************************
686
689 m_impRC->InitRef();
690}
691
693 : NodeImp< TiXmlDocument >(document) {}
694
695Document::Document(const char* documentName)
696 : NodeImp< TiXmlDocument >(new TiXmlDocument(documentName)) {
697 m_impRC->InitRef();
698}
699
700Document::Document(const std::string& documentName)
701 : NodeImp< TiXmlDocument >(new TiXmlDocument(documentName)) {
702 m_impRC->InitRef();
704
706 if (!m_tiXmlPointer->LoadFile(encoding)) {
707 TICPPTHROW("Couldn't load " << m_tiXmlPointer->Value());
708 }
709}
710
711void Document::SaveFile() const {
712 if (!m_tiXmlPointer->SaveFile()) {
713 TICPPTHROW("Couldn't save " << m_tiXmlPointer->Value());
714 }
715}
717void 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
723void Document::LoadFile(const char* filename, TiXmlEncoding encoding) {
724 if (!m_tiXmlPointer->LoadFile(filename, encoding)) {
725 TICPPTHROW("Couldn't load " << filename);
726 }
727}
728
729void Document::SaveFile(const std::string& filename) const {
730 if (!m_tiXmlPointer->SaveFile(filename.c_str())) {
731 TICPPTHROW("Couldn't save " << filename);
732 }
733}
734
735void 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
753Element::Element(const std::string& value)
754 : NodeImp< TiXmlElement >(new TiXmlElement(value)) {
755 m_impRC->InitRef();
756}
757
758Element::Element(const char* value)
759 : NodeImp< TiXmlElement >(new TiXmlElement(value)) {
760 m_impRC->InitRef();
761}
762
764 : NodeImp< TiXmlElement >(element) {}
765
766Attribute* Element::FirstAttribute(bool throwIfNoAttributes) const {
768 TiXmlAttribute* attribute = m_tiXmlPointer->FirstAttribute();
769
770 if ((0 == attribute) && throwIfNoAttributes) {
771 TICPPTHROW("This Element (" << Value() << ") has no attributes")
772 }
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
788Attribute* Element::LastAttribute(bool throwIfNoAttributes) const {
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
810std::string Element::GetAttributeOrDefault(const std::string& name,
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
821std::string Element::GetAttribute(const std::string& name) const {
822 return GetAttributeOrDefault(name, std::string());
823}
824
825bool Element::HasAttribute(const std::string& name) const {
827 return (0 != m_tiXmlPointer->Attribute(name.c_str()));
828}
829
830void Element::RemoveAttribute(const std::string& name) {
832 m_tiXmlPointer->RemoveAttribute(name.c_str());
833}
834
835bool Element::GetAttributeImp(const std::string& name, std::string* value) const {
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 }
849
850bool Element::GetTextImp(std::string* value) const {
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
871
874
875Declaration::Declaration(const std::string& version,
876 const std::string& encoding,
877 const std::string& standalone)
879 new TiXmlDeclaration(version, encoding, standalone)) {
880 m_impRC->InitRef();
881}
882
883std::string Declaration::Version() const { return m_tiXmlPointer->Version(); }
884
885std::string Declaration::Encoding() const { return m_tiXmlPointer->Encoding(); }
886
887std::string Declaration::Standalone() const {
888 return m_tiXmlPointer->Standalone();
889}
890
891//*****************************************************************************
897
901
903 const std::string& href)
905 new TiXmlStylesheetReference(type, href)) {
906 m_impRC->InitRef();
907}
908
909std::string StylesheetReference::Type() const { return m_tiXmlPointer->Type(); }
910
911std::string StylesheetReference::Href() const { return m_tiXmlPointer->Href(); }
912
913//*****************************************************************************
914
915Exception::Exception(const std::string& details)
916 : m_details(details) {}
917
919
920const char* Exception::what() const throw() { return m_details.c_str(); }
921
922//*****************************************************************************
923
925 // Spawn reference counter for this object
926 m_tiRC = new TiCppRCImp(this);
927}
928
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
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
953 : m_count(1)
954 , m_tiCppRC(tiCppRC) {}
955
957
959 m_count--;
960
961 if (0 == m_count) {
962 delete m_tiCppRC;
963 delete this;
964 }
965}
966
968
970
972
973bool TiCppRCImp::IsNull() { return 0 == m_tiCppRC; }
974
975#endif // TIXML_USE_TICPP
TiCppRC * m_tiCppRC
Holds pointer to an object inheriting TiCppRC.
Definition ticpprc.h:78
void DecRef()
Decrement Reference Count.
Definition ticpp.cpp:958
int m_count
Holds reference count to me, and to the node I point to.
Definition ticpprc.h:76
TiCppRCImp(TiCppRC *tiCppRC)
Initializes m_tiCppRC pointer, and set reference count to 1.
Definition ticpp.cpp:952
void Nullify()
Allows the TiCppRC object to set the pointer to itself ( m_tiCppRc ) to nullptr when the TiCppRC obje...
Definition ticpp.cpp:969
bool IsNull()
Returns state of internal pointer - will be null if the object was deleted.
Definition ticpp.cpp:973
void IncRef()
Increment Reference Count.
Definition ticpp.cpp:956
void InitRef()
Set Reference Count to 1 - dangerous!
Definition ticpp.cpp:967
TiCppRC * Get()
Get internal pointer to the TiCppRC object - not reference counted, use at your own risk.
Definition ticpp.cpp:971
Base class for reference counting functionality.
Definition ticpprc.h:41
void DeleteSpawnedWrappers()
Delete all container objects we've spawned with 'new'.
Definition ticpp.cpp:929
TiCppRC()
Constructor Spawns new reference counter with a pointer to this.
Definition ticpp.cpp:924
virtual ~TiCppRC()
Destructor Nullifies the pointer to this held by the reference counter Decrements reference count.
Definition ticpp.cpp:940
std::vector< ticpp::Base * > m_spawnedWrappers
Remember all wrappers that we've created with 'new' - ( e.g.
Definition ticpprc.h:63
An attribute is a name-value pair.
Definition tinyxml.h:915
An XML comment.
Definition tinyxml.h:1330
In correct XML the declaration is the first entry in the file.
Definition tinyxml.h:1469
Always the top level node.
Definition tinyxml.h:1655
The element is a container class.
Definition tinyxml.h:1095
The parent class for everything in the Document Object Model.
Definition tinyxml.h:454
int Type() const
Query the type (as an enumerated value, above) of this node.
Definition tinyxml.h:770
virtual const TiXmlComment * ToComment() const
Cast to a more defined type. Will return null if not of the requested type.
Definition tinyxml.h:792
const TiXmlElement * FirstChildElement() const
Convenience function to get through elements.
Definition tinyxml.cpp:384
const TiXmlNode * NextSibling(const std::string &_value) const
STL std::string form.
Definition tinyxml.h:695
virtual const TiXmlText * ToText() const
Cast to a more defined type. Will return null if not of the requested type.
Definition tinyxml.h:800
TiXmlNode * InsertAfterChild(TiXmlNode *afterThis, const TiXmlNode &addThis)
Add a new node related to this.
Definition tinyxml.cpp:231
const TiXmlNode * PreviousSibling() const
Navigate to a sibling node.
Definition tinyxml.h:678
TiXmlNode * ReplaceChild(TiXmlNode *replaceThis, const TiXmlNode &withThis)
Replace a child of this node.
Definition tinyxml.cpp:265
virtual const TiXmlDeclaration * ToDeclaration() const
Cast to a more defined type. Will return null if not of the requested type.
Definition tinyxml.h:804
const std::string & ValueStr() const
Return Value() as a std::string.
Definition tinyxml.h:524
const TiXmlNode * IterateChildren(const TiXmlNode *previous) const
An alternate way to walk the children of a node.
Definition tinyxml.cpp:331
void Clear()
Delete all the children of this node. Does not affect 'this'.
Definition tinyxml.cpp:139
TiXmlNode * InsertBeforeChild(TiXmlNode *beforeThis, const TiXmlNode &addThis)
Add a new node related to this.
Definition tinyxml.cpp:197
virtual const TiXmlStylesheetReference * ToStylesheetReference() const
Cast to a more defined type. Will return null if not of the requested type.
Definition tinyxml.h:808
virtual const TiXmlDocument * ToDocument() const
Cast to a more defined type. Will return null if not of the requested type.
Definition tinyxml.h:784
@ STYLESHEETREFERENCE
Definition tinyxml.h:499
@ DECLARATION
Definition tinyxml.h:498
virtual TiXmlNode * Clone() const =0
Create an exact duplicate of this node and return it.
const TiXmlNode * LastChild() const
Definition tinyxml.h:572
TiXmlNode * Parent()
One step up the DOM.
Definition tinyxml.h:549
bool NoChildren() const
Returns true if this node has no children.
Definition tinyxml.h:782
const TiXmlElement * NextSiblingElement() const
Convenience function to get through elements.
Definition tinyxml.cpp:404
virtual bool Accept(TiXmlVisitor *visitor) const =0
Accept a hierchical visit the nodes in the TinyXML DOM.
virtual const TiXmlElement * ToElement() const
Cast to a more defined type. Will return null if not of the requested type.
Definition tinyxml.h:788
const TiXmlDocument * GetDocument() const
Return a pointer to the Document this node lives in.
Definition tinyxml.cpp:424
const TiXmlNode * FirstChild() const
The first child of this node. Will be null if there are no children.
Definition tinyxml.h:552
TiXmlNode * InsertEndChild(const TiXmlNode &addThis)
Add a new node related to this.
Definition tinyxml.cpp:181
A stylesheet reference looks like this:
Definition tinyxml.h:1543
XML text.
Definition tinyxml.h:1386
Any tag that tinyXml doesn't recognize is saved as an unknown.
Definition tinyxml.h:1608
If you call the Accept() method, it requires being passed a TiXmlVisitor class to handle callbacks.
Definition tinyxml.h:144
virtual bool Visit(const TiXmlDeclaration &)
Visit a declaration.
Definition tinyxml.h:162
Wrapper around TiXmlAttribute.
Definition ticpp.h:297
std::string Name() const
Get the value of this attribute.
Definition ticpp.cpp:120
std::string Value() const
Get the value of this attribute.
Definition ticpp.cpp:115
void operator=(const Attribute &copy)
Definition ticpp.cpp:90
virtual void Print(FILE *file, int depth) const
All TinyXml classes can print themselves to a filestream.
Definition ticpp.cpp:169
void IterateNext(const std::string &, Attribute **next) const
Definition ticpp.cpp:161
Attribute()
Construct an empty attribute.
Definition ticpp.cpp:75
Attribute * Previous(bool throwIfNoAttribute=true) const
Get the previous sibling attribute in the DOM.
Definition ticpp.cpp:143
Attribute * Next(bool throwIfNoAttribute=true) const
Get the next sibling attribute in the DOM.
Definition ticpp.cpp:125
TiXmlAttribute * m_tiXmlPointer
Definition ticpp.h:299
void SetTiXmlPointer(TiXmlAttribute *newPointer)
Definition ticpp.cpp:174
void IteratePrevious(const std::string &, Attribute **previous) const
Definition ticpp.cpp:165
Wrapper around TiXmlBase.
Definition ticpp.h:161
void SetImpRC(TiXmlBase *nodeBase)
Definition ticpp.h:279
TiCppRCImp * m_impRC
Holds status of internal TiXmlPointer - use this to determine if object has been deleted already.
Definition ticpp.h:267
void ValidatePointer() const
Definition ticpp.h:281
Wrapper around TiXmlComment.
Definition ticpp.h:1349
Comment()
Constructor.
Definition ticpp.cpp:656
Wrapper around TiXmlDeclaration.
Definition ticpp.h:1896
std::string Encoding() const
Encoding.
Definition ticpp.cpp:885
Declaration()
Default Constructor.
Definition ticpp.cpp:867
std::string Standalone() const
StandAlone.
Definition ticpp.cpp:887
std::string Version() const
Version.
Definition ticpp.cpp:883
Wrapper around TiXmlDocument.
Definition ticpp.h:1409
void LoadFile(TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
Load a file using the current document value.
Definition ticpp.cpp:705
void Parse(const std::string &xml, bool throwIfParseError=true, TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
Parse the given xml data.
Definition ticpp.cpp:735
void SaveFile() const
Save a file using the current document value.
Definition ticpp.cpp:711
Document()
Default Constructor.
Definition ticpp.cpp:687
Wrapper around TiXmlElement.
Definition ticpp.h:1500
bool GetTextImp(std::string *value) const
Definition ticpp.cpp:850
bool GetAttributeImp(const std::string &name, std::string *value) const
Definition ticpp.cpp:835
Attribute * LastAttribute(bool throwIfNoAttributes=true) const
Access the last attribute in this element.
Definition ticpp.cpp:788
void RemoveAttribute(const std::string &name)
Removes attribute from element.
Definition ticpp.cpp:830
Attribute * FirstAttribute(bool throwIfNoAttributes=true) const
Access the first attribute in this element.
Definition ticpp.cpp:766
Element()
Default Constructor.
Definition ticpp.cpp:747
T GetAttribute(const std::string &name, bool throwIfNotFound=true) const
Returns an attribute of name from an element.
Definition ticpp.h:1799
bool HasAttribute(const std::string &name) const
Returns true, if attribute exists.
Definition ticpp.cpp:825
void GetAttributeOrDefault(const std::string &name, T *value, const DefaulT &defaultValue) const
Gets an attribute of name from an element, if it doesn't exist it will return the defaultValue.
Definition ticpp.h:1756
std::string m_details
Exception Details.
Definition ticpp.h:85
const char * what() const
Override std::exception::what() to return m_details.
Definition ticpp.cpp:920
Exception(const std::string &details)
Construct an exception with a message.
Definition ticpp.cpp:915
NodeImp(TiXmlComment *tiXmlPointer)
Definition ticpp.h:1292
TiXmlComment * m_tiXmlPointer
Definition ticpp.h:1262
Wrapper around TiXmlNode.
Definition ticpp.h:460
Comment * ToComment() const
Pointer conversion - replaces TiXmlNode::ToComment.
Definition ticpp.cpp:583
Node * ReplaceChild(Node *replaceThis, Node &withThis)
Replace a child of this node.
Definition ticpp.cpp:383
Declaration * ToDeclaration() const
Pointer conversion - replaces TiXmlNode::ToDeclaration.
Definition ticpp.cpp:609
std::unique_ptr< Node > Clone() const
Create an exact duplicate of this node and return it.
Definition ticpp.cpp:635
StylesheetReference * ToStylesheetReference() const
Pointer conversion - replaces TiXmlNode::ToStylesheetReference.
Definition ticpp.cpp:622
Element * FirstChildElement(bool throwIfNoChildren=true) const
The first child element of this node.
Definition ticpp.cpp:501
Node * Parent(bool throwIfNoParent=true) const
The Parent of this Node.
Definition ticpp.cpp:234
bool Accept(TiXmlVisitor *visitor) const
Accept a hierchical visit the nodes in the TinyXML DOM.
Definition ticpp.cpp:650
void Clear()
Clear all Nodes below this.
Definition ticpp.cpp:232
bool NoChildren() const
Check if this node has no children.
Definition ticpp.cpp:555
void RemoveChild(Node *removeThis)
Delete a child of this node.
Definition ticpp.cpp:401
Document * ToDocument() const
Pointer conversion - replaces TiXmlNode::ToDocument.
Definition ticpp.cpp:557
std::string Value() const
Get the value of this node.
Definition ticpp.cpp:230
Node * NodeFactory(TiXmlNode *tiXmlNode, bool throwIfNull=true, bool rememberSpawnedWrapper=true) const
Definition ticpp.cpp:181
Element * NextSiblingElement(bool throwIfNoSiblings=true) const
Navigate to a sibling element.
Definition ticpp.cpp:464
Node * InsertAfterChild(Node *afterThis, Node &addThis)
Adds a child after the specified child.
Definition ticpp.cpp:365
Node * InsertEndChild(Node &addThis)
Adds a child past the LastChild.
Definition ticpp.cpp:317
Node * LastChild(bool throwIfNoChildren=true) const
The last child of this node.
Definition ticpp.cpp:268
Node * InsertBeforeChild(Node *beforeThis, Node &addThis)
Adds a child before the specified child.
Definition ticpp.cpp:347
Node * NextSibling(bool throwIfNoSiblings=true) const
Navigate to a sibling node.
Definition ticpp.cpp:438
Document * GetDocument(bool throwIfNoDocument=true) const
Return a pointer to the Document this node lives in.
Definition ticpp.cpp:538
Node * IterateChildren(Node *previous) const
An alternate way to walk the children of a node.
Definition ticpp.cpp:292
int Type() const
Query the type (as TiXmlNode::NodeType ) of this node.
Definition ticpp.cpp:536
Node * PreviousSibling(bool throwIfNoSiblings=true) const
Navigate to a sibling node.
Definition ticpp.cpp:410
virtual TiXmlNode * GetTiXmlPointer() const =0
Node * LinkEndChild(Node *childNode)
Adds a child past the LastChild.
Definition ticpp.cpp:332
Node * FirstChild(bool throwIfNoChildren=true) const
The first child of this node.
Definition ticpp.cpp:244
Element * ToElement() const
Pointer conversion - replaces TiXmlNode::ToElement.
Definition ticpp.cpp:570
Text * ToText() const
Pointer conversion - replaces TiXmlNode::ToText.
Definition ticpp.cpp:596
Wrapper around TiXmlStylesheetReference.
Definition ticpp.h:1934
std::string Href() const
Href.
Definition ticpp.cpp:911
StylesheetReference()
Default Constructor.
Definition ticpp.cpp:893
std::string Type() const
Type.
Definition ticpp.cpp:909
Wrapper around TiXmlText.
Definition ticpp.h:1371
Text()
Constructor.
Definition ticpp.cpp:672
virtual bool VisitExit(const TiXmlDocument &doc)
Visit a document.
Definition ticpp.cpp:38
virtual bool VisitEnter(const TiXmlDocument &doc)
Visit a document.
Definition ticpp.cpp:34
virtual bool Visit(const TiXmlDeclaration &declaration)
Visit a declaration.
Definition ticpp.cpp:56
ticpp is a TinyXML wrapper that uses a lot more C++ ideals.
Definition ticpp.h:70
ticpp is a TinyXML wrapper that uses a lot more C++ ideals.
#define TICPPTHROW(message)
This allows you to stream your exceptions in.
Definition ticpp.h:92
TiXmlEncoding
Definition tinyxml.h:179