Skip to content

Commit

Permalink
fix for external C functions an string arrays in cpp runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
niklwors authored and unknown committed Nov 9, 2015
1 parent 460260f commit 186cf15
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
20 changes: 20 additions & 0 deletions SimulationRuntime/cpp/Core/Math/ArrayOperations.cpp
Expand Up @@ -465,6 +465,23 @@ 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,
* including optional type conversion if supported in assignment from S to T
Expand Down Expand Up @@ -624,6 +641,9 @@ 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
8 changes: 8 additions & 0 deletions SimulationRuntime/cpp/Include/Core/Math/Array.h
Expand Up @@ -169,6 +169,14 @@ 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 186cf15

Please sign in to comment.