summaryrefslogtreecommitdiff
path: root/ticpp/ticpp.h
blob: c3c900c45abb31f4e2274fb9e8fcbc31d9862745 (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
/*
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 edam@waxworlds.org: 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 "ticppapi.h"
#include "tinyxml.h"
#include <sstream>
#include <vector>
#include <memory>
#include <exception>
#include <typeinfo>

/**
@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 TiXmlVisitor */
	class TICPP_API Visitor : public TiXmlVisitor
	{
	public:
		// Overload the TiXmlVisitor functions, wrap objects, call ticpp::Visitor functions
		/// @internal
		virtual bool VisitEnter( const TiXmlDocument& doc );
		/// @internal
		virtual bool VisitExit( const TiXmlDocument& doc );
		/// @internal
		virtual bool VisitEnter( const TiXmlElement& element, const TiXmlAttribute* firstAttribute );
		/// @internal
		virtual bool VisitExit( const TiXmlElement& element );
		/// @internal
		virtual bool Visit( const TiXmlDeclaration& declaration );
		/// @internal
		virtual bool Visit( const TiXmlStylesheetReference& stylesheet );
		/// @internal
		virtual bool Visit( const TiXmlText& text );
		/// @internal
		virtual bool Visit( const TiXmlComment& comment );

	public:
		/// Visit a document.
		virtual bool VisitEnter( const Document& /*doc*/ )			{ return true; }
		/// Visit a document.
		virtual bool VisitExit( const Document& /*doc*/ )			{ return true; }

		/// Visit an element.
		virtual bool VisitEnter( const Element& /*element*/, const Attribute* /*firstAttribute*/ )	{ return true; }
		/// Visit an element.
		virtual bool VisitExit( const Element& /*element*/ )		{ return true; }

		/// Visit a declaration
		virtual bool Visit( const Declaration& /*declaration*/ )	{ return true; }
		/// Visit a stylesheet reference
		virtual bool Visit( const StylesheetReference& /*stylesheet*/ )	{ return true; }
		/// Visit a text node
		virtual bool Visit( const Text& /*text*/ )					{ return true; }
		/// Visit a comment node
		virtual bool Visit( const Comment& /*comment*/ )			{ return true; }
	};

	/** 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 );

		/**
		@internal
		Updates the reference count for the old and new pointers.
		*/
		Attribute( const Attribute& copy );

		/*
		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 auto_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::auto_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::auto_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

	@code
	// Only iterates through Element nodes with value "ElementValue"
	ticpp::Iterator< ticpp::Element > child( "ElementValue" );
	for ( child = child.begin( parent ); child != child.end(); child++ )
	@endcode

	Finally, Iterators also work with Attributes
	@code
	ticpp::Iterator< ticpp::Attribute > attribute;
	for ( attribute = attribute.begin( element ); attribute != attribute.end(); attribute++ )
	@endcode
	*/
	template < class T = Node >
		class Iterator
	{
	private:
		T* m_p;					/**< Internal Pointer */
		std::string m_value;	/**< Value for NextSibling  calls */

	public:

		/**
		For for loop comparisons.
		@param parent The parent of the nodes to iterate.
		@return The first child of type T.
		@code
		ticpp::Iterator< ticpp::Node > child;
		for ( child = child.begin( parent ); child != child.end(); child++ )
		@endcode
		*/
		T* begin( const Node* parent ) const
		{
			T* pointer;
			parent->IterateFirst( m_value, &pointer );
			return pointer;
		}

		/**
		For for loop comparisons.
		@return NULL
		@code
		ticpp::Iterator< ticpp::Node > child;
		for ( child = child.begin( parent ); child != child.end(); child++ )
		@endcode
		*/
		T* end() const
		{
			return 0;
		}

		/** Constructor.
		@param value If not empty, this iterator will only visit nodes with matching value.
		@code
		// Only iterates through Element nodes with value "ElementValue"
		ticpp::Iterator< ticpp::Element > child( "ElementValue" );
		for ( child = child.begin( parent ); child != child.end(); child++ )
		@endcode
		*/
		Iterator( const std::string& value = "" )
			: m_p( 0 ), m_value( value )
		{
		}

		/// Constructor
		Iterator( T* node, const std::string& value = "" )
			: m_p( node ), m_value( value )
		{
		}

		/// Constructor
		Iterator( const Iterator& it )
			: m_p( it.m_p ), m_value( it.m_value )
		{
		}

		/**
		Gets internal pointer.
		@return The internal pointer.
		*/
		T* Get() const
		{
			return m_p;
		}

		/** Sets internal pointer */
		Iterator& operator=( const Iterator& it )
		{
			m_p = it.m_p;
			m_value = it.m_value;
			return *this;
		}

		/** Sets internal pointer */
		Iterator& operator=( T* p )
		{
			m_p = p;
			return *this;
		}

		/** Sets internal pointer to the Next Sibling, or Iterator::END, if there are no more siblings */
		Iterator& operator++()
		{
			m_p->IterateNext( m_value, &m_p );
			return *this;
		}

		/** Sets internal pointer to the Next Sibling, or Iterator::END, if there are no more siblings */
		Iterator operator++(int)
		{
			Iterator tmp(*this);
			++(*this);
			return tmp;
		}

		/** Sets internal pointer to the Previous Sibling, or Iterator::END, if there are no prior siblings */
		Iterator& operator--()
		{
			m_p->IteratePrevious( m_value, &m_p );
			return *this;
		}

		/** Sets internal pointer to the Previous Sibling, or Iterator::END, if there are no prior siblings */
		Iterator operator--(int)
		{
			Iterator tmp(*this);
			--(*this);
			return tmp;
		}

		/** Compares internal pointer */
		bool operator!=( const T* p ) const
		{
			if ( m_p == p )
			{
				return false;
			}
			if ( 0 == m_p || 0 == p )
			{
				return true;
			}
			return *m_p != *p;
		}

		/** Compares internal pointer */
		bool operator!=( const Iterator& it ) const
		{
			return operator!=( it.m_p );
		}

		/** Compares internal pointer* */
		bool operator==( T* p ) const
		{
			if ( m_p == p )
			{
				return true;
			}
			if ( 0 == m_p || 0 == p )
			{
				return false;
			}
			return *m_p == *p;
		}

		/** Compares internal pointer */
		bool operator==( const Iterator& it ) const
		{
			return operator==( it.m_p );
		}

		/** So Iterator behaves like a STL iterator */
		T* operator->() const
		{
			return m_p;
		}

		/** So Iterator behaves like a STL iterator */
		T& operator*() const
		{
			return *m_p;
		}
	};

	/** Implementation of Node wrapper */
	template < class T >
		class NodeImp : public Node
	{
	protected:

		T* m_tiXmlPointer;		/**< Internal pointer to the TiXml Class which is being wrapped */

		/**
		@internal
		Gets the internal TinyXML pointer.

		@returns The internal TiXmlNode*.
		*/
		TiXmlNode* GetTiXmlPointer() const
		{
			ValidatePointer();
			return m_tiXmlPointer;
		}

		/**
		@internal
		Sets the internal pointer.
		Saves a copy of the pointer to the RC object.

		@param newPointer TiXmlNode* to set.
		*/
		void SetTiXmlPointer( T* newPointer )
		{
			m_tiXmlPointer = newPointer;
			SetImpRC( newPointer );
		}

		/**
		@internal
		Constructor used by child classes.
		*/
		NodeImp( T* tiXmlPointer )
		{
			// Check for NULL pointers
			if ( 0 == tiXmlPointer )
			{
				#ifdef TICPP_NO_RTTI
					TICPPTHROW( "Can not create TinyXML objext" );
				#else
					TICPPTHROW( "Can not create a " << typeid( T ).name() );
				#endif
			}
			SetTiXmlPointer( tiXmlPointer );
			m_impRC->IncRef();
		}

		/**
		@internal
		Updates the reference count for the old and new pointers.
		In addition, the spawnedWrappers must be cleared out before a new TiXml object is loaded in.
		*/
		virtual void operator=( const NodeImp<T>& copy )
		{
			// Dropping the reference to the old object
			this->m_impRC->DecRef();

			// Pointing to the new Object
			SetTiXmlPointer( copy.m_tiXmlPointer );

			// The internal tixml pointer changed in the above line
			this->m_impRC->IncRef();
		}

		/**
		@internal
		Updates the reference count for the old and new pointers.
		In addition, the spawnedWrappers must be cleared out before a new TiXml object is loaded in
		*/
		NodeImp( const NodeImp<T>& copy ) : Node( copy )
		{
			// Pointing to the new Object
			SetTiXmlPointer( copy.m_tiXmlPointer );

			// The internal tixml pointer changed in the above line
			this->m_impRC->IncRef();
		}

	public:

		/*
		Deletes the spawned wrapper objects.
		Decrements reference count.
		*/
		virtual ~NodeImp()
		{
			m_impRC->DecRef();
		}
	};

	/** Wrapper around TiXmlComment */
	class TICPP_API Comment : public NodeImp< TiXmlComment >
	{
	public:

		/**
		Constructor.
		*/
		Comment();

		/**
		Constructor.
		*/
		Comment( TiXmlComment* comment );

		/**
		Constructor.
		*/
		Comment( const std::string& comment );
	};

	/** Wrapper around TiXmlText */
	class TICPP_API Text : public NodeImp< TiXmlText >
	{
	public:

		/**
		Constructor.
		*/
		Text();

		/**
		Constructor.
		@overload
		*/
		Text( TiXmlText* text );

		/**
		Constructor.
		@overload
		*/
		Text( const std::string& value );

		/**
		Streams value into a string and creates a Text with it.
		Uses ToString to covert the parameter to a string.

		@param value The value of the Text node.
		@throws Exception

		@see TiXmlText
        */
		template < class T >
			Text( const T& value )
				: NodeImp< TiXmlText >( new TiXmlText( ToString( value ) ) )
		{
			m_impRC->InitRef();
		}
	};

	/** Wrapper around TiXmlDocument */
	class TICPP_API Document : public NodeImp< TiXmlDocument >
	{
	public:
		/**
		Default	Constructor.
		Create an empty document, that has no name.
		*/
		Document();

		/**
		Constructor.
		*/
		Document( TiXmlDocument* document );

		/**
		Constructor.
		*/
		Document( const char* documentName );

		/**
		 * Constructor.
		 * Create a document with a name. The name of the document is also the filename of the xml.
		 * @param documentName Name to set in the Document.
		 * @note LoadFile() needs to be called to actually load the data from the file specified by documentName
		 * 		 SaveFile() needs to be called to save data to file specified by documentName.
		 */
		Document( const std::string& documentName );

		/**
		Load a file using the current document value. Throws if load is unsuccessful.

		@param encoding Sets the documents encoding.
		@see TiXmlEncoding
		@throws Exception
		*/
		void LoadFile( TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );

		/**
		Save a file using the current document value. Throws if it can't save the file.

		@throws Exception
		*/
		void SaveFile() const;

		/**
		Load a file using the given filename. Throws if load is unsuccessful.

		@param filename File to load.
		@param encoding Sets the documents encoding.
		@see TiXmlEncoding
		@throws Exception
		*/
		void LoadFile( const std::string& filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );

		/**
		@copydoc Document::LoadFile( const std::string&, TiXmlEncoding )
		*/
		void LoadFile( const char* filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );

		/**
		Save a file using the given filename. Throws if it can't save the file.

		@param filename File to save.
		@throws Exception
		*/
		void SaveFile( const std::string& filename ) const;

		/**
		Parse the given xml data.

		@param xml Xml to parse.
		@param throwIfParseError [DEF] If true, throws when there is a parse error.
		@param encoding Sets the documents encoding.
		@throws Exception
		*/
		void Parse( const std::string& xml, bool throwIfParseError = true, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
	};

	/** Wrapper around TiXmlElement */
	class TICPP_API Element : public NodeImp< TiXmlElement >
	{
	public:
		/**
		Default Constructor.
		*/
		Element();

		/**
		Default	Constructor. Initializes all the variables.
		@param value The value of the element.
		*/
		Element( const std::string& value );

		/**
		Default	Constructor. Initializes all the variables.
		@param value The value of the element.
		*/
		Element( const char* value );

		/**
		Constructor.
		*/
		Element( TiXmlElement* element );

		/**
		Constructor that allows you to set the element text
		@param value The value of the element.
		@param text The text to set.
		*/
		template < class T >
			Element( const std::string& value, const T& text )
			: NodeImp< TiXmlElement >( new TiXmlElement( value ) )
		{
			m_impRC->InitRef();
			SetText( text );
		}

		/**
		Access the first attribute in this element.

		@param throwIfNoAttributes [DEF] If true, throws when there are no attributes
		@return The first attribute, NULL if there are none and @a throwIfNoAttributes is true
		*/
		Attribute* FirstAttribute( bool throwIfNoAttributes = true ) const;

		/**
		Access the last attribute in this element.

		@param throwIfNoAttributes [DEF] If true, throws when there are no attributes
		@return The last attribute, NULL if there are none and @a throwIfNoAttributes is true
		*/
		Attribute* LastAttribute( bool throwIfNoAttributes = 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
		*/
		void IterateFirst( const std::string&, Attribute** first ) const
		{
			*first = 0;
			for( Attribute* child = FirstAttribute( false ); child; child = child->Next( false ) )
			{
				*first = dynamic_cast< Attribute* >( child );
				if ( 0 != *first )
				{
					return;
				}
			}
		}

		/**
		Sets an attribute of name to a given value.
		The attribute will be created if it does not exist, or changed if it does.
		Uses ToString to convert the @a value to a string, so there is no need to use any other SetAttribute methods.

		@see GetAttribute
		*/
		template < class T >
			void SetAttribute ( const std::string& name, const T& value )
		{
			ValidatePointer();
			m_tiXmlPointer->SetAttribute( name, ToString( value ) );
		}

		/**
		Gets the text of an Element.

		@param throwIfNotFound	[DEF]	If true, will throw an exception if there is no text in this element
		@note This only works if the Text is the FirstChild node
		@throws Exception When there is no text and throwIfNotFound is true

		@see GetText( T* value, bool throwIfNotFound = false )
		@see GetTextOrDefault
		@see GetTextOrDefault( T* value, const DefaultT& defaultValue )
		@see TiXmlElement::GetText
		*/
		std::string GetText( bool throwIfNotFound = true ) const
		{
			// Get the element's text value as a std::string
			std::string temp;
			if ( !GetTextImp( &temp ) )
			{
				if ( throwIfNotFound )
				{
					TICPPTHROW( "Text does not exists in the current element" );
				}
			}

			return temp;
		}

		/**
		Gets the text of an Element, if it doesn't exist it will return the defaultValue.

		@param defaultValue			What to put in 'value' if there is no text in this element
		@note This only works if the Text is the FirstChild node

		@see GetText
		@see GetText( T* value, bool throwIfNotFound = false )
		@see GetTextOrDefault( T* value, const DefaultT& defaultValue )
		@see TiXmlElement::GetText
		*/
		std::string GetTextOrDefault( const std::string& defaultValue ) const
		{
			// Get the element's text value as a std::string
			std::string temp;
			if ( !GetTextImp( &temp ) )
			{
				return defaultValue;
			}

			return temp;
		}

		/**
		Gets the text value of an Element, if it doesn't exist it will return the defaultValue.
		Uses FromString to convert the string to the type of choice

		@param value		[OUT]	The container for the returned value
		@param defaultValue			What to put in 'value' if there is no text in this element
		@note This is different than GetText() in that it will covert the text to what ever type you want.
		@note This only works if the Text is the FirstChild node

		@see GetText
		@see GetText( T* value, bool throwIfNotFound = false )
		@see GetTextOrDefault( const std::string& defaultValue )
		@see TiXmlElement::GetText
		*/
		template < class T, class DefaultT >
			void GetTextOrDefault( T* value, const DefaultT& defaultValue ) const
		{
			// Get the element's text value as a std::string
			std::string temp;
			if ( !GetTextImp( &temp ) )
			{
				// The text value does not exist - set value to the default
				*value = defaultValue;
				return;
			}

			// Stream the value from the string to T
			FromString( temp, value );
		}

		/**
		Gets the text of an Element.
		Uses FromString to convert the string to the type of choice.

		@param value			[OUT]	The container for the returned value
		@param throwIfNotFound	[DEF]	If true, will throw an exception if there is no text in this element
		@note This is different than GetText() in that it will covert the text to what ever type you want
		@note This only works if the Text is the FirstChild node
		@throws Exception When there is no text and throwIfNotFound is true

		@see GetText
		@see GetTextOrDefault
		@see GetTextOrDefault( T* value, const DefaultT& defaultValue )
		@see TiXmlElement::GetText
		*/
		template< class T >
			void GetText( T* value, bool throwIfNotFound = true ) const
		{
			// Get the element's text value as a std::string
			std::string temp;
			if ( !GetTextImp( &temp ) )
			{
				if ( throwIfNotFound )
				{
					TICPPTHROW( "Text does not exists in the current element" );
				}
				else
				{
					return;
				}
			}

			// Stream the value from the string to T
			FromString( temp, value );
		}

		/**
		Convenience function to set the text of an element.
		Creates a Text node and inserts it as the first child.
		Uses ToString to convert the parameter to a string.

		@param value The text to set.
		*/
		template < class T >
			void SetText( const T& value )
		{
			ValidatePointer();
			std::string temp = ToString( value );

			if ( m_tiXmlPointer->NoChildren() )
			{
				m_tiXmlPointer->LinkEndChild( new TiXmlText( temp ) );
			}
			else
			{
				if ( 0 == m_tiXmlPointer->GetText() )
				{
					m_tiXmlPointer->InsertBeforeChild( m_tiXmlPointer->FirstChild(), TiXmlText( temp ) );
				}
				else
				{
					// There already is text, so change it
					m_tiXmlPointer->FirstChild()->SetValue( temp );
				}
			}
		}

		/**
		Gets an attribute of @a name from an element, if it doesn't exist it will return the defaultValue.
		Uses FromString to convert the string to the type of choice.

		@param name			The name of the attribute you are querying.
		@param value		[OUT] The container for the returned value.
		@param defaultValue	What to put in @a value if there is no attribute in this element.
		@throws Exception

		@see GetAttribute
		*/
		template < class T, class DefaulT >
			void GetAttributeOrDefault( const std::string& name, T* value, const DefaulT& defaultValue ) const
		{
			// Get the attribute's value as a std::string
			std::string temp;
			if ( !GetAttributeImp( name, &temp ) )
			{
				// The attribute does not exist - set value to the default
				*value = defaultValue;
				return;
			}

			// Stream the value from the string to T
			FromString( temp, value );
		}

		/**
		Gets an attribute of @a name from an element, if it doesn't exist it will return the defaultValue.

		@param name			The name of the attribute you are querying.
		@param defaultValue	What to put in @a value if there is no attribute in this element.

		@see GetAttribute
		*/
		std::string GetAttributeOrDefault( const std::string& name, const std::string& defaultValue ) const;

		/**
		Returns an attribute of @a name from an element.
		Uses FromString to convert the string to the type of choice.

		@param name				The name of the attribute you are querying.
		@param throwIfNotFound	[DEF]	If true, will throw an exception if the attribute doesn't exist
		@throws Exception When the attribute doesn't exist and throwIfNotFound is true
		@see GetAttributeOrDefault
		*/
		template < class T >
			T GetAttribute( const std::string& name, bool throwIfNotFound = true ) const
		{
			// Get the attribute's value as a std::string
			std::string temp;
			T value;
			if ( !GetAttributeImp( name, &temp ) )
			{
				if ( throwIfNotFound )
				{
					const std::string error( std::string( "Attribute '" ) + name + std::string( "' does not exist" ) );
					TICPPTHROW( error );
				}
			}
			else
			{
				// Stream the value from the string to T
				FromString( temp, &value );
			}

			return value;
		}

		/**
		Gets an attribute of @a name from an element.
		Uses FromString to convert the string to the type of choice.

		@param name				The name of the attribute you are querying.
		@param value			[OUT]	The container for the returned value
		@param throwIfNotFound	[DEF]	If true, will throw an exception if the attribute doesn't exist
		@throws Exception When the attribute doesn't exist and throwIfNotFound is true

		@see GetAttributeOrDefault
		*/
		template< class T >
			void GetAttribute( const std::string& name, T* value, bool throwIfNotFound = true ) const
		{
			// Get the attribute's value as a std::string
			std::string temp;
			if ( !GetAttributeImp( name, &temp ) )
			{
				if ( throwIfNotFound )
				{
					const std::string error( std::string( "Attribute '" ) + name + std::string( "' does not exist" ) );
					TICPPTHROW( error );
				}
				else
				{
					return;
				}
			}

			// Stream the value from the string to T
			FromString( temp, value );
		}

		/**
		Gets an attribute of @a name from an element.
		Returns an empty string if the attribute does not exist.

		@param name	The name of the attribute you are querying.
		@return The value of the attribute, or an empty string if it does not exist.

		@see GetAttributeOrDefault
		*/
		std::string GetAttribute( const std::string& name ) const;

		/**
		Returns true, if attribute exists

		@param name The name of the attribute you are checking.
		@return Existence of attribute
		*/
		bool HasAttribute( const std::string& name ) const;

		/**
		Removes attribute from element.

		@param name The name of the attribute to remove.
		*/
		void RemoveAttribute( const std::string& name );

	private:

		/**
		@internal
		Implimentation of the GetAttribute and GetAttributeOrDefault template methods.
		*/
		bool GetAttributeImp( const std::string& name, std::string* value ) const;

		/**
		@internal
		Implimentation of the GetText, GetTextOrDefault, GetTextValue, and GetTextValueOrDefault template methods.
		*/
		bool GetTextImp( std::string* value ) const;
	};

	/** Wrapper around TiXmlDeclaration */
	class TICPP_API Declaration : public NodeImp< TiXmlDeclaration >
	{
	public:
		/**
		Default	Constructor. Construct an empty declaration.
		*/
		Declaration();

		/**
		Constructor.
		*/
		Declaration( TiXmlDeclaration* declaration );

		/**
		Constructor.
		*/
		Declaration( const std::string& version, const std::string& encoding, const std::string& standalone );

		/**
		Version. Will return an empty string if none was found.
		*/
		std::string Version() const;

		/**
		Encoding. Will return an empty string if none was found.
		*/
		std::string Encoding() const;

		/**
		StandAlone. Is this a standalone document?
		*/
		std::string Standalone() const;
	};

	/** Wrapper around TiXmlStylesheetReference */
	class TICPP_API StylesheetReference : public NodeImp< TiXmlStylesheetReference >
	{
	public:
		/**
		Default	Constructor. Construct an empty declaration.
		*/
		StylesheetReference();

		/**
		Constructor.
		*/
		StylesheetReference( TiXmlStylesheetReference* stylesheetReference );

		/**
		Constructor.
		*/
		StylesheetReference( const std::string& type, const std::string& href );

		/**
		Type. Will return an empty string if none was found.
		*/
		std::string Type() const;

		/**
		Href. Will return an empty string if none was found.
		*/
		std::string Href() const;
	};
}

#endif	// TICPP_INCLUDED