graph  4.7.0
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 __attribute__((__deprecated__));
82  virtual size_t childrenSize() const;
83 
84 protected:
85 
86 private:
87  void recurseElementsWith( const std::string&, bool, const Tree *,
88  std::set< Tree * >& ) const;
89 
90  template< class T >
91  void recurseElementsWith( const std::string&, const T&, bool, const Tree *,
92  std::set< Tree * >& ) const;
93 };
94 
95 
96 //--- inline methods ----------------------------------------------------------
97 
98 inline Tree::Tree( bool allowChildren, const std::string & str )
99  : carto::AttributedObject( str ), BaseTree( allowChildren )
100 {
101 }
102 
103 
104 template< class T >
105 inline
106 void
107 Tree::recurseElementsWith( const std::string& s, const T& t, bool recurse,
108  const Tree *p, std::set< Tree * >& trees ) const
109 {
110  for ( const_iterator e = p->begin(); e != p->end(); ++e )
111  {
112  Tree *ao;
113 
114  if ( ( ao = dynamic_cast< Tree * >( *e ) ) != 0 )
115  {
116  if ( ao->hasProperty( s ) )
117  {
118  T tmp;
119 
120  if ( ao->getProperty( s, tmp ) && tmp == t )
121  trees.insert( ao );
122  }
123 
124  if ( recurse )
125  recurseElementsWith( s, t, recurse, ao, trees );
126  }
127  }
128 }
129 
130 
131 template< class T >
132 inline
133 std::set< Tree * >
134 Tree::getElementsWith( const std::string& s, const T& t, bool recurse ) const
135 {
136  std::set< Tree * > trees;
137 
138  recurseElementsWith( s, t, recurse, this, trees );
139 
140  return trees;
141 }
142 
143 
144 namespace carto
145 {
146  // type needed in anatomist
148 }
149 
150 
151 #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:98
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)