5 #ifndef BALL_CONCEPT_COMPOSITE_H
6 #define BALL_CONCEPT_COMPOSITE_H
12 #ifndef BALL_CONCEPT_PERSISTENTOBJECT_H
16 #ifndef BALL_CONCEPT_COMPARATOR_H
20 #ifndef BALL_CONCEPT_BIDIRECTIONALITERATOR_H
24 #ifndef BALL_CONCEPT_OBJECT_H
28 #ifndef BALL_CONCEPT_SELECTABLE_H
32 #ifndef BALL_CONCEPT_VISITOR_H
36 #ifndef BALL_CONCEPT_PROCESSOR_H
40 #ifndef BALL_CONCEPT_TIMESTAMP_H
79 #ifndef BALL_KERNEL_PREDICATE_TYPE
80 #define BALL_KERNEL_PREDICATE_TYPE
162 virtual
void destroy()
177 void destroy(
bool virtual_destroy)
187 void* clone(Composite& root) const
220 void set(const Composite& composite,
bool deep = true) ;
226 Composite& operator = (const Composite& composite) ;
234 void get(Composite& composite,
bool deep = true) const ;
240 Size getDegree() const ;
251 Size countDescendants() const ;
258 Size getPathLength(const Composite& composite) const ;
264 Size getDepth() const ;
270 Size getHeight() const
276 Composite& getRoot() ;
281 const Composite& getRoot() const ;
287 Composite* getLowestCommonAncestor(const Composite& composite)
294 const Composite* getLowestCommonAncestor(const Composite& composite) const
305 template <typename T>
306 T* getAncestor(const T& )
315 template <typename T>
316 const T* getAncestor(const T& ) const ;
325 template <typename T>
326 T* getPrevious(const T& ) ;
335 template <typename T>
336 const T* getPrevious(const T& dummy) const ;
345 template <typename T>
346 T* getNext(const T& ) ;
355 template <typename T>
356 const T* getNext(const T& dummy) const ;
361 Composite* getParent() ;
366 const Composite* getParent() const ;
374 Composite* getChild(
Index index) ;
382 const Composite* getChild(
Index index) const ;
392 Composite* getSibling(
Index index) ;
402 const Composite* getSibling(
Index index) const ;
407 Composite* getFirstChild() ;
412 const Composite* getFirstChild() const ;
417 Composite* getLastChild() ;
422 const Composite* getLastChild() const ;
450 void prependChild(Composite& composite) ;
459 void appendChild(Composite& composite) ;
480 static
bool insertParent(Composite& parent, Composite& first,
481 Composite& last,
bool destroy_parent = true)
493 void insertBefore(Composite& composite) ;
504 void insertAfter(Composite& composite) ;
514 void spliceBefore(Composite& composite) ;
524 void spliceAfter(Composite& composite) ;
535 void splice(Composite& composite) ;
545 bool removeChild(Composite& child) ;
560 Size removeSelected() ;
574 Size removeUnselected();
584 void replace(Composite& composite) ;
594 void swap(Composite& composite) ;
604 virtual
void select() ;
614 virtual
void deselect() ;
626 bool operator == (const Composite& composite) const ;
631 bool operator != (const Composite& composite) const
637 bool isEmpty() const ;
642 bool isRoot() const ;
646 bool isRootOf(const Composite& composite) const ;
650 bool isInterior() const ;
654 bool hasChild() const ;
658 bool isChildOf(const Composite& composite) const ;
662 bool isFirstChild() const ;
666 bool isFirstChildOf(const Composite& composite) const ;
670 bool isLastChild() const ;
674 bool isLastChildOf(const Composite& composite) const ;
678 bool hasParent() const ;
682 bool isParentOf(const Composite& composite) const ;
687 bool hasSibling() const ;
691 bool isSiblingOf(const Composite& composite) const ;
696 bool hasPreviousSibling() const ;
700 bool isPreviousSiblingOf(const Composite& composite) const ;
705 bool hasNextSibling() const ;
709 bool isNextSiblingOf(const Composite& composite) const ;
713 bool isDescendantOf(const Composite& composite) const ;
717 template <typename T>
718 bool hasAncestor(const T& dummy) const ;
722 bool isAncestorOf(const Composite& composite) const ;
727 bool isRelatedWith(const Composite& composite) const ;
732 bool isHomomorph(const Composite& composite) const ;
743 bool containsSelection() const ;
751 virtual
bool isValid() const ;
757 virtual
void dump(std::ostream& s = std::cout,
Size depth = 0) const
770 void host(
Visitor<Composite>& visitor);
776 template <typename T>
783 template <typename T>
793 template <typename T>
803 template <typename T>
813 template <typename T>
822 template <typename T>
831 template <typename T>
840 template <typename T>
847 template <typename T>
858 AncestorIteratorTraits()
866 AncestorIteratorTraits(
const Composite& composite)
868 : bound_(const_cast<Composite*>(&composite)),
874 AncestorIteratorTraits(
const AncestorIteratorTraits& traits)
876 : bound_(traits.bound_),
877 ancestor_(traits.ancestor_)
882 const AncestorIteratorTraits& operator = (
const AncestorIteratorTraits& traits)
900 BALL_INLINE bool operator == (
const AncestorIteratorTraits& traits)
const {
return (ancestor_ == traits.
ancestor_); }
902 BALL_INLINE bool operator != (
const AncestorIteratorTraits& traits)
const {
return !(ancestor_ == traits.
ancestor_); }
935 return AncestorIterator::begin(*
this);
940 return AncestorIterator::end(*
this);
948 return AncestorConstIterator::begin(*
this);
953 return AncestorConstIterator::end(*
this);
976 : bound_(traits.bound_),
977 child_(traits.child_)
1034 child_ = bound_->last_child_;
1038 child_ = child_->previous_;
1056 return ChildCompositeIterator::begin(*
this);
1062 return ChildCompositeIterator::end(*
this);
1073 return ChildCompositeConstIterator::begin(*
this);
1079 return ChildCompositeConstIterator::end(*
this);
1123 : bound_(const_cast<
Composite*>(&composite)),
1130 : bound_(traits.bound_),
1131 position_(traits.position_)
1139 return ((bound_ != 0) && (position_ != 0));
1172 return !(position_ == traits.
position_);
1188 return (position_ == bound_);
1198 return (position_ == 0);
1205 position_ = findPreviousPosition(0);
1211 return (position_ == findPreviousPosition(0));
1221 return (position_ == bound_);
1226 position_ = findNextPosition(position_);
1231 position_ = findPreviousPosition(position_);
1257 if (bound_->last_child_ == 0)
1285 else if (p != bound_)
1329 while (p->
next_ == 0)
1332 if ((p == bound_) || (p == 0))
1359 return CompositeConstIterator::begin(*
this);
1364 return CompositeConstIterator::end(*
this);
1397 void deleteChildrenList_(std::list<Composite*>& composites);
1405 Size countDescendants_()
const ;
1411 template <
typename T>
1415 template <
typename T>
1419 template <
typename T>
1423 template <
typename T>
1427 template <
typename T>
1431 void updateSelection_();
1432 void determineSelection_();
1433 void select_(
bool update_parent =
true);
1434 void deselect_(
bool update_parent =
true);
1436 void destroyChildren_();
1454 template <
typename T>
1457 if (processor.
start() ==
false)
1467 if ((t_ptr = dynamic_cast<T*>(composite)) != 0)
1469 result = processor(*t_ptr);
1477 return processor.
finish();
1480 template <
typename T>
1486 template <
typename T>
1492 composite != 0; composite = composite->
next_)
1495 if ((t_ptr = dynamic_cast<T*>(composite)) != 0)
1497 result = processor(*t_ptr);
1508 template <
typename T>
1514 template <
typename T>
1520 composite != 0; composite = composite->
next_)
1523 if ((t_ptr = dynamic_cast<T*>(composite)) != 0)
1525 result = processor(*t_ptr);
1533 if (composite->first_child_ != 0 && composite->applyDescendantPreorderNostart_(processor) ==
false)
1542 template <
typename T>
1548 template <
typename T>
1554 composite != 0; composite = composite->
next_)
1556 if (composite->first_child_ != 0 &&
1557 composite->applyDescendantPostorderNostart_(processor) ==
false)
1562 T* t_ptr =
dynamic_cast<T*
>(composite);
1565 result = processor(*t_ptr);
1577 template <
typename T>
1585 T* t_ptr =
dynamic_cast<T*
>(
this);
1587 return (t_ptr != 0 &&
1592 template <
typename T>
1598 template <
typename T>
1603 T* t_ptr =
dynamic_cast<T*
>(
this);
1625 composite != 0; composite = composite->
next_)
1627 if (composite->first_child_ != 0 && composite->applyLevelNostart_(processor, level) ==
false)
1638 template <
typename T>
1643 T* t_ptr =
dynamic_cast<T*
>(
this);
1646 result = processor(*t_ptr);
1662 return return_value;
1665 template <
typename T>
1671 template <
typename T>
1677 template <
typename T>
1684 template <
typename T>
1692 composite_ptr != 0; composite_ptr = composite_ptr->
parent_)
1694 T_ptr =
dynamic_cast<T*
>(composite_ptr);
1704 template <
typename T>
1711 composite_ptr != 0; composite_ptr = composite_ptr->
parent_)
1713 if ((t_ptr = dynamic_cast<T*>(composite_ptr)) != 0)
1719 return const_cast<const T*
>(t_ptr);
1722 template <
typename T>
1741 while (+it && !RTTI::isKindOf<T>(*it));
1751 return dynamic_cast<T*
>(ptr);
1754 template <
typename T>
1762 return const_cast<const T*
>(nonconst_this->
getPrevious(dummy));
1765 template <
typename T>
1782 while (it.
isValid() && !RTTI::isKindOf<T>(*it));
1792 return dynamic_cast<T*
>(ptr);
1795 template <
typename T>
1803 return const_cast<const T*
>(nonconst_this->
getNext(dummy));
1806 template <
typename T>
1814 # ifndef BALL_NO_INLINE_FUNCTIONS
1815 # include <BALL/CONCEPT/composite.iC>
1821 #endif // BALL_CONCEPT_COMPOSITE_H