Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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