This file is indexed.

/usr/include/BALL/CONCEPT/composite.h is in libball1.4-dev 1.4.1+20111206-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   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
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//

#ifndef BALL_CONCEPT_COMPOSITE_H
#define BALL_CONCEPT_COMPOSITE_H

#ifndef BALL_COMMON_H
#	include <BALL/common.h>
#endif

#ifndef BALL_CONCEPT_PERSISTENTOBJECT_H
#	include <BALL/CONCEPT/persistentObject.h>
#endif

#ifndef BALL_CONCEPT_COMPARATOR_H
#	include <BALL/CONCEPT/comparator.h>
#endif

#ifndef BALL_CONCEPT_BIDIRECTIONALITERATOR_H
#	include <BALL/CONCEPT/bidirectionalIterator.h>
#endif

#ifndef BALL_CONCEPT_OBJECT_H
#	include <BALL/CONCEPT/object.h>
#endif

#ifndef BALL_CONCEPT_SELECTABLE_H
#	include <BALL/CONCEPT/selectable.h>
#endif

#ifndef BALL_CONCEPT_VISITOR_H
#	include <BALL/CONCEPT/visitor.h>
#endif

#ifndef BALL_CONCEPT_PROCESSOR_H
#	include <BALL/CONCEPT/processor.h>
#endif

#ifndef BALL_CONCEPT_TIMESTAMP_H
#	include <BALL/CONCEPT/timeStamp.h>
#endif

