options_list.hpp
Go to the documentation of this file.
1 /*
2  * This file is part of ACADO Toolkit.
3  *
4  * ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.
5  * Copyright (C) 2008-2014 by Boris Houska, Hans Joachim Ferreau,
6  * Milan Vukov, Rien Quirynen, KU Leuven.
7  * Developed within the Optimization in Engineering Center (OPTEC)
8  * under supervision of Moritz Diehl. All rights reserved.
9  *
10  * ACADO Toolkit is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 3 of the License, or (at your option) any later version.
14  *
15  * ACADO Toolkit is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with ACADO Toolkit; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  *
24  */
25 
26 
32 #ifndef ACADO_TOOLKIT_OPTIONS_LIST_HPP
33 #define ACADO_TOOLKIT_OPTIONS_LIST_HPP
34 
36 
37 #include <map>
38 #include <memory>
39 
41 
44 {
45  OIT_UNKNOWN = -1,
49 };
50 
68 {
69  //
70  // PUBLIC MEMBER FUNCTIONS:
71  //
72  public:
73 
74 
75 
78  OptionsList( );
79 
85  );
86 
89  ~OptionsList( );
90 
95  OptionsList& operator=( const OptionsList& rhs
96  );
97 
108  template< typename T >
110  const T& value );
111 
121  template< typename T >
122  inline returnValue get( OptionsName name,
123  T& value
124  ) const;
125 
136  template< typename T >
137  inline returnValue set( OptionsName name,
138  const T& value
139  );
140 
145  inline uint getNumber( ) const;
146 
147 
156  inline BooleanType hasOption( OptionsName name,
157  OptionsItemType type
158  ) const;
159 
160 
166  inline BooleanType haveOptionsChanged( ) const;
167 
173 
174 
179  returnValue printOptionsList( ) const;
180 
181  //
182  // DATA MEMBERS:
183  //
184  private:
185 
188 
191  {
192  virtual void print( std::ostream& stream ) = 0;
193  };
194 
196  template< typename T >
197  struct OptionValue : public OptionValueBase
198  {
199  OptionValue( const T& _value )
200  : value( _value )
201  {}
202 
203  virtual void print( std::ostream& stream )
204  {
205  stream << value;
206  }
207 
209  };
210 
212  typedef std::map<std::pair<OptionsName, OptionsItemType>, std::shared_ptr< OptionValueBase > > OptionItems;
214  OptionItems items;
216  template< typename T >
217  inline OptionsItemType getType() const;
218 };
219 
220 template< typename T >
222 { return OIT_UNKNOWN; }
223 
224 template<>
225 inline OptionsItemType OptionsList::getType< int >() const
226 { return OIT_INT; }
227 
228 template<>
229 inline OptionsItemType OptionsList::getType< double >() const
230 { return OIT_DOUBLE; }
231 
232 template<>
234 { return OIT_STRING; }
235 
236 template< typename T >
238  const T& value
239  )
240 {
241  if (getType< T >() == OIT_UNKNOWN)
243 
244  items[ std::make_pair(name, getType< T >()) ] =
245  std::shared_ptr< OptionValue< T > > (new OptionValue< T >( value ));
246 
247  return SUCCESSFUL_RETURN;
248 }
249 
250 template< typename T >
252  T& value
253  ) const
254 {
255  if (getType< T >() == OIT_UNKNOWN)
257 
258  OptionItems::const_iterator it = items.find(std::make_pair(name, getType< T >()));
259  if (it != items.end())
260  {
261  std::shared_ptr< OptionValue< T > > ptr;
262  ptr = std::static_pointer_cast< OptionValue< T > >(it->second);
263  value = ptr->value;
264  return SUCCESSFUL_RETURN;
265  }
266 
268 }
269 
270 template< typename T >
272  const T& value
273  )
274 {
275  if (getType< T >() == OIT_UNKNOWN)
277 
278  OptionItems::const_iterator it = items.find(std::make_pair(name, getType< T >()));
279  if (it != items.end())
280  {
281  items[ std::make_pair(name, getType< T >()) ] =
282  std::shared_ptr< OptionValue< T > > (new OptionValue< T >( value ));
283 
285 
286  return SUCCESSFUL_RETURN;
287  }
288 
290 }
291 
293 
294 #include <acado/user_interaction/options_list.ipp>
295 
296 #endif // ACADO_TOOLKIT_OPTIONS_LIST_HPP
297 
298 /*
299  * end of file
300  */
BooleanType hasOption(OptionsName name, OptionsItemType type) const
USING_NAMESPACE_ACADO typedef TaylorVariable< Interval > T
OptionsItemType getType() const
Allows to pass back messages to the calling function.
OptionsList & operator=(const OptionsList &rhs)
BEGIN_NAMESPACE_ACADO typedef unsigned int uint
Definition: acado_types.hpp:42
#define CLOSE_NAMESPACE_ACADO
returnValue set(OptionsName name, const T &value)
BooleanType haveOptionsChanged() const
OptionsItemType
returnValue printOptionsList() const
BooleanType optionsHaveChanged
virtual void print(std::ostream &stream)
returnValue get(OptionsName name, T &value) const
Provides a generic list of options (for internal use).
void rhs(const real_t *x, real_t *f)
returnValue declareOptionsUnchanged()
std::map< std::pair< OptionsName, OptionsItemType >, std::shared_ptr< OptionValueBase > > OptionItems
#define BT_TRUE
Definition: acado_types.hpp:47
OptionsItemType OptionsList::getType< std::string >() const
uint getNumber() const
returnValue add(OptionsName name, const T &value)
#define BEGIN_NAMESPACE_ACADO
OptionItems items
virtual void print(std::ostream &stream)=0
OptionsName
OptionValue(const T &_value)
#define ACADOERROR(retval)


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:34:55