export_index_node.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_index_node.hpp>
00026 #include <sstream>
00027 
00028 BEGIN_NAMESPACE_ACADO
00029 
00030 using namespace std;
00031 
00032 
00033 returnValue ExportIndexNode::exportDataDeclaration(     std::ostream& stream,
00034                                                                                                         const std::string& _realString,
00035                                                                                                         const std::string& _intString,
00036                                                                                                         int _precision
00037                                                                                                         ) const
00038 {
00039         if (isGiven() == true)
00040                 return ACADOERRORTEXT(RET_UNABLE_TO_EXPORT_CODE, "Declaration of given indices is not supported.");
00041         else if (isBinary() == true)
00042                 return ACADOERRORTEXT(RET_UNABLE_TO_EXPORT_CODE, "Declaration of binary node indices is not supported.");
00043 
00044         stream << _intString << " " << getFullName() << ";" << endl;
00045 
00046         return SUCCESSFUL_RETURN;
00047 }
00048 
00049 
00050 const std::string ExportIndexNode::get( ) const
00051 {
00052         stringstream s;
00053 
00054         switch ( varType )
00055         {
00056         case EVT_VALUE:
00057                 s << value;
00058                 break;
00059 
00060         case EVT_VARIABLE:
00061                 if (factor == 1)
00062                         s << getFullName();
00063                 else
00064                         s << getFullName() << " * " << factor;
00065 
00066                 if (offset > 0)
00067                         s << " + " << offset;
00068                 else if (offset < 0)
00069                         s << offset;
00070 
00071                 break;
00072 
00073         case EVT_BINARY_OPERATOR:
00074 
00075                 s << "(" << left.get() << ")";
00076                 switch ( op )
00077                 {
00078                 case ESO_ADD:
00079                         s << " + ";
00080                         break;
00081 
00082                 case ESO_SUBTRACT:
00083                         s << " - ";
00084                         break;
00085 
00086                 case ESO_MULTIPLY:
00087                         s << " * ";
00088                         break;
00089 
00090                 case ESO_DIVIDE:
00091                         s << " / ";
00092                         break;
00093                 case ESO_MODULO:
00094                         s << " % ";
00095                         break;
00096                 }
00097                 s << "(" << right.get() << ")";
00098                 break;
00099         }
00100 
00101         return s.str();
00102 }
00103 
00104 
00105 const int ExportIndexNode::getGivenValue( ) const
00106 {
00107         if (varType == EVT_VALUE)
00108                 return value;
00109 
00110         if (varType == EVT_VARIABLE)
00111                 return -1;
00112 
00113         switch ( op )
00114         {
00115         case ESO_ADD:
00116                 return left.getGivenValue() + right.getGivenValue();
00117 
00118         case ESO_SUBTRACT:
00119                 return left.getGivenValue() - right.getGivenValue();
00120 
00121         case ESO_MULTIPLY:
00122                 return left.getGivenValue() * right.getGivenValue();
00123 
00124         case ESO_DIVIDE:
00125                 return left.getGivenValue() / right.getGivenValue();
00126 
00127         case ESO_MODULO:
00128                 return left.getGivenValue() % right.getGivenValue();
00129 
00130         default:
00131                 return 0;
00132         }
00133 }
00134 
00135 
00136 bool ExportIndexNode::isGiven( ) const
00137 {
00138         if (varType == EVT_VALUE)
00139                 return true;
00140 
00141         return false;
00142 }
00143 
00144 
00145 CLOSE_NAMESPACE_ACADO


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Sat Jun 8 2019 19:37:01