options_list.hpp
Go to the documentation of this file.
00001 /*
00002  *    This file is part of ACADO Toolkit.
00003  *
00004  *    ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.
00005  *    Copyright (C) 2008-2014 by Boris Houska, Hans Joachim Ferreau,
00006  *    Milan Vukov, Rien Quirynen, KU Leuven.
00007  *    Developed within the Optimization in Engineering Center (OPTEC)
00008  *    under supervision of Moritz Diehl. All rights reserved.
00009  *
00010  *    ACADO Toolkit is free software; you can redistribute it and/or
00011  *    modify it under the terms of the GNU Lesser General Public
00012  *    License as published by the Free Software Foundation; either
00013  *    version 3 of the License, or (at your option) any later version.
00014  *
00015  *    ACADO Toolkit is distributed in the hope that it will be useful,
00016  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  *    Lesser General Public License for more details.
00019  *
00020  *    You should have received a copy of the GNU Lesser General Public
00021  *    License along with ACADO Toolkit; if not, write to the Free Software
00022  *    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00023  *
00024  */
00025 
00026 
00032 #ifndef ACADO_TOOLKIT_OPTIONS_LIST_HPP
00033 #define ACADO_TOOLKIT_OPTIONS_LIST_HPP
00034 
00035 #include <acado/utils/acado_utils.hpp>
00036 
00037 #include <map>
00038 #ifdef _WIN32
00039     #include <memory>
00040 #else
00041     #include <tr1/memory>
00042 #endif
00043 
00044 BEGIN_NAMESPACE_ACADO
00045 
00047 enum OptionsItemType
00048 {
00049         OIT_UNKNOWN     = -1,   
00050         OIT_INT,                        
00051         OIT_DOUBLE,                     
00052         OIT_STRING                      
00053 };
00054 
00071 class OptionsList
00072 {
00073         //
00074         // PUBLIC MEMBER FUNCTIONS:
00075         //
00076         public:
00077 
00078 
00079 
00082                 OptionsList( );
00083 
00088                 OptionsList(    const OptionsList& rhs
00089                                                 );
00090 
00093                 ~OptionsList( );
00094 
00099                 OptionsList& operator=( const OptionsList& rhs
00100                                                                 );
00101 
00112                 template< typename T >
00113                 inline returnValue add( OptionsName name,
00114                                                                 const T& value );
00115 
00125                 template< typename T >
00126                 inline returnValue get( OptionsName name,
00127                                                                 T& value
00128                                                                 ) const;
00129 
00140                 template< typename T >
00141                 inline returnValue set( OptionsName name,
00142                                                                 const T& value
00143                                                                 );
00144 
00149                 inline uint getNumber( ) const;
00150 
00151 
00160                 inline BooleanType hasOption(   OptionsName name,
00161                                                                                 OptionsItemType type
00162                                                                                 ) const;
00163 
00164 
00170                 inline BooleanType haveOptionsChanged( ) const;
00171 
00176                 inline returnValue declareOptionsUnchanged( );
00177 
00178 
00183                 returnValue printOptionsList( ) const;
00184 
00185     //
00186     // DATA MEMBERS:
00187     //
00188         private:
00189 
00191                 BooleanType optionsHaveChanged;
00192 
00194                 struct OptionValueBase
00195                 {
00196                         virtual void print( std::ostream& stream ) = 0;
00197                 };
00198 
00200                 template< typename T >
00201                 struct OptionValue : public OptionValueBase
00202                 {
00203                         OptionValue( const T& _value )
00204                                 : value( _value )
00205                         {}
00206 
00207                         virtual void print( std::ostream& stream )
00208                         {
00209                                 stream << value;
00210                         }
00211 
00212                         T value;
00213                 };
00214 
00216                 typedef std::map<std::pair<OptionsName, OptionsItemType>, std::tr1::shared_ptr< OptionValueBase > > OptionItems;
00218                 OptionItems items;
00220                 template< typename T >
00221                 inline OptionsItemType getType() const;
00222 };
00223 
00224 template< typename T >
00225 inline OptionsItemType OptionsList::getType() const
00226 { return OIT_UNKNOWN; }
00227 
00228 template<>
00229 inline OptionsItemType OptionsList::getType< int >() const
00230 { return OIT_INT; }
00231 
00232 template<>
00233 inline OptionsItemType OptionsList::getType< double >() const
00234 { return OIT_DOUBLE; }
00235 
00236 template<>
00237 inline OptionsItemType OptionsList::getType< std::string >() const
00238 { return OIT_STRING; }
00239 
00240 template< typename T >
00241 inline returnValue OptionsList::add(    OptionsName name,
00242                                                                                 const T& value
00243                                                                                 )
00244 {
00245         if (getType< T >() == OIT_UNKNOWN)
00246                 return ACADOERROR( RET_NOT_IMPLEMENTED_YET );
00247 
00248         items[ std::make_pair(name, getType< T >()) ] =
00249                         std::tr1::shared_ptr< OptionValue< T > > (new OptionValue< T >( value ));
00250 
00251         return SUCCESSFUL_RETURN;
00252 }
00253 
00254 template< typename T >
00255 inline returnValue OptionsList::get(    OptionsName name,
00256                                                                                 T& value
00257                                                                                 ) const
00258 {
00259         if (getType< T >() == OIT_UNKNOWN)
00260                 return ACADOERROR( RET_NOT_IMPLEMENTED_YET );
00261 
00262         OptionItems::const_iterator it = items.find(std::make_pair(name, getType< T >()));
00263         if (it != items.end())
00264         {
00265                 std::tr1::shared_ptr< OptionValue< T > > ptr;
00266                 ptr = std::tr1::static_pointer_cast< OptionValue< T > >(it->second);
00267                 value = ptr->value;
00268                 return SUCCESSFUL_RETURN;
00269         }
00270 
00271         return ACADOERROR( RET_OPTION_DOESNT_EXIST );
00272 }
00273 
00274 template< typename T >
00275 inline returnValue OptionsList::set(    OptionsName name,
00276                                                                                 const T& value
00277                                                                                 )
00278 {
00279         if (getType< T >() == OIT_UNKNOWN)
00280                 return ACADOERROR( RET_NOT_IMPLEMENTED_YET );
00281 
00282         OptionItems::const_iterator it = items.find(std::make_pair(name, getType< T >()));
00283         if (it != items.end())
00284         {
00285                 items[ std::make_pair(name, getType< T >()) ] =
00286                                 std::tr1::shared_ptr< OptionValue< T > > (new OptionValue< T >( value ));
00287 
00288                 optionsHaveChanged = BT_TRUE;
00289 
00290                 return SUCCESSFUL_RETURN;
00291         }
00292 
00293         return ACADOERROR( RET_OPTION_DOESNT_EXIST );
00294 }
00295 
00296 CLOSE_NAMESPACE_ACADO
00297 
00298 #include <acado/user_interaction/options_list.ipp>
00299 
00300 #endif  // ACADO_TOOLKIT_OPTIONS_LIST_HPP
00301 
00302 /*
00303  *      end of file
00304  */


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Thu Aug 27 2015 11:59:22