graph  5.0.5
Graph: generic attributed relational graphs
tree.h
Go to the documentation of this file.
1 /* This software and supporting documentation are distributed by
2  * Institut Federatif de Recherche 49
3  * CEA/NeuroSpin, Batiment 145,
4  * 91191 Gif-sur-Yvette cedex
5  * France
6  *
7  * This software is governed by the CeCILL-B license under
8  * French law and abiding by the rules of distribution of free software.
9  * You can use, modify and/or redistribute the software under the
10  * terms of the CeCILL-B license as circulated by CEA, CNRS
11  * and INRIA at the following URL "http://www.cecill.info".
12  *
13  * As a counterpart to the access to the source code and rights to copy,
14  * modify and redistribute granted by the license, users are provided only
15  * with a limited warranty and the software's author, the holder of the
16  * economic rights, and the successive licensors have only limited
17  * liability.
18  *
19  * In this respect, the user's attention is drawn to the risks associated
20  * with loading, using, modifying and/or developing or reproducing the
21  * software by the user in light of its specific status of free software,
22  * that may mean that it is complicated to manipulate, and that also
23  * therefore means that it is reserved for developers and experienced
24  * professionals having in-depth computer knowledge. Users are therefore
25  * encouraged to load and test the software's suitability as regards their
26  * requirements in conditions enabling the security of their systems and/or
27  * data to be ensured and, more generally, to use and operate it in the
28  * same conditions as regards security.
29  *
30  * The fact that you are presently reading this means that you have had
31  * knowledge of the CeCILL-B license and that you accept its terms.
32  */
33 
34 #ifndef GRAPH_TREE_TREE_H
35 #define GRAPH_TREE_TREE_H
36 
37 
38 //--- header files ------------------------------------------------------------
39 
41 #include <set>
42 
43 #ifndef GRAPH_TREE_BASE_H
44 #include <graph/tree/base.h>
45 #endif
48 
49 
50 //--- forward declarations ----------------------------------------------------
51 
52 class TreeVisitor;
53 class ConstTreeVisitor;
54 
55 
56 //--- class declarations ------------------------------------------------------
57 
61 {
62 public:
63  Tree( bool allowChildren=true, const std::string & str="" );
64  virtual ~Tree();
65 
68  virtual void accept( TreeVisitor & visitor );
69  virtual void const_accept( ConstTreeVisitor & visitor ) const;
71 
72  virtual bool check (const carto::SyntaxSet& syntax,
73  std::set<std::string>& missing) const;
74 
75  std::set< Tree * > getElementsWith( const std::string&,
76  bool recurse=true ) const;
77  template< class T >
78  std::set< Tree * > getElementsWith( const std::string&, const T&,
79  bool recurse=true ) const;
81  virtual size_t size() const
82 #ifndef AIMS_GRAPH_SIZE_NO_DEPREC_WARNING
84 #endif
85  ;
86  virtual size_t childrenSize() const;
87 
88 protected:
89 
90 private:
91  void recurseElementsWith( const std::string&, bool, const Tree *,
92  std::set< Tree * >& ) const;
93 
94  template< class T >
95  void recurseElementsWith( const std::string&, const T&, bool, const Tree *,
96  std::set< Tree * >& ) const;
97 };
98 
99 
100 //--- inline methods ----------------------------------------------------------
101 
102 inline Tree::Tree( bool allowChildren, const std::string & str )
103  : carto::AttributedObject( str ), BaseTree( allowChildren )
104 {
105 }
106 
107 
108 template< class T >
109 inline
110 void
111 Tree::recurseElementsWith( const std::string& s, const T& t, bool recurse,
112  const Tree *p, std::set< Tree * >& trees ) const
113 {
114  for ( const_iterator e = p->begin(); e != p->end(); ++e )
115  {
116  Tree *ao;
117 
118  if ( ( ao = dynamic_cast< Tree * >( *e ) ) != 0 )
119  {
120  if ( ao->hasProperty( s ) )
121  {
122  T tmp;
123 
124  if ( ao->getProperty( s, tmp ) && tmp == t )
125  trees.insert( ao );
126  }
127 
128  if ( recurse )
129  recurseElementsWith( s, t, recurse, ao, trees );
130  }
131  }
132 }
133 
134 
135 template< class T >
136 inline
137 std::set< Tree * >
138 Tree::getElementsWith( const std::string& s, const T& t, bool recurse ) const
139 {
140  std::set< Tree * > trees;
141 
142  recurseElementsWith( s, t, recurse, this, trees );
143 
144  return trees;
145 }
146 
147 
148 namespace carto
149 {
150  // type needed in anatomist
152 }
153 
154 
155 #endif
#define DECLARE_GENERIC_OBJECT_TYPE(T)
#define __deprecated__(msg)
Abstract base class for visiting constant Trees.
Definition: tvisitor.h:93
BaseTree element.
Definition: base.h:53
virtual size_t childrenSize() const
Returns the number of children BaseTree the receiver contains.
Definition: base.h:155
Tree(bool allowChildren=true, const std::string &str="")
Definition: tree.h:102
virtual size_t size() const __attribute__((__deprecated__("use childrenSize() for the number of children")))
deprecated - use childrenSize() for the number of children.
Definition: base.h:149
#define GRAPH_API
Definition: graph_config.h:46
std::list< BaseTree * >::const_iterator const_iterator
Definition: base.h:57
std::set< Tree *> getElementsWith(const std::string &, bool recurse=true) const
Abstract base class for visiting Trees.
Definition: tvisitor.h:57
std::map< std::string, Syntax > SyntaxSet
SyntaxedObject< PropertySet > AttributedObject
const_iterator end() const
Definition: base.h:179
Attributed tree element.
Definition: tree.h:60
const_iterator begin() const
Definition: base.h:173
#define __attribute__(a)