///
namespace BALL 
{
	/**	Composite Class.
			This class implements a variant of the composite design pattern. A
			Composite may contain an arbitrary number of other composites, thus
			forming a tree. All BALL kernel classes are derived from Composite.
			This provides a unique interface for all kernel classes.
			 \par
			The composite class provides a selection mechanism that allows
			hierarchical selection and deselection of arbitrary subtrees. The
			time of the last selection/deselection operation is stored as well as
			the time of the last modification operation in time stamps that can
			be accessed via  \link getModificationTime getModificationTime \endlink  
			and  \link getSelectionTime getSelectionTime \endlink .
			Selecting or deselecting a Composite automatically selects or
			deselects all its children (recursively!).  Selecting or deselecting
			all children of a node deselects their parent as well.	Selection
			information is propagated upwards in the tree.
			 \par
			Composites are persistent objects. 
			 \par
			
			\ingroup ConceptsMiscellaneous 
	*/
	class BALL_EXPORT Composite
		: public PersistentObject,
			public Selectable
	{
		public:

		/**	@name	Type Definitions and Enums
		*/
		//@{

#ifndef BALL_KERNEL_PREDICATE_TYPE
#define BALL_KERNEL_PREDICATE_TYPE
		/**	Composite predicate type.
				This type declares a predicate operating on composites.
				As it is used as a predicate for all kernel classes,
				it is named KernelPredicateType.
		*/
		typedef	UnaryPredicate<Composite>	KernelPredicateType;
#endif

		/**	Time stamp type.
		*/
		enum StampType
		{
			/**	
			*/
			MODIFICATION = 1,
			/**
			*/
			SELECTION = 2,
			/**	
			*/
			BOTH = 3
		};
		//@}
				
		BALL_CREATE_DEEP(Composite)

		static UnaryProcessor<Composite> DEFAULT_PROCESSOR;
		static KernelPredicateType DEFAULT_UNARY_PREDICATE;
		
		/**	@name	Construction and Destruction 
		*/
		//@{
		
		/**	Default constructor.
				This constructor creates an empty composite object.
		*/
		Composite()
			;

		/**	Copy constructor.
				Creates a copy of a composite. <b>  Deep </b> copies include the whole
				composite tree, <b>  shallow </b> copies contain anly a single composite.
				@param	composite the composite to be cloned (the root of the tree in 
								the case of a deep copy)
				@param	deep make a deep copy (<b>true</b>) or shallow copy 
								(<b>false</b>)
		*/
		Composite(const Composite& composite, bool deep = true)
			;

		/**	Destructor.	
				The destructor calls  \link destroy destroy \endlink  to remove the composite from 
				potential tree structures. It also recursively destructs all
				children of the composite.
		*/
		virtual ~Composite() 
			;

		/**	Clear the composite properties.	
				This method removes the composite's children and destructs them if
				they are auto-deletable.
				 \par
				It does not remove the composite from any parental structure.
				 \par
				This  method updates the modification time stamp of <tt>this</tt>.
				@see	stamp
				@see	AutoDeletable
				@see	destroy
		*/
		virtual void clear()
			;
	
		/**	Destroy the composite.
				This method removes the composite from potential parental
				structures and then calls  \link clear clear \endlink  to destruct all children.
				 \par
				This  method updates the modification time stamp of <tt>this</tt>.
				@see stamp
				@see	~Composite
				@see	clear
		*/
		virtual void destroy()
			;

		/**	Non-virtual destroy method.
				This method behaves exactly like destroy except for a small
				difference: when called with <b>true</b>, it calls the <b>  virtual </b>
				clear function. If called with <b>false</b> it calls the original
				clear function of Composite. This is useful when implementing the
				behaviour of derived classes.
				 \par
				This  method updates the modification time stamp of <tt>this</tt>.
				@see stamp
				@param	virtual_destroy call the virtual clear method (<b>true</b>) or
								<tt>Composite::clear()</tt> (<b>false</b>)
		*/		
		void destroy(bool virtual_destroy)
			;

		/**	Clone with a predicate.
				This method copies the attributes of <tt>this</tt> composite to root
				(shallow copy) and then adds recursively each of its children.
				@param	root the cloning target root is <tt>destroy</tt>ed prior to
								any copying 
				@return  a pointer to the root composite (<tt>&root</tt>)
		*/
		void* clone(Composite& root) const
			;

		//@}		

		/**	@name	Persistence 
		*/
		//@{
		
		/** Write a persistent copy of the object.
				@param	pm the persistence manager
				@param	name the object name
				\throws Exception::GeneralException
		*/
		virtual void persistentWrite(PersistenceManager& pm, const char* name = 0) const;

		/** Read a persistent object.
				@param	pm the persistence manager
				\throws Exception::GeneralException
		*/
		virtual void persistentRead(PersistenceManager& pm);

		//@}

		/**	@name	Modifying and Accessing the Tree 
		*/
		//@{

		/**	Assignment.
				@param	composite the Composite tree to assign from
				@param	deep a <tt>bool</tt> deciding whether the assignment will be
								deep or shallow.
		*/
		void set(const Composite& composite, bool deep = true) ;

		/**	Assignment operator.
				@param	composite the Composite tree to assign from
				@return	a const reference to <b>this</b>
		*/
		Composite& operator = (const Composite& composite) ;

		/**	Assignment of a tree to another.
				Create a deep (<tt>deep</tt> = <b>true</b>) or shallow copy of a composite
				and assign it to <tt>composite</tt>. <tt>composite</tt> is destroyed first.
				@param	composite the composite to assign the copy to
				@param	deep <b>true</b> for a deep copy
		*/
		void get(Composite& composite, bool deep = true) const ;

		/**	Return the degree of the node.
				This method returns the number of children of a composite object.
				@return Size the number of children
		*/
		Size getDegree() const ;

		/**	Count the number of nodes fulfilling a predicate in this subtree.
				@param	predicate the predicate
				@return Size the number of nodes in the subtree satisfying the predicate
		*/
		Size count(const KernelPredicateType& predicate) const ;

		/**	Count the number of descendants.
				@return Size the number of descendants of this node
		*/
		Size countDescendants() const ;

		/** Get the length of the path between two composite objects.
				If no path exists <tt>INVALID_SIZE</tt> is returned.
				@param composite the second object
				@return Size the size of the path
		*/
		Size getPathLength(const Composite& composite) const ;

		/** Get the depth of this item in its tree.
				The depth of a root item is 0.
				@return Size the depth
		*/
		Size getDepth() const ;

		/** Get the height of this item in its tree.
				The hight of a leaf is 0.
				@return Size the height
		*/
		Size getHeight() const
			;

		/** Get the root of this item.
				@return Composite& the root
		*/
		Composite& getRoot() ;

		/** Get a const reference to the root of this item.
				@return Composite& the root
		*/
		const Composite& getRoot() const ;

		/** Get the lowest common ancestor of this item with an other.
				If no common ancestor exists 0 is returned.
				@return Composite& the lowest common ancestor
		*/
		Composite* getLowestCommonAncestor(const Composite& composite)
			;

		/** Get a const reference to the lowest common ancestor of this item
				with an other. If no common ancestor exists, 0 is returned.
				@return Composite& the lowest common ancestor
		*/
		const Composite* getLowestCommonAncestor(const Composite& composite) const
			;

		/**	Find the first ancestor of type T.
				This method walks up the tree from parent to parent and
				checks whether the composite object is a kind of <tt>T</tt>.
				This method is useful to identify special container classes.
				@return a pointer to the first composite found that is a kind of T
								or 0 if no matching composite was found up to the root of
								the tree
		*/
		template <typename T>
		T* getAncestor(const T& /* dummy */)
			;

		/**	Find the first ancestor of type T (const method).
				This method operates also on constant trees.
				@return a pointer to the first composite found that is a kind of T
								or 0 if no matching composite was found to the root of the
								tree
		*/
		template <typename T>
		const T* getAncestor(const T& /* dummy */) const ;

		/**	Find the nearest previous composite of type T.
				This method walks backward in the tree from composite to composite and
				checks whether the composite object is a kind of <tt>T</tt>.
				@return a pointer to the first composite found that is a kind of T
								or 0 if no matching composite was found up to the root of
								the tree
		*/
		template <typename T>
		T* getPrevious(const T& /* dummy */) ;

		/**	Find the nearest previous composite of type T (const method).
				This method walks backward in the tree from composite to composite and
				checks whether the composite object is a kind of <tt>T</tt>.
				@return a pointer to the first composite found that is a kind of T
								or 0 if no matching composite was found up to the root of
								the tree
		*/
		template <typename T>
		const T* getPrevious(const T& dummy) const ;

		/**	Find the next composite of type T.
				This method walks backward in the tree from composite to composite and
				checks whether the composite object is a kind of <tt>T</tt>.
				@return a pointer to the first composite found that is a kind of T
								or 0 if no matching composite was found up to the root of
								the tree
		*/
		template <typename T>
		T* getNext(const T& /* dummy */) ;

		/**	Find the next composite of type T (const method).
				This method walks backward in the tree from composite to composite and
				checks whether the composite object is a kind of <tt>T</tt>.
				@return a pointer to the first composite found that is a kind of T
								or 0 if no matching composite was found up to the root of
								the tree
		*/
		template <typename T>
		const T* getNext(const T& dummy) const ;

		/**	Return the composite's parent.
				@return a pointer to the parent composite or 0 if no parent exists
		*/
		Composite* getParent() ;

		/**	Return the composite's parent (const method).
				@return a pointer to the parent composite or 0 if no parent exists
		*/
		const Composite* getParent() const ;

		/**	Return the <b>  index </b>th child of this composite.
				If no such child exists, 0 is returned.
				The index of the first child is <b>0</b>.
				@param	index the index of the child to return
				@return	a pointer to the child or 0 if there is no such child.
		*/
		Composite* getChild(Index index) ;
	
		/**	Return a const pointer to the <b>  index </b>th child of this composite.
				If no such child exists, 0 is returned.
				The index of the first child is <b>0</b>.
				@param	index the index of the child to return
				@return	a const pointer to the child or 0 if there is no such child.
		*/
		const Composite* getChild(Index index) const ;
	
		/**	Return a pointer to the sibling index positions from this composite.
				A pointer to the sibling <tt>index</tt> positions to the right (for
				positive values of <tt>index</tt>) or <tt>-index</tt> positions to the left 
				(for negative values of <tt>index</tt>) is returned.
				For Index = 0 the this-pointer is returned.
				@param index the index of the sibling
				@return	a pointer to the child or 0 if there is no such sibling.
		*/
		Composite* getSibling(Index index) ;

		/**	Return a const pointer to the sibling index positions from this composite.
				A pointer to the sibling <tt>index</tt> positions to the right (for
				positive values of <tt>index</tt>) or <tt>-index</tt> positions to the left 
				(for negative values of <tt>index</tt>) is returned.
				For Index = 0 the this-pointer is returned.
				@param index the index of the sibling
				@return	a const pointer to the child or 0 if there is no such sibling.
		*/
		const Composite* getSibling(Index index) const ;

		/**	Return a pointer to the first child.
				@return a pointer to the first child or 0 if there is no child.
		*/
		Composite* getFirstChild() ;

		/**	Return a const pointer to the first child.
				@return a const pointer to the first child or 0 if there is no child.
		*/
		const Composite* getFirstChild() const ;

		/**	Return a pointer to the last child.
				@return a  pointer to the last child or 0 if there is no child.
		*/
		Composite* getLastChild() ;

		/**	Return a const pointer to the last child.
				@return a const pointer to the last child or 0 if there is no child.
		*/
		const Composite* getLastChild() const ;
			
		/**	Return the time of last modification
				@return the last modification time
		*/
		const PreciseTime& getModificationTime() const ;

		/**	Return the time of last change of selection.
				@return the last time of change of selection
		*/
		const PreciseTime& getSelectionTime() const ;

		/**	Modify a time stamp.
				Update one or both of the two time stamps with the
				current time. The time stamp is then propagated up to the
				root of the composite tree. Each composite contains two stamps. 
				the <em>modification stamp</em> is updated each time the tree structure
				changes, while the <em>selection stamp</em> is updated each time the
				selection status changes.
				@param stamp the time stamp type 
		*/
		void stamp(StampType stamp = BOTH) ;
			
		/**	Insert a composite as the first child of this composite.
				Updates the modification time stamp.
				@see stamp
				@param	composite the composite to be inserted
		*/
		void prependChild(Composite& composite) ;

		/**	Insert a composite as the last child of this composite.
				Updates the modification time stamp. <b>Note</b> that this method
				alters the composite tree from which <tt>composite</tt> is taken,
				if there is such a tree.
				@see stamp
				@param	composite the composite to be inserted
		*/
		void appendChild(Composite& composite) ;

		/**	Insert a new parent node.
				This method is used to combine a range of nodes into a single
				parent. First, the <tt>parent</tt> composite is <tt>destroy</tt>ed.
				Then, all nodes from <tt>first</tt> through <tt>last</tt> are inserted
				into <tt>parent</tt> and <tt>parent</tt> is inserted in the former
				position of <tt>first</tt>. The method returns <b>false</b>, if {\tt
				first} or <tt>last</tt> have differing parents, if <tt>parent</tt> is
				identical with either <tt>first</tt> or <tt>last</tt>, or if <tt>first</tt>
				is already a descendant of <tt>parent</tt>.  
				 \par
				This method updates the modification time stamp.
				@see stamp
				@param	parent the new parent of the nodes from <tt>first</tt> through
								<tt>last</tt>
				@param	first the first of the nodes to be inserted into <tt>parent</tt>
				@param	last the last of the nodes to be inserted into <tt>parent</tt>
				@param	destroy_parent keeps the current contents of <tt>parent</tt>
								if set to <tt>true</tt>
		*/
		static bool insertParent(Composite& parent, Composite& first,  
														 Composite& last, bool destroy_parent = true)
			;

		/**	Insert a node before this node.
				This method inserts <tt>composite</tt> before <tt>this</tt> node, if
				<tt>this</tt> node has a parent and is not a descendant of <tt>composite</tt>.
				Self-insertion is recognized and ignored (nothing is done).
				 \par
				This method updates the modification time stamp.
				@see stamp
				@param	composite the node to be inserted in the tree before <tt>this</tt>
		*/
		void insertBefore(Composite& composite) ;

		/**	Insert a node after this node.
				This method inserts <tt>composite</tt> after <tt>this</tt> node, if 
				<tt>this</tt> node has a parent and is not a descendant of <tt>composite</tt>.
				Self-insertion is recognized and ignored (nothing is done).
				 \par
				This method updates the modification time stamp.
				@see stamp
				@param	composite the node to be inserted in the tree after of <tt>this</tt>
		*/
		void insertAfter(Composite& composite) ;

		/**	Prepend all children of <tt>composite</tt> to the children of this
				composite.  The method does nothing, if <tt>composite</tt> is
				identical to <tt>this</tt> or is a descendent of <tt>this</tt>.
				 \par
				This method updates the modification time stamp.
				@see stamp
				@param the composite to be spliced
		*/
		void spliceBefore(Composite& composite) ;

		/**	Append all children of <tt>composite</tt> to the children of this
				composite.  The method does nothing, if <tt>composite</tt> is
				identical to <tt>this</tt> or is a descendent of <tt>this</tt>.
				 \par
				This method updates the modification time stamp.
				@see stamp
				@param composite the composite to be spliced
		*/
		void spliceAfter(Composite& composite) ;

		/**	Insert the children of composite into this composite.
				The children of <tt>composite</tt> are inserted at the position of 
				<tt>composite</tt> if <tt>composite</tt> is a child of <tt>this</tt>.
				Otherwise the children are inserted using  \link spliceBefore spliceBefore \endlink .
				 \par
				This method updates the modification time stamp.
				@see stamp
				@param composite the composite to be spliced
		*/
		void splice(Composite& composite) ;

		/**	Remove a child from its parent.
				<tt>child</tt> is only removed, if it is a true child of <tt>this</tt>.
				 \par
				This method updates the modification time stamp of <tt>this</tt>.
				@see stamp
				@param child the child to remove
				@return false if child could not be removed
		*/
		bool removeChild(Composite& child) ;


		/**	Remove selected subcomposites.
				This method iterates over all children of the current composite
				and removes all selected composites by <tt>delete</tt>ing them.
				If the respective Composite are not \link AutoDeletable \endlink,
				they are just \link remove\endlink d from the hierarchy, but not
				deleted.

				This method is useful in combination with the \link Selector \endlink
				class in order to remove unwanted partitions of kernel data structures.

				@return the number of composites deleted.
		*/
		Size removeSelected() ;

		/** Remove unselected subcomposites.
		    This method iterates over all children of the current composite
		    and removes all unselected composites by <tt>delete</tt>ing them.
		    If the respective Composite are not \link AutoDeletable \endlink,
		    they are just \link remove\endlink d from the hierarchy, but not
		    deleted.

		    This method is useful in combination with the \link Selector \endlink
		    class in order to remove unwanted partitions of kernel data structures.

		    @return the number of composites deleted.
		*/
		Size removeUnselected();

		/** This instance and its subtree is removed form its tree and 
				replaced by <tt>composite</tt> and its subtree.
				 \par
				This method updates the modification time stamp of 
				<tt>this</tt> and <tt>composite</tt>.
				@see stamp
				@param	composite the composite which will be inserted
		*/
		void replace(Composite& composite) ;

		/**	Swap the contents of two composites.
				 \par
				This  method updates the modification time stamp of <tt>this</tt> and
				<tt>composite</tt>.
				@see stamp
				@param	composite the composite with which the contents will be
								swapped
		*/
		void swap(Composite& composite) ;

		/**	Select a composite.
				This method selects the composite and all the composites therein.
				 \par
				If the state of this composite is modified, its selection time
				stamp is updated and that of its ancestors (up to and including the
				root composite) as well. The time stamps of descendants that
				changed their selection state are update, too.
		*/	
		virtual void select() ;

		/**	Deselect a composite.
				This method deselects the composite and all the composites therein.
				 \par
				If the state of this composite is modified, its selection time
				stamp is updated and that of its ancestors (up to and including the
				root composite) as well. The time stamps of descendants that
				changed their selection state are update, too.
		*/	
		virtual void deselect() ;
		//@}

		/**	@name	Predicates */
		//@{

		/**	Equality operator.
				Compares the handles of two Composite objects, therefore two
				Composite objects can never be equal.
				@see Object::operator ==
				@param	composite the composite against which equality will be tested
		*/
		bool operator == (const Composite& composite) const ;

		/**	Inequality operator.
				@see operator ==
B		*/
		bool operator != (const Composite& composite) const
			;

		/**	Return true if the node does not contain children.
				@return bool <b>true</b> if <tt>number_of_children_ == 0</tt>
		*/
		bool isEmpty() const ;

		/**	Return true if the node has no parent.
				@return bool <b>true</b> if <tt>parent_ == 0</tt>
		*/
		bool isRoot() const ;
	
		/** Return true if the node is root of composite.
		*/
		bool isRootOf(const Composite& composite) const ;
	
		/** Return true if the node is not the root or a leaf.
		*/
		bool isInterior() const ;
	
		/** Return true if the node has a child.
		*/
		bool hasChild() const ;
	
		/** Return true if the node has the parent <tt>composite</tt>.
		*/
		bool isChildOf(const Composite& composite) const ;
	
		/** Return true if the node is the first child of its parent.
		*/
		bool isFirstChild() const ;
	
		/** Return true if the node is the first child of <tt>composite</tt>.
		*/
		bool isFirstChildOf(const Composite& composite) const ;
	
		/** Return true if the node is the last child of its parent.
		*/
		bool isLastChild() const ;
	
		/** Return true if the node is the last child of <tt>composite</tt>.
		*/
		bool isLastChildOf(const Composite& composite) const ;
	
		/** Return true if the node has a parent.
		*/
		bool hasParent() const ;

		/** Return true if the node is the parent of <tt>composite</tt>.
		*/
		bool isParentOf(const Composite& composite) const ;

		/** Return true if the node has a sibling.
				(Its parent has other childs.)
		*/
		bool hasSibling() const ;
			
		/** Return true if the node is a sibling of <tt>composite</tt>.
		*/
		bool isSiblingOf(const Composite& composite) const ;
			
		/** Return true if the node has a previous sibling.
				(Its parent has a child before this.)
		*/
		bool hasPreviousSibling() const ;
	
		/** Return true if the node is a previous sibling of <tt>composite</tt>.
		*/
		bool isPreviousSiblingOf(const Composite& composite) const ;
	
		/** Return true if the node has a previous sibling.
				(Its parent has a child after this.)
		*/
		bool hasNextSibling() const ;

		/** Return true if the node is a next sibling of <tt>composite</tt>.
		*/
		bool isNextSiblingOf(const Composite& composite) const ;
		
		/** Return true if the node is a descendent of <tt>composite</tt>.
		*/
		bool isDescendantOf(const Composite& composite) const ;

		/** Return true if the node has a ancestor of the same type as dummy.
		*/
		template <typename T>
		bool hasAncestor(const T& dummy) const	;

		/** Return true if the node has composite as descendent.
		*/
		bool isAncestorOf(const Composite& composite) const	;

		/** Return true if the node has composite as ancestor or
				composite is ancestor of this node.
		*/
		bool isRelatedWith(const Composite& composite) const ;
	
		/** Return true if composite is homomorph to this node.
				(The subtrees of the two instances have to be of the same form.)
		*/
		bool isHomomorph(const Composite& composite) const ;

		/**	Return true if any descendant is selected.
				This method does not check all nodes recursively. Instead, on each
				modification of the tree, internal flags are updated and the
				information is propagated upwards in the tree.
				 \par
				Complexity: O(1)
				 \par
				@return bool <b>true</b> if any node in the subtree is selected
		*/
		bool containsSelection() const ;
		//@}

		/**	@name	Debugging and Diagnostics */
		//@{
		/** Test if the subtree with this node as root is valid.
				(The structure of the subtree has to be valid.)
		*/
		virtual bool isValid() const ;

		/** Dump the constent of this instance to an ostream.
				@param	s the stream to which we will dump
				@param	depth the indentation depth of the output
		*/
		virtual void dump(std::ostream& s = std::cout, Size depth = 0) const
			;

		//@}
		/**	@name	Application and Hosting */
		//@{

		/**	Visitor host method.
				Composites may be visited.
				For an example look into Composite_test.C
				@param	visitor	the visitor
				\throws Exception::GeneralException
		*/
		void host(Visitor<Composite>& visitor);

		/** Apply a processor to all ancestors of this node.
				@return true if the processor could be applied.
				\throws Exception::GeneralException
		*/
		template <typename T>
		bool applyAncestor(UnaryProcessor<T>& processor);

		/** Apply a processor to all children of this node.
				@return true if the processor could be applied.
				\throws Exception::GeneralException
		*/
		template <typename T>
		bool applyChild(UnaryProcessor<T>& processor);
		
		/** Apply a processor to all descendents of this node.
				The node itself is not processed.
				The root of a subtree is accessed before the nodes in its left 
				and right subtree.
				@return true if the processor could be applied.
				\throws Exception::GeneralException
		*/
		template <typename T>
		bool applyDescendantPreorder(UnaryProcessor<T>& processor);

		/** Apply a processor to all descendents of this node.
				The node itself is not processed.
				The root of a subtree is accessed after the nodes in its left 
				and right subtree.
				@return true if the processor could be applied.
				\throws Exception::GeneralException
		*/
		template <typename T>
		bool applyDescendantPostorder(UnaryProcessor<T>& processor);
	
		/** Apply a processor to all descendents of this node.
				The node itself is not processed.
				applyDescendantPreorder is used.
				@see applyDescendantPreorder
				@return true if the processor could be applied.
				\throws Exception::GeneralException
		*/
		template <typename T>
		bool applyDescendant(UnaryProcessor<T>& processor);
		
		/** Apply a processor to the node and its subtree.
				The root of a subtree is accessed before the nodes in its left 
				and right subtree.
				@return true if the processor could be applied.
				\throws Exception::GeneralException
		*/
		template <typename T>
		bool applyPreorder(UnaryProcessor<T>& processor);
		
		/** Apply a processor to the node and its subtree.
				The root of a subtree is accessed after the nodes in its left 
				and right subtree.
				@return true if the processor could be applied.
				\throws Exception::GeneralException
		*/
		template <typename T>
		bool applyPostorder(UnaryProcessor<T>& processor);

		/** Apply a processor to the node and its subtree.
				applyPreorder is used.
				@see applyPreorder
				@return true if the processor could be applied.
				\throws Exception::GeneralException
		*/
		template <typename T>
		bool apply(UnaryProcessor<T>& processor);
		
		/** Apply a processor to the node and its siblings.
				@return true if the processor could be applied.
				\throws Exception::GeneralException
		*/
		template <typename T>
		bool applyLevel(UnaryProcessor<T>& processor, long level);
		//@}			


	
		class BALL_EXPORT AncestorIteratorTraits
		{
			public:

			BALL_INLINE
			AncestorIteratorTraits()
				
				:	bound_(0),
					ancestor_(0)
			{
			}
		
			BALL_INLINE
			AncestorIteratorTraits(const Composite& composite)
				
				:	bound_(const_cast<Composite*>(&composite)),
					ancestor_(0)
			{
			}
		
			BALL_INLINE
			AncestorIteratorTraits(const AncestorIteratorTraits& traits)
				
				:	bound_(traits.bound_),
					ancestor_(traits.ancestor_)
			{
			}
		
			BALL_INLINE
			const AncestorIteratorTraits& operator = (const AncestorIteratorTraits& traits)
				
			{
				bound_ = traits.bound_;
				ancestor_ = traits.ancestor_;
				return *this;
			}

			BALL_INLINE	Composite* getContainer()	 { return bound_; }

			BALL_INLINE	const Composite* getContainer() const	 { return bound_; }

			BALL_INLINE	bool isSingular() const		{	return (bound_ == 0);	}

			BALL_INLINE	Composite* getPosition()		{	return ancestor_;	}

			BALL_INLINE	Composite* const& getPosition() const	 {	return ancestor_;	}

			BALL_INLINE	bool operator == (const AncestorIteratorTraits& traits) const		{	return (ancestor_ == traits.ancestor_);	}
		
			BALL_INLINE	bool operator != (const AncestorIteratorTraits& traits) const		{	return !(ancestor_ == traits.ancestor_); }

			BALL_INLINE	bool isValid() const		{	return (bound_ != 0 && ancestor_ != 0);	}

			BALL_INLINE	void invalidate()		{	bound_ 	= ancestor_ = 0; }
			
			BALL_INLINE	void toBegin()		{	ancestor_ = bound_->parent_; }

			BALL_INLINE	bool isBegin() const  { return (ancestor_ == bound_->parent_); }

			BALL_INLINE void toEnd()  { ancestor_ = 0;	}

			BALL_INLINE	bool isEnd() const  { return (ancestor_ == 0); }

			BALL_INLINE Composite& getData()  { return *ancestor_;	}

			BALL_INLINE	const Composite& getData() const  { return *ancestor_; }

			BALL_INLINE void forward()  { ancestor_ = ancestor_->parent_; }

			private:

			Composite* bound_;
			Composite* ancestor_;
		};

		friend class AncestorIteratorTraits;

		typedef ForwardIterator <Composite, Composite, Composite*, AncestorIteratorTraits>
			AncestorIterator;

		AncestorIterator beginAncestor() 
		{
			return AncestorIterator::begin(*this);
		}

		AncestorIterator endAncestor() 
		{
			return AncestorIterator::end(*this);
		}

		typedef ConstForwardIterator<Composite, Composite, Composite*, AncestorIteratorTraits>
			AncestorConstIterator;

		AncestorConstIterator beginAncestor() const 
		{
			return AncestorConstIterator::begin(*this);
		}

		AncestorConstIterator endAncestor() const 
		{
			return AncestorConstIterator::end(*this);
		}

		class BALL_EXPORT ChildCompositeIteratorTraits
		{
			public:

			ChildCompositeIteratorTraits()
				
				:	bound_(0),
					child_(0)
			{
			}
			
			ChildCompositeIteratorTraits(const Composite& composite)
				
				:	bound_((Composite *)&composite),
					child_(0)
			{
			}
		
			ChildCompositeIteratorTraits(const ChildCompositeIteratorTraits& traits)
				
				:	bound_(traits.bound_),
					child_(traits.child_)
			{
			}
		
			const ChildCompositeIteratorTraits& operator = (const ChildCompositeIteratorTraits& traits)
				
			{
				bound_ = traits.bound_;
				child_ = traits.child_;
				return *this;
			}

			BALL_INLINE Composite* getContainer()	 {	return bound_; }

			BALL_INLINE const Composite* getContainer() const 	{	return bound_; }

			BALL_INLINE bool isSingular() const 	{ return (bound_ == 0);	}

			BALL_INLINE Composite* getPosition() 	{ return child_; }

			BALL_INLINE Composite* const& getPosition() const		{ return child_; }

			BALL_INLINE bool operator == (const ChildCompositeIteratorTraits& traits) const  { return (child_ == traits.child_); }
		
			BALL_INLINE bool operator != (const ChildCompositeIteratorTraits& traits) const  { return !(child_ == traits.child_); }
		
			BALL_INLINE bool isValid() const  { return (bound_ != 0 && child_ != 0); }

			BALL_INLINE void invalidate()  { bound_ = child_ = 0; }

			BALL_INLINE void toBegin()  { child_ = bound_->first_child_; }

			BALL_INLINE bool isBegin() const  { return (child_ == bound_->first_child_); }

			BALL_INLINE void toEnd()  { child_ = 0; }

			BALL_INLINE bool isEnd() const  { return (child_ == 0); }

			BALL_INLINE void toRBegin()  { child_ = bound_->last_child_; }

			BALL_INLINE bool isRBegin() const  { return (child_ == bound_->last_child_); }

			BALL_INLINE void toREnd()  { child_ = 0; }

			BALL_INLINE bool isREnd() const  { return (child_ == 0); }

			BALL_INLINE Composite& getData()  { return *child_; }

			BALL_INLINE const Composite& getData() const  { return *child_; }

			BALL_INLINE void forward()  {	child_ = child_->next_;	}

			BALL_INLINE void backward()		
			{		
				if (child_ == 0) 
				{ 
					// Allow decrementation for past-the-end iterators
					child_ = bound_->last_child_; 
				}
				else  
				{ 
					child_ = child_->previous_; 
				}	
			}

			private:

			Composite* bound_;
			Composite* child_;
		};

		friend class ChildCompositeIteratorTraits;

		typedef BidirectionalIterator<Composite, Composite, Composite *, ChildCompositeIteratorTraits>
			ChildCompositeIterator;

		ChildCompositeIterator beginChildComposite()
			
		{
			return ChildCompositeIterator::begin(*this);
		}

		ChildCompositeIterator endChildComposite()
			
		{
			return ChildCompositeIterator::end(*this);
		}



		typedef ConstBidirectionalIterator<Composite, Composite, Composite *, ChildCompositeIteratorTraits>
			ChildCompositeConstIterator;

		ChildCompositeConstIterator beginChildComposite() const
			
		{
			return ChildCompositeConstIterator::begin(*this);
		}

		ChildCompositeConstIterator endChildComposite() const
			
		{
			return ChildCompositeConstIterator::end(*this);
		}



		typedef std::reverse_iterator<ChildCompositeIterator> ChildCompositeReverseIterator;

		ChildCompositeReverseIterator rbeginChildComposite() 
		{
			return ChildCompositeReverseIterator(endChildComposite());
		}

		ChildCompositeReverseIterator rendChildComposite() 
		{
			return ChildCompositeReverseIterator(beginChildComposite());
		}



		typedef std::reverse_iterator<ChildCompositeConstIterator> ChildCompositeConstReverseIterator;

		ChildCompositeConstReverseIterator rbeginChildComposite() const 
		{
			return ChildCompositeConstReverseIterator(endChildComposite());
		}

		ChildCompositeConstReverseIterator rendChildComposite() const 
		{
			return ChildCompositeConstReverseIterator(beginChildComposite());
		}

		class BALL_EXPORT CompositeIteratorTraits
		{
			public:

			BALL_INLINE CompositeIteratorTraits()
				
				:	bound_(0),
					position_(0)
			{
			}
		
			CompositeIteratorTraits(const Composite& composite)
				
				:	bound_(const_cast<Composite*>(&composite)),
					position_(0)
			{
			}
		
			CompositeIteratorTraits(const CompositeIteratorTraits& traits)
				
				:	bound_(traits.bound_),
					position_(traits.position_)
			{
			}

			BALL_INLINE ~CompositeIteratorTraits()  {}
		
			BALL_INLINE bool isValid() const  
			{ 
				return ((bound_ != 0) && (position_ != 0)); 
			}

			BALL_INLINE CompositeIteratorTraits& operator = (const CompositeIteratorTraits& traits) 
			{
				bound_ = traits.bound_;
				position_ = traits.position_;
				return *this;
			}

			BALL_INLINE Composite* getContainer()		{	return bound_; }

			BALL_INLINE const Composite* getContainer() const	 { return bound_; }
		
			BALL_INLINE bool isSingular() const		{	return (bound_ == 0);	}
		
			BALL_INLINE Composite* getPosition()  { return position_;	}
			
			BALL_INLINE const Composite* getPosition() const  { return position_; }
			BALL_INLINE void setPosition(Composite* position)  { position_ = position; }


			BALL_INLINE Composite& getData()  { return *position_; }

			BALL_INLINE const Composite& getData() const  { return *position_; }

			BALL_INLINE bool operator == (const CompositeIteratorTraits& traits) const  
			{ 
				return (position_ == traits.position_); 
			}
		
			BALL_INLINE bool operator != (const CompositeIteratorTraits& traits) const  
			{	
				return !(position_ == traits.position_); 
			}
		
			BALL_INLINE void invalidate() 	
			{ 
				bound_ = 0;	
				position_ = 0;
			}

			BALL_INLINE void toBegin() 
			{
				position_ = bound_;
			}

			BALL_INLINE bool isBegin() const 
			{
				return (position_ == bound_);
			}

			BALL_INLINE void toEnd()  
			{
				position_ = 0;
			}

			BALL_INLINE bool isEnd() const 
			{
				return (position_ == 0);
			}

			BALL_INLINE void toRBegin() 
			{
				if (bound_ != 0)
				{
					position_ = findPreviousPosition(0);
				}
			}

			BALL_INLINE bool isRBegin() const 
			{
				return (position_ == findPreviousPosition(0));
			}
		
			BALL_INLINE void toREnd() 
			{	
				position_ = bound_;
			}

			BALL_INLINE bool isREnd() const 
			{
				return (position_ == bound_);
			}
		
			BALL_INLINE void forward() 
			{
				position_ = findNextPosition(position_);
			}

			BALL_INLINE void backward()	
			{
				position_ = findPreviousPosition(position_);
			}

			protected:

			/// A pointer to the "container" the iterator is bound to
			Composite* bound_;

			/// The current iterator position
			Composite* position_;

			Composite* findPreviousPosition(Composite* p) const
			{
				// If we are at the root of the iterator, the 
				// decrementing it results in an invalid iterator
				// (past-the-end).
				if (p == bound_)
				{
					return 0;
				}
				// If we decrement a past-the-end-iterator, we
				// start at the root and "fall down" on the right
				// hand side following the last_child_ pointers
				// until we hit bottom.
				else if (p == 0)
				{
					if (bound_->last_child_ == 0)
					{
						return bound_;
					}
					else
					{
						p = bound_->last_child_;
					}
					while (p->last_child_ != 0)
					{
						p = p->last_child_;
					}
				}
				// Normally, we just grab the guy to the
				// left in the doubly-linked child list.
				else if (p->previous_ != 0)
				{
					p = p->previous_;

					// If the guy to the left hast children,
					// we do the drop on the rigth again.
					while (p->last_child_ != 0)
					{
						p = p->last_child_;
					}
				}
				// Finally, if we can't go down and we can't go 
				// left, we have to go upwards.
				else if (p != bound_)
				{
					p = p->parent_;
				}

				return p;
			}

			Composite* findNextPosition(Composite* p) const
			{
				// If we are in a past-the-end position, we stay put.
				if (p == 0)
				{
					return 0;
				}
				// Otherwise, we try the first child. If there's one,
				// that's our next position.
				else 
				{
					if (p->first_child_ != 0)
					{
						p = p->first_child_;
					}
					else 
					{
						// If we are already in the root node, we are done.
						if (p == bound_)
						{
							return 0;
						}
						// Otherwise, we try to walk to the right at the current level.
						if (p->next_ != 0)
						{
							p = p->next_;
						}
						// If that doesn't work out, we'll have to climb up again.
						// Now, we either revisit a node we have already been to, or we
						// are trying to climb up *beyond* our iteration root (bound_).
						// In the latter case, we return a past-the-end-iterator (0).
						else
						{
							// If we could not walk left or right and we are at the root
							// again, then we are done with the iteration (this is the
							// case if bound_ is a leaf node).
							while (p->next_ == 0)
							{
								p = p->parent_;
								if ((p == bound_) || (p == 0))
								{
									return 0;
								}
							}
							p = p->next_;
						}
					}
				}
				return p;
			}
		};

		friend class CompositeIteratorTraits;

		typedef BidirectionalIterator<Composite, Composite, Composite*, CompositeIteratorTraits>
			CompositeIterator;

		CompositeIterator beginComposite()  { return CompositeIterator::begin(*this); }

		CompositeIterator endComposite()  { return CompositeIterator::end(*this); }

		typedef ConstBidirectionalIterator<Composite, Composite, Composite*, CompositeIteratorTraits>
			CompositeConstIterator;

		CompositeConstIterator beginComposite() const  
		{	
			return CompositeConstIterator::begin(*this);
		}

		CompositeConstIterator endComposite() const	
		{
			return CompositeConstIterator::end(*this);
		}


		typedef std::reverse_iterator<CompositeIterator> CompositeReverseIterator;

		CompositeReverseIterator rbeginComposite() 
		{
			return CompositeReverseIterator(endComposite());
		}

		CompositeReverseIterator rendComposite() 
		{
			return CompositeReverseIterator(beginComposite());
		}


		typedef std::reverse_iterator<CompositeConstIterator> CompositeConstReverseIterator;

		CompositeConstReverseIterator rbeginComposite() const 
		{
			return CompositeConstReverseIterator(endComposite());
		}

		CompositeConstReverseIterator rendComposite() const 
		{
			return CompositeConstReverseIterator(beginComposite());
		}

		/*
		 * This function removes and deletes all composites that are
		 * supplied in the list of children.
		 */
		void deleteChildrenList_(std::list<Composite*>& composites);

		private:
		
		///
		Size getHeight_(Size size, Size& max_height) const ;
	
		///
		Size countDescendants_() const ;

		///
		void clone_(Composite& parent, Composite& stack) const ;

		// \throws Exception::GeneralException
		template <typename T>
		bool applyLevelNostart_(UnaryProcessor<T>& processor, long level);

		// \throws Exception::GeneralException
		template <typename T>
		bool applyChildNostart_(UnaryProcessor<T>& processor);

		// \throws Exception::GeneralException
		template <typename T>
		bool applyPreorderNostart_(UnaryProcessor<T>& processor);

		// \throws Exception::GeneralException
		template <typename T>
		bool applyDescendantPreorderNostart_(UnaryProcessor<T>& processor);

		// \throws Exception::GeneralException
		template <typename T>
		bool applyDescendantPostorderNostart_(UnaryProcessor<T>& processor);


		void updateSelection_();
		void determineSelection_();
		void select_(bool update_parent = true);
		void deselect_(bool update_parent = true);

		// private attributes
		
		Size 						number_of_children_;
		Composite*			parent_;
		Composite* 			previous_;
		Composite* 			next_;
		Composite* 			first_child_;
		Composite* 			last_child_;
		unsigned char		properties_;
		bool						contains_selection_;
		Size						number_of_selected_children_;
		Size						number_of_children_containing_selection_;
		TimeStamp				selection_stamp_;
		TimeStamp				modification_stamp_;
	};

