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
81 #ifndef BALL_KERNEL_PREDICATE_TYPE
82 #define BALL_KERNEL_PREDICATE_TYPE
164 virtual
void destroy()
179 void destroy(
bool virtual_destroy)
189 void* clone(Composite& root) const
222 void set(const Composite& composite,
bool deep = true) ;
228 Composite& operator = (const Composite& composite) ;
236 void get(Composite& composite,
bool deep = true) const ;
242 Size getDegree() const ;
253 Size countDescendants() const ;
260 Size getPathLength(const Composite& composite) const ;
266 Size getDepth() const ;
272 Size getHeight() const
278 Composite& getRoot() ;
283 const Composite& getRoot() const ;
289 Composite* getLowestCommonAncestor(const Composite& composite)
296 const Composite* getLowestCommonAncestor(const Composite& composite) const
307 template <typename T>
308 T* getAncestor(const T& )
317 template <typename T>
318 const T* getAncestor(const T& ) const ;
327 template <typename T>
328 T* getPrevious(const T& ) ;
337 template <typename T>
338 const T* getPrevious(const T& dummy) const ;
347 template <typename T>
348 T* getNext(const T& ) ;
357 template <typename T>
358 const T* getNext(const T& dummy) const ;
363 Composite* getParent() ;
368 const Composite* getParent() const ;
376 Composite* getChild(
Index index) ;
384 const Composite* getChild(
Index index) const ;
394 Composite* getSibling(
Index index) ;
404 const Composite* getSibling(
Index index) const ;
409 Composite* getFirstChild() ;
414 const Composite* getFirstChild() const ;
419 Composite* getLastChild() ;
424 const Composite* getLastChild() const ;
452 void prependChild(Composite& composite) ;
461 void appendChild(Composite& composite) ;
482 static
bool insertParent(Composite& parent, Composite& first,
483 Composite& last,
bool destroy_parent = true)
495 void insertBefore(Composite& composite) ;
506 void insertAfter(Composite& composite) ;
516 void spliceBefore(Composite& composite) ;
526 void spliceAfter(Composite& composite) ;
537 void splice(Composite& composite) ;
547 bool removeChild(Composite& child) ;
562 Size removeSelected() ;
576 Size removeUnselected();
586 void replace(Composite& composite) ;
596 void swap(Composite& composite) ;
606 virtual
void select() ;
616 virtual
void deselect() ;
628 bool operator == (const Composite& composite) const ;
633 bool operator != (const Composite& composite) const
639 bool isEmpty() const ;
644 bool isRoot() const ;
648 bool isRootOf(const Composite& composite) const ;
652 bool isInterior() const ;
656 bool hasChild() const ;
660 bool isChildOf(const Composite& composite) const ;
664 bool isFirstChild() const ;
668 bool isFirstChildOf(const Composite& composite) const ;
672 bool isLastChild() const ;
676 bool isLastChildOf(const Composite& composite) const ;
680 bool hasParent() const ;
684 bool isParentOf(const Composite& composite) const ;
689 bool hasSibling() const ;
693 bool isSiblingOf(const Composite& composite) const ;
698 bool hasPreviousSibling() const ;
702 bool isPreviousSiblingOf(const Composite& composite) const ;
707 bool hasNextSibling() const ;
711 bool isNextSiblingOf(const Composite& composite) const ;
715 bool isDescendantOf(const Composite& composite) const ;
719 template <typename T>
720 bool hasAncestor(const T& dummy) const ;
724 bool isAncestorOf(const Composite& composite) const ;
729 bool isRelatedWith(const Composite& composite) const ;
734 bool isHomomorph(const Composite& composite) const ;
745 bool containsSelection() const ;
757 virtual
bool isAtom()
const {
return false; }
782 virtual bool isChain()
const {
return false; }
790 virtual bool isValid()
const ;
796 virtual void dump(std::ostream& s = std::cout,
Size depth = 0)
const
815 template <
typename T>
822 template <
typename T>
830 template <
typename T>
837 template <
typename T>
847 template <
typename T>
857 template <
typename T>
867 template <
typename T>
877 template <
typename T>
887 template <
typename T>
897 template <
typename T>
906 template <
typename T>
915 template <
typename T>
924 template <
typename T>
933 template <
typename T>
942 template <
typename T>
951 template <
typename T>
958 template <
typename T>
966 template <
typename T>
988 : bound_(const_cast<
Composite*>(&composite)),
996 : bound_(traits.bound_),
997 ancestor_(traits.ancestor_)
1005 bound_ = traits.bound_;
1006 ancestor_ = traits.ancestor_;
1055 return AncestorIterator::begin(*
this);
1060 return AncestorIterator::end(*
this);
1068 return AncestorConstIterator::begin(*
this);
1073 return AncestorConstIterator::end(*
this);
1096 : bound_(traits.bound_),
1097 child_(traits.child_)
1104 bound_ = traits.bound_;
1105 child_ = traits.child_;
1154 child_ = bound_->last_child_;
1158 child_ = child_->previous_;
1176 return ChildCompositeIterator::begin(*
this);
1182 return ChildCompositeIterator::end(*
this);
1193 return ChildCompositeConstIterator::begin(*
this);
1199 return ChildCompositeConstIterator::end(*
this);
1243 : bound_(const_cast<
Composite*>(&composite)),
1250 : bound_(traits.bound_),
1251 position_(traits.position_)
1259 return ((bound_ != 0) && (position_ != 0));
1292 return !(position_ == traits.
position_);
1308 return (position_ == bound_);
1318 return (position_ == 0);
1325 position_ = findPreviousPosition(0);
1331 return (position_ == findPreviousPosition(0));
1341 return (position_ == bound_);
1346 position_ = findNextPosition(position_);
1351 position_ = findPreviousPosition(position_);
1377 if (bound_->last_child_ == 0)
1383 p = bound_->last_child_;
1385 while (p->last_child_ != 0)
1392 else if (p->previous_ != 0)
1398 while (p->last_child_ != 0)
1405 else if (p != bound_)
1424 if (p->first_child_ != 0)
1426 p = p->first_child_;
1449 while (p->next_ == 0)
1452 if ((p == bound_) || (p == 0))
1479 return CompositeConstIterator::begin(*
this);
1484 return CompositeConstIterator::end(*
this);
1517 void deleteChildrenList_(std::list<Composite*>& composites);
1525 Size countDescendants_()
const ;
1531 template <
typename T>
1535 template <
typename T>
1539 template <
typename T>
1543 template <
typename T>
1547 template <
typename T>
1554 template <
typename T>
1558 template <
typename T>
1565 template <
typename T>
1569 template <
typename T>
1573 template <
typename T>
1576 void updateSelection_();
1577 void determineSelection_();
1578 void select_(
bool update_parent =
true);
1579 void deselect_(
bool update_parent =
true);
1581 void destroyChildren_();
1585 Size number_of_children_;
1591 unsigned char properties_;
1592 bool contains_selection_;
1593 Size number_of_selected_children_;
1594 Size number_of_children_containing_selection_;
1599 template <
typename T>
1602 if (processor.
start() ==
false)
1609 for (
Composite* composite = parent_; composite != 0; composite = composite->parent_)
1612 if ((t_ptr = dynamic_cast<T*>(composite)) != 0)
1614 result = processor(*t_ptr);
1622 return processor.
finish();
1625 template <
typename T>
1628 if (processor.
start() ==
false)
1635 for (
const Composite* composite = parent_; composite != 0; composite = composite->parent_)
1638 if ((t_ptr = dynamic_cast<const T*>(composite)) != 0)
1640 result = processor(*t_ptr);
1648 return processor.
finish();
1651 template <
typename T>
1654 return processor.
start() && applyChildNostart_(processor) && processor.
finish();
1657 template <
typename T>
1660 return processor.
start() && applyChildNostart_(processor) && processor.
finish();
1663 template <
typename T>
1668 for (
Composite* composite = first_child_;
1669 composite != 0; composite = composite->next_)
1672 if ((t_ptr = dynamic_cast<T*>(composite)) != 0)
1674 result = processor(*t_ptr);
1685 template <
typename T>
1686 bool Composite::applyChildNostart_(ConstUnaryProcessor<T>& processor)
const
1690 for (
const Composite* composite = first_child_;
1691 composite != 0; composite = composite->next_)
1694 if ((t_ptr = dynamic_cast<const T*>(composite)) != 0)
1696 result = processor(*t_ptr);
1707 template <
typename T>
1710 return processor.
start() && applyDescendantPreorderNostart_(processor) && processor.
finish();
1713 template <
typename T>
1716 return processor.
start() && applyDescendantPreorderNostart_(processor) && processor.
finish();
1719 template <
typename T>
1724 for (
Composite* composite = first_child_;
1725 composite != 0; composite = composite->next_)
1728 if ((t_ptr = dynamic_cast<T*>(composite)) != 0)
1730 result = processor(*t_ptr);
1738 if (composite->first_child_ != 0 && composite->applyDescendantPreorderNostart_(processor) ==
false)
1747 template <
typename T>
1748 bool Composite::applyDescendantPreorderNostart_(ConstUnaryProcessor<T>& processor)
const
1752 for (
const Composite* composite = first_child_;
1753 composite != 0; composite = composite->next_)
1756 if ((t_ptr = dynamic_cast<const T*>(composite)) != 0)
1758 result = processor(*t_ptr);
1766 if (composite->first_child_ != 0 && composite->applyDescendantPreorderNostart_(processor) ==
false)
1775 template <
typename T>
1778 return processor.
start() && applyDescendantPostorderNostart_(processor) && processor.
finish();
1781 template <
typename T>
1784 return processor.
start() && applyDescendantPostorderNostart_(processor) && processor.
finish();
1787 template <
typename T>
1792 for (
Composite* composite = first_child_;
1793 composite != 0; composite = composite->next_)
1795 if (composite->first_child_ != 0 &&
1796 composite->applyDescendantPostorderNostart_(processor) ==
false)
1801 T* t_ptr =
dynamic_cast<T*
>(composite);
1804 result = processor(*t_ptr);
1816 template <
typename T>
1817 bool Composite::applyDescendantPostorderNostart_(ConstUnaryProcessor<T>& processor)
const
1821 for (
const Composite* composite = first_child_;
1822 composite != 0; composite = composite->next_)
1824 if (composite->first_child_ != 0 &&
1825 composite->applyDescendantPostorderNostart_(processor) ==
false)
1830 const T* t_ptr =
dynamic_cast<const T*
>(composite);
1833 result = processor(*t_ptr);
1845 template <
typename T>
1848 if (!processor.
start() || !applyDescendantPostorderNostart_(processor))
1853 T* t_ptr =
dynamic_cast<T*
>(
this);
1855 return (t_ptr != 0 &&
1860 template <
typename T>
1863 if (!processor.
start() || !applyDescendantPostorderNostart_(processor))
1868 const T* t_ptr =
dynamic_cast<const T*
>(
this);
1870 return (t_ptr != 0 &&
1876 template <
typename T>
1879 return processor.
start() && applyLevelNostart_(processor, level) && processor.
finish();
1882 template <
typename T>
1885 return processor.
start() && applyLevelNostart_(processor, level) && processor.
finish();
1888 template <
typename T>
1893 T* t_ptr =
dynamic_cast<T*
>(
this);
1908 return applyChildNostart_(processor);
1914 for (
Composite* composite = first_child_;
1915 composite != 0; composite = composite->next_)
1917 if (composite->first_child_ != 0 && composite->applyLevelNostart_(processor, level) ==
false)
1928 template <
typename T>
1929 bool Composite::applyLevelNostart_(ConstUnaryProcessor<T>& processor,
long level)
const
1933 const T* t_ptr =
dynamic_cast<const T*
>(
this);
1948 return applyChildNostart_(processor);
1954 for (
const Composite* composite = first_child_;
1955 composite != 0; composite = composite->next_)
1957 if (composite->first_child_ != 0 && composite->applyLevelNostart_(processor, level) ==
false)
1969 template <
typename T>
1970 bool Composite::applyPreorderNostart_(UnaryProcessor<T>& processor)
1974 T* t_ptr =
dynamic_cast<T*
>(
this);
1977 result = processor(*t_ptr);
1985 return_value = applyDescendantPreorderNostart_(processor);
1990 return_value = applyDescendantPreorderNostart_(processor);
1993 return return_value;
1996 template <
typename T>
1997 bool Composite::applyPreorderNostart_(ConstUnaryProcessor<T>& processor)
const
2001 const T* t_ptr =
dynamic_cast<const T*
>(
this);
2004 result = processor(*t_ptr);
2012 return_value = applyDescendantPreorderNostart_(processor);
2017 return_value = applyDescendantPreorderNostart_(processor);
2020 return return_value;
2023 template <
typename T>
2029 template <
typename T>
2035 template <
typename T>
2038 return processor.
start() && applyPreorderNostart_(processor) && processor.
finish();
2041 template <
typename T>
2044 return processor.
start() && applyPreorderNostart_(processor) && processor.
finish();
2047 template <
typename T>
2054 template <
typename T>
2061 template <
typename T>
2068 for (
Composite* composite_ptr = parent_;
2069 composite_ptr != 0; composite_ptr = composite_ptr->parent_)
2071 T_ptr =
dynamic_cast<T*
>(composite_ptr);
2081 template <
typename T>
2087 for (
Composite* composite_ptr = parent_;
2088 composite_ptr != 0; composite_ptr = composite_ptr->parent_)
2090 if ((t_ptr = dynamic_cast<T*>(composite_ptr)) != 0)
2096 return const_cast<const T*
>(t_ptr);
2099 template <
typename T>
2118 while (+it && !RTTI::isKindOf<T>(*it));
2128 return dynamic_cast<T*
>(ptr);
2131 template <
typename T>
2139 return const_cast<const T*
>(nonconst_this->
getPrevious(dummy));
2142 template <
typename T>
2159 while (it.
isValid() && !RTTI::isKindOf<T>(*it));
2169 return dynamic_cast<T*
>(ptr);
2172 template <
typename T>
2180 return const_cast<const T*
>(nonconst_this->
getNext(dummy));
2183 template <
typename T>
2191 # ifndef BALL_NO_INLINE_FUNCTIONS
2192 # include <BALL/CONCEPT/composite.iC>
2198 #endif // BALL_CONCEPT_COMPOSITE_H
BALL_INLINE bool isSingular() const
BALL_INLINE Composite * getPosition()
BALL_INLINE Composite *const & getPosition() const
ChildCompositeIteratorTraits(const ChildCompositeIteratorTraits &traits)
CompositeReverseIterator rendComposite()
Composite * bound_
A pointer to the "container" the iterator is bound to.
BALL_INLINE CompositeIteratorTraits()
BALL_INLINE void invalidate()
bool applyDescendantPreorder(UnaryProcessor< T > &processor)
BALL_INLINE Composite & getData()
ChildCompositeIterator endChildComposite()
CompositeIteratorTraits(const CompositeIteratorTraits &traits)
BALL_INLINE const Composite & getData() const
BALL_INLINE bool isRBegin() const
BALL_INLINE bool isEnd() const
bool hasAncestor(const T &dummy) const
ChildCompositeReverseIterator rbeginChildComposite()
BALL_INLINE bool isBegin() const
T * getPrevious(const T &)
AncestorConstIterator beginAncestor() const
ConstBidirectionalIterator< Composite, Composite, Composite *, CompositeIteratorTraits > CompositeConstIterator
std::reverse_iterator< ChildCompositeConstIterator > ChildCompositeConstReverseIterator
bool applyDescendantPostorder(UnaryProcessor< T > &processor)
BALL_INLINE bool isREnd() const
bool applyPostorder(UnaryProcessor< T > &processor)
bool applyPreorder(UnaryProcessor< T > &processor)
ChildCompositeReverseIterator rendChildComposite()
BALL_INLINE void forward()
AncestorIterator endAncestor()
BALL_INLINE bool isSingular() const
CompositeConstIterator beginComposite() const
BALL_INLINE void backward()
BALL_INLINE ~CompositeIteratorTraits()
bool applyChild(UnaryProcessor< T > &processor)
BALL_INLINE AncestorIteratorTraits()
BALL_INLINE Composite * getContainer()
BALL_INLINE void invalidate()
virtual bool isProtein() const
BALL_INLINE Composite * getContainer()
BALL_INLINE void forward()
BALL_INLINE void toRBegin()
BALL_INLINE Composite & getData()
bool applyDescendant(UnaryProcessor< T > &processor)
CompositeReverseIterator rbeginComposite()
BALL_INLINE void toREnd()
BALL_INLINE AncestorIteratorTraits(const Composite &composite)
BALL_INLINE AncestorIteratorTraits(const AncestorIteratorTraits &traits)
BALL_INLINE bool isValid() const
BALL_INLINE Composite * getContainer()
BALL_INLINE bool isBegin() const
CompositeConstIterator endComposite() const
CompositeConstReverseIterator rbeginComposite() const
UnaryPredicate< Composite > KernelPredicateType
BALL_INLINE Composite & getData()
CompositeIteratorTraits(const Composite &composite)
BALL_INLINE void setPosition(Composite *position)
BALL_INLINE bool isValid() const
ChildCompositeIterator beginChildComposite()
CompositeIterator beginComposite()
ChildCompositeConstReverseIterator rendChildComposite() const
BALL_INLINE bool isREnd() const
BALL_EXPORT bool operator!=(const String &s1, const String &s2)
bool applyAncestor(UnaryProcessor< T > &processor)
BALL_INLINE const Composite * getContainer() const
#define BALL_CREATE_DEEP(name)
BALL_INLINE void invalidate()
std::reverse_iterator< ChildCompositeIterator > ChildCompositeReverseIterator
virtual bool isFragment() const
BALL_INLINE bool isValid() const
BALL_INLINE bool isBegin() const
std::reverse_iterator< CompositeConstIterator > CompositeConstReverseIterator
virtual bool isChain() const
CompositeConstReverseIterator rendComposite() const
std::reverse_iterator< CompositeIterator > CompositeReverseIterator
Composite * findPreviousPosition(Composite *p) const
BALL_INLINE const Traits & getTraits() const
Get a constant reference to the traits of this iterator.
ChildCompositeIteratorTraits()
BALL_INLINE const Composite * getContainer() const
BidirectionalIterator< Composite, Composite, Composite *, CompositeIteratorTraits > CompositeIterator
T * getAncestor(const T &)
bool apply(UnaryProcessor< T > &processor)
BALL_INLINE void toRBegin()
BALL_EXPORT bool operator==(const String &s1, const String &s2)
ChildCompositeConstIterator endChildComposite() const
BALL_INLINE void toREnd()
Composite * position_
The current iterator position.
BALL_INLINE void backward()
BALL_INLINE void forward()
BALL_INLINE void toBegin()
ChildCompositeConstReverseIterator rbeginChildComposite() const
BALL_INLINE void toBegin()
ChildCompositeIteratorTraits(const Composite &composite)
BALL_INLINE bool isRBegin() const
virtual bool isResidue() const
BALL_INLINE Composite * getPosition()
Mutable bidirectional iterator.
BidirectionalIterator< Composite, Composite, Composite *, ChildCompositeIteratorTraits > ChildCompositeIterator
BALL_INLINE bool isSingular() const
ConstBidirectionalIterator< Composite, Composite, Composite *, ChildCompositeIteratorTraits > ChildCompositeConstIterator
CompositeIterator endComposite()
AncestorIterator beginAncestor()
virtual bool isMolecule() const
BALL_INLINE void toBegin()
ConstForwardIterator< Composite, Composite, Composite *, AncestorIteratorTraits > AncestorConstIterator
BALL_INLINE bool isValid() const
BALL_INLINE const Composite * getPosition() const
BALL_INLINE bool isEnd() const
bool applyLevel(UnaryProcessor< T > &processor, long level)
Composite * findNextPosition(Composite *p) const
BALL_INLINE const Composite * getContainer() const
BALL_INLINE const Composite & getData() const
AncestorConstIterator endAncestor() const
ChildCompositeConstIterator beginChildComposite() const
BALL_INLINE bool isEnd() const
BALL_INLINE Composite * getPosition()
ForwardIterator< Composite, Composite, Composite *, AncestorIteratorTraits > AncestorIterator
BALL_INLINE Composite *const & getPosition() const
BALL_INLINE const Composite & getData() const