This repository has been archived by the owner on Jul 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
/
ticpp.h
1862 lines (1547 loc) · 47.6 KB
/
ticpp.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
http://code.google.com/p/ticpp/
Copyright (c) 2006 Ryan Pusztai, Ryan Mulder
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/**
@copydoc ticpp
@file
@author Ryan Pusztai
@author Ryan Mulder
@date 04/11/2006
@version 0.04a by [email protected]: based Exception based on std::exception; added stream
<< and >> support; added Document::Parse(); bug fix; improved THROW() macro.
@version 0.04 Added NodeImp class. Also made all the classes inherit from NodeImp.
@version 0.03 Added Declaration class
@version 0.02 Added Element class
@version 0.01 Added Exception class, Document class
@todo add UNKNOWN support. See ticpp::NodeFactory.
@todo add TYPECOUNT support. See ticpp::NodeFactory.
@todo Add a quick reference
*/
/*
* THIS FILE WAS ALTERED BY Matt Janisz, 12. October 2012.
*
* - added ticppapi.h include and TICPP_API dll-interface to support building DLL using VS200X
*/
#ifndef TIXML_USE_TICPP
#define TIXML_USE_TICPP
#endif
#ifndef TICPP_INCLUDED
#define TICPP_INCLUDED
#include "tinyxml.h"
#include <memory>
/**
@subpage ticpp is a TinyXML wrapper that uses a lot more C++ ideals.
It throws exceptions, uses templates, is in its own name space, and
<b>requires</b> STL (Standard Template Library). This is done to ease the use
of getting values in and out of the xml.
If you don't perfer to use some of the concepts just don't use it.
It is just a wrapper that extends TinyXML. It doesn't actually change
any of TinyXML.
*/
namespace ticpp
{
/**
This is a ticpp exception class
*/
class TICPP_API Exception : public std::exception
{
public:
/**
Construct an exception with a message
*/
Exception( const std::string& details );
~Exception() throw();
/// Override std::exception::what() to return m_details
const char* what() const throw();
std::string m_details; /**< Exception Details */
};
/**
This allows you to stream your exceptions in.
It will take care of the conversion and throwing the exception.
*/
#define TICPPTHROW( message ) \
{ \
std::ostringstream full_message; \
std::string file( __FILE__ ); \
file = file.substr( file.find_last_of( "\\/" ) + 1 ); \
full_message << message << " <" << file << "@" << __LINE__ << ">"; \
full_message << BuildDetailedErrorString(); \
throw Exception( full_message.str() ); \
}
// Forward Declarations for Visitor, and others.
class TICPP_API Document;
class TICPP_API Element;
class TICPP_API Declaration;
class TICPP_API StylesheetReference;
class TICPP_API Text;
class TICPP_API Comment;
class TICPP_API Attribute;
/** Wrapper around TiXmlBase */
class TICPP_API Base
{
public:
/**
Converts any class with a proper overload of the << opertor to a std::string
@param value The value to be converted
@throws Exception When value cannot be converted to a std::string
*/
template < class T >
std::string ToString( const T& value ) const
{
std::stringstream convert;
convert << value;
if ( convert.fail() )
{
TICPPTHROW( "Could not convert value to text" );
}
return convert.str();
}
std::string ToString( const std::string& value ) const
{
return value;
}
/**
Converts a std::string to any class with a proper overload of the >> opertor
@param temp The string to be converted
@param out [OUT] The container for the returned value
@throws Exception When temp cannot be converted to the target type
*/
template < class T >
void FromString( const std::string& temp, T* out ) const
{
std::istringstream val( temp );
val >> *out;
if ( val.fail() )
{
TICPPTHROW( "Could not convert \"" << temp << "\" to target type" );
}
}
/**
Specialization for std::string
*/
void FromString( const std::string& temp, std::string* out ) const
{
*out = temp;
}
/**
Return the position, in the original source file, of this node or attribute.
Wrapper around TiXmlBase::Row()
*/
int Row() const
{
return GetBasePointer()->Row();
}
/**
Return the position, in the original source file, of this node or attribute.
Wrapper around TiXmlBase::Row()
*/
int Column() const
{
return GetBasePointer()->Column();
}
/**
Compare internal TiXml pointers to determine is both are wrappers around the same node
*/
bool operator == ( const Base& rhs ) const
{
return ( GetBasePointer() == rhs.GetBasePointer() );
}
/**
Compare internal TiXml pointers to determine is both are wrappers around the same node
*/
bool operator != ( const Base& rhs ) const
{
return ( GetBasePointer() != rhs.GetBasePointer() );
}
/**
Builds detailed error string using TiXmlDocument::Error() and others
*/
std::string BuildDetailedErrorString() const
{
std::ostringstream full_message;
#ifndef TICPP_NO_RTTI
TiXmlNode* node = dynamic_cast< TiXmlNode* >( GetBasePointer() );
if ( node != 0 )
{
TiXmlDocument* doc = node->GetDocument();
if ( doc != 0 )
{
if ( doc->Error() )
{
full_message << "\nDescription: " << doc->ErrorDesc()
<< "\nFile: " << (strlen( doc->Value() ) > 0 ? doc->Value() : "<unnamed-file>")
<< "\nLine: " << doc->ErrorRow()
<< "\nColumn: " << doc->ErrorCol();
}
}
}
#endif
return full_message.str();
}
/**
Destructor
*/
virtual ~Base()
{
}
protected:
mutable TiCppRCImp* m_impRC; /**< Holds status of internal TiXmlPointer - use this to determine if object has been deleted already */
/**
@internal
Updates the pointer to the reference counter to point at the counter in the new node.
@param node TiXmlBase containing the new reference counter
*/
void SetImpRC( TiXmlBase* node )
{
m_impRC = node->m_tiRC;
}
void ValidatePointer() const
{
if ( m_impRC->IsNull() )
{
TICPPTHROW( "Internal TiXml Pointer is NULL" );
}
}
/**
@internal
Get internal TiXmlBase*
*/
virtual TiXmlBase* GetBasePointer() const = 0;
};
/**
Wrapper around TiXmlAttribute
*/
class TICPP_API Attribute : public Base
{
private:
TiXmlAttribute* m_tiXmlPointer;
TiXmlBase* GetBasePointer() const
{
ValidatePointer();
return m_tiXmlPointer;
}
public:
/**
Construct an empty attribute.
*/
Attribute();
/**
Construct an attribute with @a name and @a value
@param name The name of the attribute
@param value The value of the attribute
*/
Attribute( const std::string& name, const std::string& value );
/**
@internal
Construct an attribute with the internal pointer
@param attribute The internal pointer
*/
Attribute( TiXmlAttribute* attribute );
/**
Get the value of this attribute
Uses Base::FromString to convert TiXmlAttribute::ValueStr from a std::string,
and puts it in the passed pointer.
@param value [OUT] A pointer to fill with the value
*/
template < class T >
void GetValue( T* value ) const
{
ValidatePointer();
FromString( m_tiXmlPointer->ValueStr(), value );
}
/**
Get the value of this attribute.
Simple wrapper for TiXmlAttribute::ValueStr.
@see GetValue
*/
std::string Value() const;
/**
Set the value of this node.
Uses Base::ToString to convert value to a std::string, then calls TiXmlAttribute::SetValue.
@param value The value to set
*/
template < class T >
void SetValue( const T& value )
{
ValidatePointer();
m_tiXmlPointer->SetValue( ToString( value ) );
}
/**
Get the value of this attribute
Uses Base::FromString to convert TiXmlAttribute::Name from a std::string,
and puts it in the passed pointer.
@param name [OUT] A pointer to fill with the name
*/
template < class T >
void GetName( T* name ) const
{
ValidatePointer();
FromString( m_tiXmlPointer->Name(), name );
}
/**
Get the value of this attribute.
Simple wrapper for TiXmlAttribute::Name.
@see GetName
*/
std::string Name() const;
/**
Set the value of this attribute.
Uses Base::ToString to convert @a name to a std::string, then calls TiXmlAttribute::SetName.
@param name The name to set
*/
template < class T >
void SetName( const T& name )
{
ValidatePointer();
m_tiXmlPointer->SetName( ToString( name ) );
}
/**
@internal
Updates the reference count for the old and new pointers.
*/
void operator=( const Attribute& copy );
Attribute( const Attribute& copy ) = delete;
/*
Decrements reference count.
*/
~Attribute();
/**
Get the next sibling attribute in the DOM.
*/
Attribute* Next( bool throwIfNoAttribute = true ) const;
/**
Get the previous sibling attribute in the DOM.
*/
Attribute* Previous( bool throwIfNoAttribute = true ) const;
/**
@internal
Just for Iterator<>
@param next [OUT] The pointer to the next valid attribute
@return true if there is a next attribute, false if not
*/
void IterateNext( const std::string&, Attribute** next ) const;
/**
@internal
Just for Iterator<>
@param previous [OUT] The pointer to the previous valid attribute
@return true if there is a previous attribute, false if not
*/
void IteratePrevious( const std::string&, Attribute** previous ) const;
/**
All TinyXml classes can print themselves to a filestream.
*/
virtual void Print( FILE* file, int depth ) const;
private:
/**
@internal
Sets the internal pointer.
Saves a copy of the pointer to the RC object.
@param newPointer TiXmlAttribute* to set.
*/
void SetTiXmlPointer( TiXmlAttribute* newPointer );
};
/**
Wrapper around TiXmlNode
*/
class TICPP_API Node : public Base
{
public:
/**
Get the value of this node
Uses Base::FromString to convert TiXmlNode::ValueStr from a std::string,
and puts it in the passed pointer.
@param value [OUT] A pointer to fill with the value
*/
template < class T >
void GetValue( T* value) const
{
FromString( GetTiXmlPointer()->ValueStr(), value );
}
/**
Get the value of this node.
Simple wrapper for TiXmlNode::ValueStr.
@see GetValue
*/
std::string Value() const;
/**
Set the value of this node.
Uses Base::ToString to convert value to a std::string, then calls TiXmlNode::SetValue.
@param value The value to set
*/
template < class T >
void SetValue( const T& value )
{
GetTiXmlPointer()->SetValue( ToString( value ) );
}
/**
Clear all Nodes below this.
Simple wrapper for TiXmlNode::Clear.
*/
void Clear();
/**
The Parent of this Node.
Simple wrapper for TiXmlNode::Parent.
@param throwIfNoParent [DEF] If true, throws when Parent = NULL.
@return The parent of this node, NULL if there is no Parent.
@throws Exception When throwIfNoParent is true, and TiXmlNode::Parent returns Null.
*/
Node* Parent( bool throwIfNoParent = true ) const;
/**
The first child of this node.
@param throwIfNoChildren [DEF] If true, will throw an exception if there are no children.
@return Pointer to child, Null if no children and 'throwIfNoChildren' is false.
@throws Exception When throwIfNoChildren is true, and TiXmlNode::FirstChild returns Null.
@see TiXmlNode::FirstChild
*/
Node* FirstChild( bool throwIfNoChildren = true ) const;
/**
@internal
The first child of this node with the matching @a value.
@overload
@param value Value to match.
@param throwIfNoChildren [DEF] If true, will throw an exception if there are no children.
@see FirstChild( bool throwIfNoChildren = true )
*/
Node* FirstChild( const char* value, bool throwIfNoChildren = true ) const;
/**
The first child of this node with the matching @a value.
@overload
@param value Value to match.
@param throwIfNoChildren [DEF] If true, will throw an exception if there are no children.
@see FirstChild( const char* value, bool throwIfNoChildren = true )
*/
Node* FirstChild( const std::string& value, bool throwIfNoChildren = true ) const;
/**
The last child of this node.
@param throwIfNoChildren [DEF] If true, will throw an exception if there are no children.
@return Pointer to child, Null if no children and 'throwIfNoChildren' is false.
@throws Exception When throwIfNoChildren is true, and TiXmlNode::LastChild returns Null.
@see TiXmlNode::LastChild
*/
Node* LastChild( bool throwIfNoChildren = true ) const;
/**
@internal
The last child of this node with the matching @a value.
@overload
@param value Value to match.
@param throwIfNoChildren [DEF] If true, will throw an exception if there are no children.
@see LastChild( bool throwIfNoChildren = true )
*/
Node* LastChild( const char* value, bool throwIfNoChildren = true ) const;
/**
The last child of this node with the matching @a value.
@overload
@param value Value to match.
@param throwIfNoChildren [DEF] If true, will throw an exception if there are no children.
@see LastChild( const char* value, bool throwIfNoChildren = true )
*/
Node* LastChild( const std::string& value, bool throwIfNoChildren = true ) const;
/**
An alternate way to walk the children of a node.
Simple wrapper for TiXmlNode::IterateChildren.
@param previous The previous Node* that was returned from IterateChildren.
@return NULL When there are no more children.
*/
Node* IterateChildren( Node* previous ) const;
/**
This flavor of IterateChildren searches for children with a particular @a value.
Simple wrapper for TiXmlNode::IterateChildren.
@param value The value you want to search for.
@param previous The previous Node* that was returned from IterateChildren.
@return NULL When there are no more children.
*/
Node* IterateChildren( const std::string& value, Node* previous ) const;
/**
Adds a child past the LastChild.
Throws if you try to insert a document.
@note This takes a copy of @a addThis so it is not as efficiant as LinkEndChild.
@param addThis Node to insert.
@throws Exception When TiXmlNode::InsertEndChild returns Null
@see LinkEndChild
@see TiXmlNode::InsertEndChild
*/
Node* InsertEndChild( const Node& addThis );
/**
Adds a child past the LastChild.
Throws if you try to link a document.
@param childNode Node to link.
@throws Exception When TiXmlNode::LinkEndChild returns Null.
@see InsertEndChild
@see TiXmlNode::LinkEndChild
*/
Node* LinkEndChild( Node* childNode );
/**
Adds a child before the specified child.
Throws if you try to insert a document.
@param beforeThis Node that will have @a addThis linked before.
@param addThis Node to insert before.
@throws Exception When TiXmlNode::InsertBeforeChild returns Null.
@see InsertAfterChild
@see TiXmlNode::InsertBeforeChild
*/
Node* InsertBeforeChild( Node* beforeThis, const Node& addThis );
/**
Adds a child after the specified child.
Throws if you try to insert a document.
@param afterThis Node that will have @a addThis linked after.
@param addThis Node to insert after.
@throws Exception When TiXmlNode::InsertAfterChild returns Null.
@see InsertBeforeChild
@see TiXmlNode::InsertAfterChild
*/
Node* InsertAfterChild( Node* afterThis, const Node& addThis );
/**
Replace a child of this node.
Throws if you try to replace with a document.
@param replaceThis Node to replace.
@param withThis Node that is replacing @a replaceThis.
@throws Exception When TiXmlNode::ReplaceChild returns Null.
@see TiXmlNode::ReplaceChild
*/
Node* ReplaceChild( Node* replaceThis, const Node& withThis );
/**
Delete a child of this node.
@param removeThis Node to delete.
@throws Exception When removeThis is not a child of this Node.
@see TiXmlNode::RemoveChild
*/
void RemoveChild( Node* removeThis );
/**
Navigate to a sibling node.
Wrapper around TiXmlNode::PreviousSibling.
@param throwIfNoSiblings [DEF] If true, will throw an exception if there are no siblings.
@return Pointer to sibling, Null if no siblings and 'throwIfNoSiblings' is false.
@throws Exception When TiXmlNode::PreviousSibling returns Null and 'throwIfNoSiblings' is true.
*/
Node* PreviousSibling( bool throwIfNoSiblings = true ) const;
/**
Navigate to a sibling node with the given @a value.
@overload
@param value The value of the node to look for.
@param throwIfNoSiblings [DEF] If true, will throw an exception if there are no siblings.
@see PreviousSibling( bool throwIfNoSiblings )
*/
Node* PreviousSibling( const std::string& value, bool throwIfNoSiblings = true ) const;
/**
@internal
Navigate to a sibling node with the given @a value.
@overload
@param value The value of the node to look for.
@param throwIfNoSiblings [DEF] If true, will throw an exception if there are no siblings.
@see PreviousSibling( const std::string& value, bool throwIfNoSiblings )
*/
Node* PreviousSibling( const char* value, bool throwIfNoSiblings = true ) const;
/**
Navigate to a sibling node.
Wrapper around TiXmlNode::NextSibling.
@param throwIfNoSiblings [DEF] If true, will throw an exception if there are no siblings.
@return Pointer to sibling, Null if no siblings and 'throwIfNoSiblings' is false.
@throws Exception When TiXmlNode::NextSibling returns Null and 'throwIfNoSiblings' is true.
*/
Node* NextSibling( bool throwIfNoSiblings = true ) const;
/**
Navigate to a sibling node with the given @a value.
@overload
@param value The value of the node to look for.
@param throwIfNoSiblings [DEF] If true, will throw an exception if there are no siblings.
@see NextSibling( bool throwIfNoSiblings )
*/
Node* NextSibling( const std::string& value, bool throwIfNoSiblings = true ) const;
/**
@internal
Navigate to a sibling node with the given @a value.
@overload
@param value The value of the node to look for.
@param throwIfNoSiblings [DEF] If true, will throw an exception if there are no siblings.
@see NextSibling( const std::string& value, bool throwIfNoSiblings )
*/
Node* NextSibling( const char* value, bool throwIfNoSiblings = true ) const;
/**
@internal
Just for Iterator<>
@param value The value of nodes to iterate through
@param next [OUT] The pointer to the first valid node
*/
template < class T >
void IterateFirst( const std::string& value, T** first ) const
{
*first = 0;
for( Node* child = FirstChild( value, false ); child; child = child->NextSibling( value, false ) )
{
*first = dynamic_cast< T* >( child );
if ( 0 != *first )
{
return;
}
}
}
virtual void IterateFirst( const std::string&, Attribute** ) const
{
TICPPTHROW( "Attributes can only be iterated with Elements." )
}
/**
@internal
Just for Iterator<>
@param value The value of nodes to iterate through
@param next [OUT] The pointer to the next valid node
*/
template < class T >
void IterateNext( const std::string& value, T** next ) const
{
Node* sibling = NextSibling( value, false );
*next = dynamic_cast< T* >( sibling );
while ( ( 0 != sibling ) && ( 0 == *next ) )
{
sibling = sibling->NextSibling( value, false );
*next = dynamic_cast< T* >( sibling );
}
}
/**
@internal
Just for Iterator<>
@param value The value of nodes to iterate through
@param previous [OUT] The pointer to the previous valid node
*/
template < class T >
void IteratePrevious( const std::string& value, T** previous ) const
{
Node* sibling = PreviousSibling( value, false );
*previous = dynamic_cast< T* >( sibling );
while ( ( 0 != sibling ) && ( 0 == *previous ) )
{
sibling = sibling->PreviousSibling( value, false );
*previous = dynamic_cast< T* >( sibling );
}
}
/**
Navigate to a sibling element.
Wrapper around TiXmlNode::NextSibling.
@param throwIfNoSiblings [DEF] If true, will throw an exception if there are no sibling element.
@return Pointer to sibling, Null if no siblings and 'throwIfNoSiblings' is false.
@throws Exception When TiXmlNode::NextSibling returns Null and 'throwIfNoSiblings' is true.
*/
Element* NextSiblingElement( bool throwIfNoSiblings = true ) const;
/**
Navigate to a sibling element with the given @a value.
@overload
@param value The value of the element to look for.
@param throwIfNoSiblings [DEF] If true, will throw an exception if there are no sibling elements.
@see NextSiblingElement( bool throwIfNoSiblings )
*/
Element* NextSiblingElement( const std::string& value, bool throwIfNoSiblings = true ) const;
/**
@internal
Navigate to a sibling element with the given @a value.
@overload
@param value The value of the element to look for.
@param throwIfNoSiblings [DEF] If true, will throw an exception if there are no sibling elements.
@see NextSiblingElement( const std::string& value, bool throwIfNoSiblings )
*/
Element* NextSiblingElement( const char* value, bool throwIfNoSiblings = true ) const;
/**
The first child element of this node.
@param throwIfNoChildren [DEF] If true, will throw an exception if there are no element children.
@return Pointer to child, Null if no element children and 'throwIfNoChildren' is false.
@throws Exception When throwIfNoChildren is true, and TiXmlNode::FirstChildElement returns Null.
@see TiXmlNode::FirstChildElement
*/
Element* FirstChildElement( bool throwIfNoChildren = true ) const;
/**
@internal
The first child element of this node with the matching @a value.
@overload
@param value Value to match.
@param throwIfNoChildren [DEF] If true, will throw an exception if there are no element children.
@see FirstChildElement( bool throwIfNoChildren = true )
*/
Element* FirstChildElement( const char* value, bool throwIfNoChildren = true ) const;
/**
The first child element of this node with the matching @a value.
@overload
@param value Value to match.
@param throwIfNoChildren [DEF] If true, will throw an exception if there are no element children.
@see FirstChildElement( const char* value, bool throwIfNoChildren = true )
*/
Element* FirstChildElement( const std::string& value, bool throwIfNoChildren = true ) const;
/**
Query the type (as TiXmlNode::NodeType ) of this node.
*/
int Type() const;
/**
Return a pointer to the Document this node lives in.
@param throwIfNoDocument [DEF] If true, will throw an exception if this node is not linked under a Document.
@return A pointer to the Document this node lives in, NULL if not linked under a Document, and 'throwIfNoDocument' is false.
@throws Exception When this node is not linked under a Document and 'throwIfNoDocument' is true.
*/
Document* GetDocument( bool throwIfNoDocument = true ) const;
/**
Check if this node has no children.
@return true if this node has no children.
*/
bool NoChildren() const;
#ifndef TICPP_NO_RTTI
/**
Pointer conversion ( NOT OBJECT CONVERSION ) - replaces TiXmlNode::ToElement, TiXmlNode::ToDocument, TiXmlNode::ToComment, etc.
@throws Exception When the target is not an object of class T
@warning Some ancient compilers do not support explicit specification of member template arguments, which this depends on ( e.g. VC6 ).
*/
template < class T >
T* To() const
{
T* pointer = dynamic_cast< T* >( this );
if ( 0 == pointer )
{
std::string thisType = typeid( this ).name();
std::string targetType = typeid( T ).name();
std::string thatType = typeid( *this ).name();
TICPPTHROW( "The " << thisType.substr( 6 ) << " could not be casted to a " << targetType.substr( 6 )
<< " *, because the target object is not a " << targetType.substr( 6 ) << ". (It is a " << thatType.substr( 6 ) << ")" );
}
return pointer;
}
#endif
/**
Pointer conversion - replaces TiXmlNode::ToDocument.
@throws Exception When this node is not a Document.
*/
Document* ToDocument() const;
/**
Pointer conversion - replaces TiXmlNode::ToElement.
@throws Exception When this node is not a Element.
*/
Element* ToElement() const;
/**
Pointer conversion - replaces TiXmlNode::ToComment.
@throws Exception When this node is not a Comment.
*/
Comment* ToComment() const;
/**
Pointer conversion - replaces TiXmlNode::ToText.
@throws Exception When this node is not a Text.
*/
Text* ToText() const;
/**
Pointer conversion - replaces TiXmlNode::ToDeclaration.
@throws Exception When this node is not a Declaration.
*/
Declaration* ToDeclaration() const;
/**
Pointer conversion - replaces TiXmlNode::ToStylesheetReference.
@throws Exception When this node is not a StylesheetReference.
*/
StylesheetReference* ToStylesheetReference() const;
/**
Create an exact duplicate of this node and return it.
@note Using unique_ptr to manage the memory declared on the heap by TiXmlNode::Clone.
@code
// Now using clone
ticpp::Document doc( "C:\\Test.xml" );
ticpp::Node* sectionToClone;
sectionToClone = doc.FirstChild( "settings" );
std::unique_ptr< ticpp::Node > clonedNode = sectionToClone->Clone();
// Now you can use the clone.
ticpp::Node* node2 = clonedNode->FirstChildElement()->FirstChild();
...
// After the variable clonedNode goes out of scope it will automatically be cleaned up.
@endcode
@return Pointer the duplicate node.
*/
std::unique_ptr< Node > Clone() const;
/**
Accept a hierchical visit the nodes in the TinyXML DOM.
@return The boolean returned by the visitor.
*/
bool Accept( TiXmlVisitor* visitor ) const;
/**
Stream input operator.
*/
friend std::istream& operator >>( std::istream& in, Node& base )
{
in >> *base.GetTiXmlPointer();
return in;
}
/**
Stream output operator.
*/
friend std::ostream& operator <<( std::ostream& out, const Node& base )
{
out << *base.GetTiXmlPointer();
return out;
}
protected:
/**
@internal
Allows NodeImp to use Node*'s.
*/
virtual TiXmlNode* GetTiXmlPointer() const = 0;
TiXmlBase* GetBasePointer() const
{
return GetTiXmlPointer();
}
/**
@internal
Constructs the correct child of Node, based on the Type of the TiXmlNode*.
*/
Node* NodeFactory( TiXmlNode* tiXmlNode, bool throwIfNull = true, bool rememberSpawnedWrapper = true ) const;
};
/** Iterator for conveniently stepping through Nodes and Attributes.
TinyXML++ introduces iterators:
@code
ticpp::Iterator< ticpp::Node > child;
for ( child = child.begin( parent ); child != child.end(); child++ )
@endcode
Iterators have the added advantage of filtering by type:
@code
// Only iterates through Comment nodes
ticpp::Iterator< ticpp::Comment > child;
for ( child = child.begin( parent ); child != child.end(); child++ )
@endcode