	template <typename T>
	bool Composite::applyAncestor(UnaryProcessor<T>& processor)
	{
		if (processor.start() == false)
		{
			return false;
		}

		Processor::Result result;

		for (Composite* composite = parent_; composite != 0; composite = composite->parent_)
		{
			T* t_ptr;
			if ((t_ptr = dynamic_cast<T*>(composite)) != 0)
			{	
				result = processor(*t_ptr);
				if (result <= Processor::BREAK)
				{
					return (result == Processor::BREAK);
				}
			}
		}

		return processor.finish();
	}
	
	template <typename T>
	bool Composite::applyChild(UnaryProcessor<T>& processor)
	{
		return processor.start() && applyChildNostart_(processor) && processor.finish();
	}

	template <typename T>
	bool Composite::applyChildNostart_(UnaryProcessor<T>& processor)
	{
		Processor::Result result = Processor::CONTINUE;

		for (Composite* composite = first_child_;
				 composite != 0; composite = composite->next_)
		{
			T* t_ptr;
			if ((t_ptr = dynamic_cast<T*>(composite)) != 0)
			{
				result = processor(*t_ptr);
				if (result <= Processor::BREAK)
				{
					break;
				}
			}
		}

		return (result >= Processor::BREAK);
	}
 
	template <typename T>
	bool Composite::applyDescendantPreorder(UnaryProcessor<T>& processor)
	{
		return processor.start() && applyDescendantPreorderNostart_(processor) && processor.finish();
	}

