cartobase 6.0.6
algorithm.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 CARTOBASE_ALGORITHM_ALGORITHM_H
35#define CARTOBASE_ALGORITHM_ALGORITHM_H
36
37
38//===========================================================================//
39// //
40// WARNING : All code here is under construction. Do not use it. //
41// //
42//===========================================================================//
43
44
47
48namespace carto {
49
50 //-----------------//
51 // BaseParameter //
52//-----------------//
53
55{
56public:
57 virtual ~BaseParameter();
58};
59
60
61 //----------------//
62 // Parameter<T> //
63//----------------//
64
65template <typename T>
67
68template <typename T>
70{
71 public:
72 inline Parameter() {}
73 inline Parameter( T &ref, const std::string &name,
74 const std::string &doc ) :
75 _pValue( &ref ),
76 _name( name ),
77 _documentation( doc ) {}
78 virtual ~Parameter();
79
80 private:
81
82 friend class ParameterModifier<T>;
83
84 T *_pValue;
85 std::string _name;
86 std::string _documentation;
87 bool _input;
88 bool _output;
89 std::vector< std::pair< std::string, T > > _choices;
90 bool _optional;
91};
92
93
94 //-------------//
95 // Algorithm //
96//-------------//
97
99{
100public:
101
102 Algorithm( const std::string &name );
103
104
105protected:
106
107 template <typename T>
108 ParameterModifier<T> inputParameter( T &ref, const std::string &name,
109 const std::string &documentation );
110 template <typename T>
111 ParameterModifier<T> outputParameter( T &ref, const std::string &name,
112 const std::string &documentation );
113
114private:
115
116 std::string _name;
117
118 // It is not going to be a vector in the future, maybe a kind of ParameterSet
119 std::vector< rc_ptr< BaseParameter > > _parameters;
120};
121
122
123 //------------------------//
124 // ParameterModifier<T> //
125//------------------------//
126
127template <typename T>
129{
130public:
131
133 _parameter( pm._parameter ) {}
134
136 _parameter( p ) {}
137
138 inline ParameterModifier<T> optional( bool o = true )
139 {
140 _parameter._optional = o;
141 return *this;
142 }
143
144 inline ParameterModifier<T> choice( const T &value )
145 {
146 return choices( "", value );
147 }
148
149 inline ParameterModifier<T> choice( const std::string &label,
150 const T &value )
151 {
152 _parameter._choices.push_back( std::pair<std::string, T>( label,
153 value ) );
154 return *this;
155 }
156
157 private:
158
159 Parameter<T> &_parameter;
160};
161
162
163 //-------------------//
164 // AlgorithmCaller //
165//-------------------//
166
168{
169public:
170
171 AlgorithmCaller( const std::string &algorithmName );
172 template <typename T>
173 AlgorithmCaller &operator <<( const T & );
174
176
177private:
178
179 std::string _name;
180 std::vector< carto::Object > _unnamedParameters;
181 carto::Object _namedParameters;
182};
183
185
187
188
189
190
191
192 //----------------//
193 // Parameter<T> //
194//----------------//
195
196//-----------------------------------------------------------------------------
197template <typename T>
199
200
201 //-------------//
202 // Algorithm //
203//-------------//
204
205//-----------------------------------------------------------------------------
206template <typename T>
208Algorithm::inputParameter( T &ref, const std::string &name,
209 const std::string &doc )
210{
211 _parameters.push_back( rc_ptr<BaseParameter>( new Parameter<T>( ref, name, doc ) ) );
212 // TODO set _input = true;
213 return ParameterModifier<T>( static_cast< Parameter<T> &>( *_parameters.rbegin()->get() ) );
214}
215
216
217//-----------------------------------------------------------------------------
218template <typename T>
220Algorithm::outputParameter( T &ref, const std::string &name,
221 const std::string &doc )
222{
223 _parameters.push_back( rc_ptr<BaseParameter>( new Parameter<T>( ref, name, doc ) ) );
224 // TODO set _output = true;
225 return ParameterModifier<T>( static_cast< Parameter<T> &>( *_parameters.rbegin()->get() ) );
226}
227
228
229 //-------------------//
230 // AlgorithmCaller //
231//-------------------//
232
233template <typename T>
235{
236 _unnamedParameters.push_back( Object::value( v ) );
237 return *this;
238}
239
240template <>
243
244
245
246} // namespace carto
247
248
249#endif //ifndef CARTOBASE_ALGORITHM_ALGORITHM_H
AlgorithmCaller & operator<<(const T &)
Definition algorithm.h:234
AlgorithmCaller(const std::string &algorithmName)
Algorithm(const std::string &name)
ParameterModifier< T > outputParameter(T &ref, const std::string &name, const std::string &documentation)
Definition algorithm.h:220
ParameterModifier< T > inputParameter(T &ref, const std::string &name, const std::string &documentation)
Definition algorithm.h:208
virtual ~BaseParameter()
static Object value()
factory function: builds an Object by using the default constructor
Definition object.h:1496
ParameterModifier(const ParameterModifier< T > &pm)
Definition algorithm.h:132
ParameterModifier< T > choice(const std::string &label, const T &value)
Definition algorithm.h:149
ParameterModifier(Parameter< T > &p)
Definition algorithm.h:135
ParameterModifier< T > optional(bool o=true)
Definition algorithm.h:138
ParameterModifier< T > choice(const T &value)
Definition algorithm.h:144
Parameter(T &ref, const std::string &name, const std::string &doc)
Definition algorithm.h:73
virtual ~Parameter()
Definition algorithm.h:198
Reference-counting pointer.
Definition rcptr.h:640
A ref is a const_ref which can reference non constant objects.
Definition rcptr.h:467
const AlgorithmCaller::LaunchExecution execute
AlgorithmCaller algo
Definition algorithm.h:186