export_data_internal.cpp
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 #include <acado/code_generation/export_data_internal.hpp>
00026 
00027 BEGIN_NAMESPACE_ACADO
00028 
00029 using namespace CasADi;
00030 
00031 
00032 //
00033 // PUBLIC MEMBER FUNCTIONS:
00034 //
00035 
00036 ExportDataInternal::ExportDataInternal( const std::string& _name,
00037                                                                                 ExportType _type,
00038                                                                                 ExportStruct _dataStruct,
00039                                                                                 const std::string& _prefix
00040                                                                                 )
00041         : SharedObjectNode(), name( _name ), type( _type ), prefix( _prefix ), dataStruct( _dataStruct ),
00042           description()
00043 {
00044         setFullName();
00045 }
00046 
00047 ExportDataInternal::~ExportDataInternal( )
00048 {
00049 }
00050 
00051 returnValue     ExportDataInternal::setName(    const std::string& _name
00052                                                                                         )
00053 {
00054         if ( _name.empty() == true )
00055                 return ACADOERROR( RET_INVALID_ARGUMENTS );
00056 
00057         name = _name;
00058 
00059         setFullName();
00060 
00061         return SUCCESSFUL_RETURN;
00062 }
00063 
00064 
00065 returnValue     ExportDataInternal::setType(    ExportType _type
00066                                                                                         )
00067 {
00068         type = _type;
00069 
00070         setFullName();
00071 
00072         return SUCCESSFUL_RETURN;
00073 }
00074 
00075 returnValue ExportDataInternal::setPrefix(      const std::string& _prefix
00076                                                                                         )
00077 {
00078         prefix = _prefix;
00079 
00080         setFullName();
00081 
00082         return SUCCESSFUL_RETURN;
00083 }
00084 
00085 returnValue     ExportDataInternal::setDataStruct(      ExportStruct _dataStruct
00086                                                                                                 )
00087 {
00088         dataStruct = _dataStruct;
00089 
00090         setFullName();
00091 
00092         return SUCCESSFUL_RETURN;
00093 }
00094 
00095 
00096 
00097 std::string ExportDataInternal::getName( ) const
00098 {
00099         return name;
00100 }
00101 
00102 ExportType ExportDataInternal::getType( ) const
00103 {
00104         return type;
00105 }
00106 
00107 std::string ExportDataInternal::getPrefix() const
00108 {
00109         return prefix;
00110 }
00111 
00112 std::string ExportDataInternal::getTypeString(  const std::string& _realString,
00113                                                                                                 const std::string& _intString
00114                                                                                                 ) const
00115 {
00116         switch ( type )
00117         {
00118         case INT:
00119                 return _intString;
00120 
00121         case REAL:
00122                 return _realString;
00123 
00124         case STATIC_CONST_INT:
00125                 return std::string("static const ") + _intString;
00126 
00127         case STATIC_CONST_REAL:
00128                 return std::string("static const ") + _realString;
00129         }
00130 
00131         return std::string("unknownType");
00132 }
00133 
00134 
00135 ExportStruct ExportDataInternal::getDataStruct( ) const
00136 {
00137         return dataStruct;
00138 }
00139 
00140 
00141 std::string ExportDataInternal::getDataStructString( ) const
00142 {
00143         std::stringstream tmp;
00144 
00145         tmp << prefix;
00146 
00147         if (prefix.empty() == false)
00148                 tmp << "_";
00149 
00150         switch ( dataStruct )
00151         {
00152                 case ACADO_VARIABLES:
00153                         tmp << "acadoVariables";
00154                         break;
00155 
00156                 case ACADO_WORKSPACE:
00157                         tmp << "acadoWorkspace";
00158                         break;
00159 
00160                 case ACADO_PARAMS:
00161                         tmp << "params";
00162                         break;
00163 
00164                 case ACADO_VARS:
00165                         tmp << "vars";
00166                         break;
00167 
00168                 case FORCES_PARAMS:
00169                         tmp << "params";
00170                         break;
00171 
00172                 case FORCES_OUTPUT:
00173                         tmp << "output";
00174                         break;
00175 
00176                 case FORCES_INFO:
00177                         tmp << "info";
00178                         break;
00179 
00180                 default:
00181                         tmp << "";
00182                         break;
00183         }
00184 
00185         return tmp.str();
00186 }
00187 
00188 
00189 std::string ExportDataInternal::getFullName( ) const
00190 {
00191         if ( fullName.empty() == true )
00192                 return name;
00193 
00194         return fullName;
00195 }
00196 
00197 
00198 
00199 //
00200 // PROTECTED MEMBER FUNCTIONS:
00201 //
00202 
00203 
00204 //
00205 // PRIVATE MEMBER FUNCTIONS:
00206 //
00207 
00208 returnValue ExportDataInternal::setFullName()
00209 {
00210         if ( dataStruct == ACADO_LOCAL )
00211         {
00212                 if ( prefix.empty() == false )
00213                 {
00214                         fullName = prefix;
00215                         fullName += std::string("_") + name;
00216                 }
00217                 else
00218                 {
00219                         fullName = "";
00220                 }
00221         }
00222         else
00223         {
00224 //              if ( prefix.isEmpty() == false )
00225 //              {
00226 //                      fullName = prefix;
00227 //                      fullName << "_" << getDataStructstd::string();
00228 //              }
00229 //              else
00230 //              {
00231                         fullName = getDataStructString();
00232 //              }
00233 
00234                 fullName += std::string(".") + name;
00235         }
00236 
00237         return SUCCESSFUL_RETURN;
00238 }
00239 
00240 returnValue ExportDataInternal::setDoc( const std::string& _doc )
00241 {
00242         description = _doc;
00243 
00244         return SUCCESSFUL_RETURN;
00245 }
00246 
00247 std::string ExportDataInternal::getDoc() const
00248 {
00249         return description;
00250 }
00251 
00252 CLOSE_NAMESPACE_ACADO


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