	template <typename T>
	bool Composite::applyDescendantPreorderNostart_(UnaryProcessor<T>& processor)
	{
		Processor::Result result;

		for (Composite* composite = first_child_;
				 composite != 0; composite = composite->next_)
		{
			T* t_ptr;
			if ((t_ptr = dynamic_cast<T*>(composite)) != 0)
			{	
				result = processor(*t_ptr);

				if (result <= Processor::BREAK)
				{
					return (result == Processor::BREAK);
				}
			}

			if (composite->first_child_ != 0  && composite->applyDescendantPreorderNostart_(processor) == false)
			{
				return false;
			}
		}

		return true;
	}

	template <typename T>
	bool Composite::applyDescendantPostorder(UnaryProcessor<T>& processor)
	{
		return processor.start() && applyDescendantPostorderNostart_(processor) && processor.finish();
	}

	template <typename T>
	bool Composite::applyDescendantPostorderNostart_(UnaryProcessor<T>& processor)
	{
		Processor::Result result;

		for (Composite* composite = first_child_;
				 composite != 0; composite = composite->next_)
		{
			if (composite->first_child_ != 0 && 
					composite->applyDescendantPostorderNostart_(processor) == false)
			{
				return false;
			}

			T* t_ptr = dynamic_cast<T*>(composite);
			if (t_ptr != 0)
			{
				result = processor(*t_ptr);

				if (result <= Processor::BREAK)
				{
					return (result == Processor::BREAK);
				}
			}
		}

		return true;
	}

