Skip to content

Commit

Permalink
fix for external string in cpp template
Browse files Browse the repository at this point in the history
  • Loading branch information
niklwors authored and unknown committed Nov 19, 2015
1 parent 609f8a7 commit 6d1160c
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 27 deletions.
3 changes: 2 additions & 1 deletion Compiler/Template/CodegenCpp.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4472,7 +4472,7 @@ template extType2(Type type, Boolean isInput, Boolean isArray)
let s = match type
case T_INTEGER(__) then "int"
case T_REAL(__) then "double"
case T_STRING(__) then "const char*"
case T_STRING(__) then "string"/*use string instead of char* for external types*/
case T_BOOL(__) then "int"
case T_ENUMERATION(__) then "int"
case T_ARRAY(__) then extType2(ty,isInput,true)
Expand Down Expand Up @@ -14066,3 +14066,4 @@ end generateMeasureTimeEndCode;

annotation(__OpenModelica_Interface="backend");
end CodegenCpp;

20 changes: 1 addition & 19 deletions SimulationRuntime/cpp/Core/Math/ArrayOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,22 +517,6 @@ static void convertArrayDim(size_t dim,
}
}

/**
Special case to convert std string array to c-string array
*/
static void convertArrayDim(size_t dim,
const BaseArray<string> &s, vector<size_t> &sidx,
BaseArray<const char*> &d, vector<size_t> &didx) {
size_t ndims = s.getNumDims();
size_t size = s.getDim(dim);
for (size_t i = 1; i <= size; i++) {
didx[ndims - dim] = sidx[dim - 1] = i;
if (dim < sidx.size())
convertArrayDim(dim + 1, s, sidx, d, didx);
else
d(didx) = s(sidx).c_str();
}
}

/**
* permutes dims between row and column major storage layout,
Expand Down Expand Up @@ -698,9 +682,7 @@ template void BOOST_EXTENSION_EXPORT_DECL
convertArrayLayout(const BaseArray<int> &s, BaseArray<bool> &d);
template void BOOST_EXTENSION_EXPORT_DECL
convertArrayLayout(const BaseArray<string> &s, BaseArray<string> &d);
///Special case for Modelica external C string arrays. Modelica strings are mapped to const char*
template void BOOST_EXTENSION_EXPORT_DECL
convertArrayLayout(const BaseArray<string> &s, BaseArray<const char*> &d);


template void BOOST_EXTENSION_EXPORT_DECL
assignRowMajorData(const double *data, BaseArray<double> &d);
Expand Down
7 changes: 0 additions & 7 deletions SimulationRuntime/cpp/Include/Core/Math/Array.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,7 @@ class CStrArray
for(size_t i = 0; i < _c_str_array.size(); i++)
_c_str_array[i] = data[i].c_str();
}
///Special case for Modelica external C string arrays. Modelica strings are mapped to const char*
CStrArray(const BaseArray<const char*>& stringArray)
:_c_str_array(stringArray.getNumElems())
{

for(size_t i = 0; i < _c_str_array.size(); i++)
_c_str_array[i] = stringArray(i);
}

/**
* Convert to c_str array
Expand Down

0 comments on commit 6d1160c

Please sign in to comment.