graph 6.0.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
46#include <cartobase/object/attributed.h>
47#include <cartobase/object/syntax.h>
48
49
50//--- forward declarations ----------------------------------------------------
51
52class TreeVisitor;
54
55
56//--- class declarations ------------------------------------------------------
57
61{
62public:
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
88protected:
89
90private:
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
102inline Tree::Tree( bool allowChildren, const std::string & str )
103 : carto::AttributedObject( str ), BaseTree( allowChildren )
104{
105}
106
107
108template< class T >
109inline
110void
111Tree::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
135template< class T >
136inline
137std::set< Tree * >
138Tree::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
148namespace carto
149{
150 // type needed in anatomist
152}
153
154
155#endif
#define __deprecated__(msg)
#define __attribute__(a)
BaseTree(bool allowsChildren=true)
Constructor.
Definition base.h:125
const_iterator end() const
Definition base.h:179
std::list< BaseTree * >::const_iterator const_iterator
Definition base.h:57
const_iterator begin() const
Definition base.h:173
Abstract base class for visiting constant Trees.
Definition tvisitor.h:94
Abstract base class for visiting Trees.
Definition tvisitor.h:58
Attributed tree element.
Definition tree.h:61
virtual ~Tree()
virtual bool check(const carto::SyntaxSet &syntax, std::set< std::string > &missing) const
virtual size_t childrenSize() const
Returns the number of children BaseTree the receiver contains.
virtual size_t size() const __attribute__((__deprecated__))
deprecated
virtual void const_accept(ConstTreeVisitor &visitor) const
std::set< Tree * > getElementsWith(const std::string &, bool recurse=true) const
Tree(bool allowChildren=true, const std::string &str="")
Definition tree.h:102
virtual void accept(TreeVisitor &visitor)
#define GRAPH_API
SyntaxedObject< PropertySet > AttributedObject
std::map< std::string, Syntax > SyntaxSet
#define DECLARE_GENERIC_OBJECT_TYPE(T)