	template <typename T>  
	bool Composite::applyPostorder(UnaryProcessor<T>& processor)
	{ 
		if (!processor.start() || !applyDescendantPostorderNostart_(processor))
		{
			return false;
		}

		T* t_ptr = dynamic_cast<T*>(this);

		return (t_ptr != 0													  && 
						processor(*t_ptr) >= Processor::BREAK && 
						processor.finish()											);
	}

	template <typename T>
	bool Composite::applyLevel(UnaryProcessor<T>& processor, long level)
	{
		return processor.start() && applyLevelNostart_(processor, level) && processor.finish();
	}

	template <typename T>
	bool Composite::applyLevelNostart_(UnaryProcessor<T>& processor, long level)
	{
		if (level == 0)
		{
			T* t_ptr = dynamic_cast<T*>(this);
			if (t_ptr != 0)
			{
			 Processor::Result result = processor(*t_ptr);

				if (result <= Processor::BREAK)
				{
					return (result == Processor::BREAK);
				}
			}
		}
		else 
		{
			if (--level == 0)
			{
				return applyChildNostart_(processor);
			}
			else 
			{
				if (level > 0)
				{
					for (Composite* composite = first_child_;
							 composite != 0; composite = composite->next_)
					{
						if (composite->first_child_ != 0 && composite->applyLevelNostart_(processor, level) == false)
						{
							return false;
						}
					}
				}
			}
		}
		return true;
	}

