cartobase  5.0.5
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 
48 namespace carto {
49 
50  //-----------------//
51  // BaseParameter //
52 //-----------------//
53 
55 {
56 public:
57  virtual ~BaseParameter();
58 };
59 
60 
61  //----------------//
62  // Parameter<T> //
63 //----------------//
64 
65 template <typename T>
67 
68 template <typename T>
69 class Parameter : public BaseParameter
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 
98 class Algorithm
99 {
100 public:
101 
102  Algorithm( const std::string &name );
103 
104 
105 protected:
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 
114 private:
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 
127 template <typename T>
128 class ParameterModifier
129 {
130 public:
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 {
169 public:
170 
171  AlgorithmCaller( const std::string &algorithmName );
172  template <typename T>
173  AlgorithmCaller &operator <<( const T & );
174 
175  class LaunchExecution {};
176 
177 private:
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 //-----------------------------------------------------------------------------
197 template <typename T>
199 
200 
201  //-------------//
202  // Algorithm //
203 //-------------//
204 
205 //-----------------------------------------------------------------------------
206 template <typename T>
208 Algorithm::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 //-----------------------------------------------------------------------------
218 template <typename T>
220 Algorithm::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 
233 template <typename T>
235 {
236  _unnamedParameters.push_back( Object::value( v ) );
237  return *this;
238 }
239 
240 template <>
243 
244 
245 
246 } // namespace carto
247 
248 
249 #endif //ifndef CARTOBASE_ALGORITHM_ALGORITHM_H
ParameterModifier< T > outputParameter(T &ref, const std::string &name, const std::string &documentation)
Definition: algorithm.h:220
ParameterModifier< T > optional(bool o=true)
Definition: algorithm.h:138
AlgorithmCaller algo
Definition: algorithm.h:186
ParameterModifier(const ParameterModifier< T > &pm)
Definition: algorithm.h:132
std::ostream & operator<<(std::ostream &out, const VoxelValue< T, C > &aa)
Definition: voxelvalue.h:96
virtual ~Parameter()
Definition: algorithm.h:198
ParameterModifier< T > choice(const T &value)
Definition: algorithm.h:144
const AlgorithmCaller::LaunchExecution execute
virtual ~BaseParameter()
Parameter(T &ref, const std::string &name, const std::string &doc)
Definition: algorithm.h:73
Reference-counting pointer.
Definition: rcptr.h:639
ParameterModifier(Parameter< T > &p)
Definition: algorithm.h:135
AlgorithmCaller & operator<<(const T &)
Definition: algorithm.h:234
A ref is a const_ref which can reference non constant objects.
Definition: rcptr.h:79
ParameterModifier< T > inputParameter(T &ref, const std::string &name, const std::string &documentation)
Definition: algorithm.h:208
static Object value()
factory function: builds an Object by using the default constructor
Definition: object.h:1482
ParameterModifier< T > choice(const std::string &label, const T &value)
Definition: algorithm.h:149