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)
222 void set(const
Composite& composite,
bool deep = true) ;
236 void get(
Composite& composite,
bool deep = true) const ;
253 Size countDescendants() 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 ;
483 Composite& last,
bool destroy_parent = true)
606 virtual
void select() ;
616 virtual
void deselect() ;
639 bool isEmpty() const ;
644 bool isRoot() const ;
652 bool isInterior() const ;
656 bool hasChild() const ;
664 bool isFirstChild() const ;
672 bool isLastChild() const ;
680 bool hasParent() const ;
689 bool hasSibling() const ;
698 bool hasPreviousSibling() const ;
702 bool isPreviousSiblingOf(const
Composite& composite) const ;
707 bool hasNextSibling() const ;
711 bool isNextSiblingOf(const
Composite& composite) const ;
719 template <typename T>
720 bool hasAncestor(const T& dummy) const ;
745 bool containsSelection() const ;
757 virtual
bool isAtom()
const {
return false; }
782 virtual bool isChain()
const {
return false; }
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_;
1050 typedef ForwardIterator <Composite, Composite, Composite*, AncestorIteratorTraits>
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);
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>
2128 return dynamic_cast<T*
>(ptr);
2131 template <
typename T>
2139 return const_cast<const T*
>(nonconst_this->
getPrevious(dummy));
2142 template <
typename T>
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>
#define BALL_CREATE_DEEP(name)
bool isKindOf(const U *u)
BALL_INLINE const Traits & getTraits() const
Get a constant reference to the traits of this iterator.
BALL_INLINE bool isValid() const
Mutable bidirectional iterator.
bool applyLevel(UnaryProcessor< T > &processor, long level)
bool applyDescendantPostorder(UnaryProcessor< T > &processor)
BidirectionalIterator< Composite, Composite, Composite *, ChildCompositeIteratorTraits > ChildCompositeIterator
CompositeReverseIterator rendComposite()
bool applyAncestor(UnaryProcessor< T > &processor)
ChildCompositeConstIterator beginChildComposite() const
T * getPrevious(const T &)
std::reverse_iterator< ChildCompositeConstIterator > ChildCompositeConstReverseIterator
AncestorConstIterator endAncestor() const
bool hasAncestor(const T &dummy) const
BidirectionalIterator< Composite, Composite, Composite *, CompositeIteratorTraits > CompositeIterator
ChildCompositeConstReverseIterator rbeginChildComposite() const
bool applyDescendant(UnaryProcessor< T > &processor)
ChildCompositeConstReverseIterator rendChildComposite() const
virtual bool isChain() const
std::reverse_iterator< CompositeIterator > CompositeReverseIterator
ConstBidirectionalIterator< Composite, Composite, Composite *, ChildCompositeIteratorTraits > ChildCompositeConstIterator
virtual void dump(std::ostream &s=std::cout, Size depth=0) const
CompositeReverseIterator rbeginComposite()
virtual bool isResidue() const
ChildCompositeIterator endChildComposite()
UnaryPredicate< Composite > KernelPredicateType
std::reverse_iterator< CompositeConstIterator > CompositeConstReverseIterator
ChildCompositeConstIterator endChildComposite() const
bool applyDescendantPreorder(UnaryProcessor< T > &processor)
CompositeIterator endComposite()
ChildCompositeIterator beginChildComposite()
bool applyChild(UnaryProcessor< T > &processor)
CompositeConstIterator beginComposite() const
virtual bool isValid() const
CompositeConstIterator endComposite() const
virtual bool isProtein() const
virtual bool isFragment() const
AncestorIterator beginAncestor()
ChildCompositeReverseIterator rendChildComposite()
virtual bool isMolecule() const
CompositeConstReverseIterator rbeginComposite() const
bool apply(ConstUnaryProcessor< T > &processor) const
AncestorIterator endAncestor()
void host(Visitor< Composite > &visitor)
bool apply(UnaryProcessor< T > &processor)
CompositeConstReverseIterator rendComposite() const
ForwardIterator< Composite, Composite, Composite *, AncestorIteratorTraits > AncestorIterator
bool applyPostorder(UnaryProcessor< T > &processor)
AncestorConstIterator beginAncestor() const
std::reverse_iterator< ChildCompositeIterator > ChildCompositeReverseIterator
ConstBidirectionalIterator< Composite, Composite, Composite *, CompositeIteratorTraits > CompositeConstIterator
T * getAncestor(const T &)
ChildCompositeReverseIterator rbeginChildComposite()
ConstForwardIterator< Composite, Composite, Composite *, AncestorIteratorTraits > AncestorConstIterator
bool applyPreorder(UnaryProcessor< T > &processor)
void deleteChildrenList_(std::list< Composite * > &composites)
CompositeIterator beginComposite()
BALL_INLINE AncestorIteratorTraits()
BALL_INLINE void invalidate()
BALL_INLINE bool isEnd() const
BALL_INLINE bool isValid() const
BALL_INLINE void toBegin()
BALL_INLINE Composite & getData()
BALL_INLINE void forward()
BALL_INLINE AncestorIteratorTraits(const Composite &composite)
BALL_INLINE bool isSingular() const
BALL_INLINE Composite * getContainer()
BALL_INLINE Composite *const & getPosition() const
BALL_INLINE AncestorIteratorTraits(const AncestorIteratorTraits &traits)
BALL_INLINE const Composite * getContainer() const
BALL_INLINE bool isBegin() const
BALL_INLINE const Composite & getData() const
BALL_INLINE Composite * getPosition()
BALL_INLINE bool isSingular() const
BALL_INLINE Composite * getContainer()
BALL_INLINE const Composite & getData() const
ChildCompositeIteratorTraits(const ChildCompositeIteratorTraits &traits)
BALL_INLINE bool isREnd() const
BALL_INLINE Composite * getPosition()
BALL_INLINE void forward()
BALL_INLINE bool isEnd() const
BALL_INLINE Composite *const & getPosition() const
BALL_INLINE void toRBegin()
ChildCompositeIteratorTraits(const Composite &composite)
BALL_INLINE Composite & getData()
BALL_INLINE const Composite * getContainer() const
BALL_INLINE void toREnd()
BALL_INLINE void toBegin()
BALL_INLINE bool isValid() const
BALL_INLINE bool isBegin() const
BALL_INLINE bool isRBegin() const
BALL_INLINE void backward()
BALL_INLINE void invalidate()
ChildCompositeIteratorTraits()
BALL_INLINE bool isREnd() const
BALL_INLINE Composite * getContainer()
BALL_INLINE void toRBegin()
BALL_INLINE void toREnd()
BALL_INLINE void invalidate()
BALL_INLINE const Composite & getData() const
BALL_INLINE Composite * getPosition()
CompositeIteratorTraits(const CompositeIteratorTraits &traits)
Composite * findNextPosition(Composite *p) const
BALL_INLINE Composite & getData()
Composite * position_
The current iterator position.
BALL_INLINE bool isSingular() const
BALL_INLINE ~CompositeIteratorTraits()
BALL_INLINE void forward()
BALL_INLINE CompositeIteratorTraits()
BALL_INLINE void toBegin()
BALL_INLINE bool isBegin() const
Composite * findPreviousPosition(Composite *p) const
CompositeIteratorTraits(const Composite &composite)
BALL_INLINE bool isRBegin() const
BALL_INLINE bool isEnd() const
BALL_INLINE bool isValid() const
BALL_INLINE const Composite * getContainer() const
BALL_INLINE const Composite * getPosition() const
BALL_INLINE void setPosition(Composite *position)
BALL_INLINE void backward()
Composite * bound_
A pointer to the "container" the iterator is bound to.