	template <typename T>
	bool Composite::applyPreorderNostart_(UnaryProcessor<T>& processor)
	{
		Processor::Result result;
		bool return_value;
		T* t_ptr = dynamic_cast<T*>(this);
		if (t_ptr != 0)
		{
			result = processor(*t_ptr);
	
			if (result <= Processor::BREAK)
			{
				return_value = (result == Processor::BREAK);
			} 
			else 
			{
				return_value =  applyDescendantPreorderNostart_(processor);
			}
		} 
		else 
		{
			return_value =  applyDescendantPreorderNostart_(processor);
		}
		
		return return_value;
	}

	template <typename T>
	bool Composite::applyDescendant(UnaryProcessor<T>& processor)
	{
		return applyDescendantPreorder(processor);
	}

	template <typename T>
	bool Composite::applyPreorder(UnaryProcessor<T>& processor)
	{
		return processor.start() && applyPreorderNostart_(processor) && processor.finish();
	}

	template <typename T>
	BALL_INLINE 
	bool Composite::apply(UnaryProcessor<T>& processor)
	{
		return applyPreorder(processor);
	}

	template <typename T>
	BALL_INLINE 
	T* Composite::getAncestor(const T& /* dummy */)
		
	{
		T* T_ptr = 0;
		
		for (Composite* composite_ptr = parent_;
				 composite_ptr != 0; composite_ptr = composite_ptr->parent_)
		{
			T_ptr = dynamic_cast<T*>(composite_ptr);
			if (T_ptr != 0)
			{
				break;
			}	
		}
		
		return T_ptr;
	}

	template <typename T>
	BALL_INLINE 
	const T* Composite::getAncestor(const T& /* dummy */) const
		
	{
		T* t_ptr = 0;
		for (Composite* composite_ptr = parent_;
				 composite_ptr != 0; composite_ptr = composite_ptr->parent_)
		{
			if ((t_ptr = dynamic_cast<T*>(composite_ptr)) != 0)
			{
				break;
			}	
		}
		
		return const_cast<const T*>(t_ptr);
	}

	template <typename T>
	BALL_INLINE 
	T* Composite::getPrevious(const T& /* dummy */)
		
	{
		// create an iterator bound to the root of the subtree
		CompositeIterator it(getRoot().endComposite());

		// set its position to the current composite
		it.getTraits().setPosition(this);

		// walk back until we find something	
		// or we cannot walk any further
		if (+it)
		{
			do 
			{
				--it;
			} 
			while (+it && !RTTI::isKindOf<T>(*it));
		}

		// return a NULL pointer if nothing was found
		Composite* ptr = 0;
		if (+it)
		{
			ptr = &*it;
		}
		
		return dynamic_cast<T*>(ptr);
	}

	template <typename T>
	BALL_INLINE 
	const T* Composite::getPrevious(const T& dummy) const
		
	{
		// cast away the constness of this and call the non-const method
		Composite* nonconst_this = const_cast<Composite*>(this);

		return const_cast<const T*>(nonconst_this->getPrevious(dummy));
	}

	template <typename T>
	BALL_INLINE 
	T* Composite::getNext(const T& /* dummy */)
		
	{
		// create an iterator bound to the root of the subtree
		CompositeIterator it(getRoot().beginComposite());

		// set its position to the current composite
		it.getTraits().setPosition(this);

		// walk forward until we find something	
		// or we cannot walk any further
		do 
		{
			it++;
		} 
		while (it.isValid() && !RTTI::isKindOf<T>(*it));


		// return a NULL pointer if nothing was found
		Composite* ptr = 0;
		if (+it)
		{
			ptr = &*it;
		}
		
		return dynamic_cast<T*>(ptr);
	}

	template <typename T>
	BALL_INLINE 
	const T* Composite::getNext(const T& dummy) const
		
	{
		// cast away the constness of this and call the non-const method
		Composite* nonconst_this = const_cast<Composite*>(this);

		return const_cast<const T*>(nonconst_this->getNext(dummy));
	}

	template <typename T>
	BALL_INLINE 
	bool Composite::hasAncestor(const T& dummy ) const 
		
	{
		return (getAncestor(dummy) != 0);	
	}

#	ifndef BALL_NO_INLINE_FUNCTIONS
#		include <BALL/CONCEPT/composite.iC>
#	endif


} // namespace BALL

#endif // BALL_CONCEPT_COMPOSITE_H