Skip to content

Commit

Permalink
fix for load ini xml file with msvc for cpp runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
niklwors authored and OpenModelica-Hudson committed Sep 14, 2015
1 parent 967f532 commit 2ed0fcd
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 54 deletions.
4 changes: 2 additions & 2 deletions Compiler/Template/CodegenCpp.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -5811,7 +5811,7 @@ end initExtVarsDecl;
template init(SimCode simCode ,Text& extraFuncs,Text& extraFuncsDecl,Text extraFuncsNamespace, Text stateDerVectorName /*=__zDot*/, Boolean useFlatArrayNotation, Text& complexStartExpressions)
::=
match simCode
case SIMCODE(modelInfo = MODELINFO(__)) then
case SIMCODE(modelInfo = MODELINFO(__),makefileParams = MAKEFILE_PARAMS(__)) then
//let () = System.tmpTickReset(0)
let &varDecls = buffer "" /*BUFD*/

Expand All @@ -5828,7 +5828,7 @@ case SIMCODE(modelInfo = MODELINFO(__)) then
void <%lastIdentOfPath(modelInfo.name)%>Initialize::initialize()
{
initializeMemory();
IPropertyReader *reader = new XmlPropertyReader("OMCpp<%fileNamePrefix%>Init.xml");
IPropertyReader *reader = new XmlPropertyReader("<%makefileParams.compileDir%>OMCpp/<%fileNamePrefix%>Init.xml");
reader->readInitialValues(*this, _sim_vars);
initializeFreeVariables();
/*Start complex expressions */
Expand Down
6 changes: 3 additions & 3 deletions SimulationRuntime/cpp/Core/DataExchange/XmlPropertyReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ XmlPropertyReader::~XmlPropertyReader()
void XmlPropertyReader::readInitialValues(IContinuous& system, boost::shared_ptr<ISimVars> sim_vars)
{
using boost::property_tree::ptree;
std::ifstream file(propertyFile.c_str());

if(file)
std::ifstream file;
file.open (propertyFile.c_str(), std::ifstream::in);
if(file.good())
{
double *realVars = sim_vars->getRealVarsVector();
int *intVars = sim_vars->getIntVarsVector();
Expand Down
10 changes: 7 additions & 3 deletions SimulationRuntime/cpp/Core/Math/ArrayOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,19 @@ void cat_array(int k, const vector<const BaseArray<T>*>& x, BaseArray<T>& a)
new_k_dim_size = x[0]->getDims()[k-1];
for(int i = 1; i < n; i++)
{
if(x[0]->getDims().size() != x[i]->getDims().size())
//arrays must have same number of dimensions
if(x[0]->getDims().size() != x[i]->getDims().size())
throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION,"Wrong dimension for input array");
for(int j = 0; j < (k - 1); j++)
//Size matching: Arrays must have identical array sizes with the exception of the size of dimension k
for(int j = 0; j < (k - 1); j++)
{
if (x[0]->getDims()[j] != x[i]->getDims()[j])
throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION,"Wrong size for input array");
}
//calculate new size of dimension k
new_k_dim_size += x[i]->getDims()[k-1];
for(int j = k; j < x[0]->getDims().size(); j++)
//Size matching: Arrays must have identical array sizes with the exception of the size of dimension k
for(int j = k; j < x[0]->getDims().size(); j++)
{
if (x[0]->getDims()[j] != x[i]->getDims()[j])
throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION,"Wrong size for input array");
Expand Down
88 changes: 42 additions & 46 deletions SimulationRuntime/cpp/Include/Core/Math/Array.h
Original file line number Diff line number Diff line change
Expand Up @@ -1490,27 +1490,27 @@ class DynArrayDim1 : public DynArray<T, 1>
public:
DynArrayDim1()
:DynArray<T, 1>()
,_multi_array(DynArray<T, 1>::_multi_array)

{
}

DynArrayDim1(const DynArrayDim1<T>& dynarray)
:DynArray<T, 1>(dynarray)
,_multi_array(DynArray<T, 1>::_multi_array)

{
}

DynArrayDim1(const BaseArray<T>& b)
:DynArray<T, 1>(b)
,_multi_array(DynArray<T, 1>::_multi_array)

{
}

DynArrayDim1(size_t size1)
:DynArray<T, 1>()
,_multi_array(DynArray<T, 1>::_multi_array)

{
_multi_array.resize(boost::extents[size1]);
DynArray<T, 1>::_multi_array.resize(boost::extents[size1]);
}

virtual ~DynArrayDim1()
Expand All @@ -1520,54 +1520,53 @@ class DynArrayDim1 : public DynArray<T, 1>
virtual const T& operator()(const vector<size_t>& idx) const
{
//return _multi_array[idx[0]-1];
return _multi_array.data()[idx[0]-1];
return DynArray<T, 1>::_multi_array.data()[idx[0]-1];
}

virtual T& operator()(const vector<size_t>& idx)
{
//return _multi_array[idx[0]-1];
return _multi_array.data()[idx[0]-1];
return DynArray<T, 1>::_multi_array.data()[idx[0]-1];
}

inline virtual T& operator()(size_t index)
{
//return _multi_array[index-1];
return _multi_array.data()[index-1];
return DynArray<T, 1>::_multi_array.data()[index-1];
}

inline virtual const T& operator()(size_t index) const
{
//return _multi_array[index-1];
return _multi_array.data()[index-1];
return DynArray<T, 1>::_multi_array.data()[index-1];
}

DynArrayDim1<T>& operator=(const DynArrayDim1<T>& b)
{
_multi_array.resize(b.getDims());
_multi_array = b._multi_array;
DynArray<T, 1>::_multi_array.resize(b.getDims());
DynArray<T, 1>::_multi_array = b._multi_array;
return *this;
}

void setDims(size_t size1)
{
_multi_array.resize(boost::extents[size1]);
DynArray<T, 1>::_multi_array.resize(boost::extents[size1]);
}

typedef typename boost::multi_array<T, 1>::const_iterator const_iterator;
typedef typename boost::multi_array<T, 1>::iterator iterator;

iterator begin()
{
return _multi_array.begin();
return DynArray<T, 1>::_multi_array.begin();
}

iterator end()
{
return _multi_array.end();
return DynArray<T, 1>::_multi_array.end();
}

private:
boost::multi_array<T, 1> &_multi_array; // refers to base class

};

/**
Expand All @@ -1580,74 +1579,73 @@ class DynArrayDim2 : public DynArray<T, 2>
public:
DynArrayDim2()
:DynArray<T, 2>()
,_multi_array(DynArray<T, 2>::_multi_array)

{
}

DynArrayDim2(const DynArrayDim2<T>& dynarray)
:DynArray<T, 2>(dynarray)
,_multi_array(DynArray<T, 2>::_multi_array)

{
}

DynArrayDim2(const BaseArray<T>& b)
:DynArray<T, 2>(b)
,_multi_array(DynArray<T, 2>::_multi_array)

{
}

DynArrayDim2(size_t size1, size_t size2)
:DynArray<T, 2>()
,_multi_array(DynArray<T, 2>::_multi_array)

{
_multi_array.resize(boost::extents[size1][size2]);
DynArray<T, 2>::_multi_array.resize(boost::extents[size1][size2]);
}

virtual ~DynArrayDim2() {}

void append(size_t i, const DynArrayDim1<T>& b)
{
_multi_array[i-1] = b._multi_array;
DynArray<T, 2>::_multi_array[i-1] = b._multi_array;
}

DynArrayDim2<T>& operator=(const DynArrayDim2<T>& b)
{
_multi_array.resize(b.getDims());
_multi_array = b._multi_array;
DynArray<T, 2>::_multi_array.resize(b.getDims());
DynArray<T, 2>::_multi_array = b._multi_array;
return *this;
}

virtual const T& operator()(const vector<size_t>& idx) const
{
//return _multi_array[idx[0]-1][idx[1]-1];
return _multi_array.data()[idx[0]-1 + _multi_array.shape()[0]*(idx[1]-1)];
return DynArray<T, 2>::_multi_array.data()[idx[0]-1 + DynArray<T, 2>::_multi_array.shape()[0]*(idx[1]-1)];
}

virtual T& operator()(const vector<size_t>& idx)
{
//return _multi_array[idx[0]-1][idx[1]-1];
return _multi_array.data()[idx[0]-1 + _multi_array.shape()[0]*(idx[1]-1)];
return DynArray<T, 2>::_multi_array.data()[idx[0]-1 + DynArray<T, 2>::_multi_array.shape()[0]*(idx[1]-1)];
}

inline virtual T& operator()(size_t i, size_t j)
{
//return _multi_array[i-1][j-1];
return _multi_array.data()[i-1 + _multi_array.shape()[0]*(j-1)];
return DynArray<T, 2>::_multi_array.data()[i-1 + DynArray<T, 2>::_multi_array.shape()[0]*(j-1)];
}

inline virtual const T& operator()(size_t i, size_t j) const
{
//return _multi_array[i-1][j-1];
return _multi_array.data()[i-1 + _multi_array.shape()[0]*(j-1)];
return DynArray<T, 2>::_multi_array.data()[i-1 + DynArray<T, 2>::_multi_array.shape()[0]*(j-1)];
}

void setDims(size_t size1, size_t size2)
{
_multi_array.resize(boost::extents[size1][size2]);
DynArray<T, 2>::_multi_array.resize(boost::extents[size1][size2]);
}

private:
boost::multi_array<T, 2> &_multi_array; // refers to base class

};

/**
Expand All @@ -1660,60 +1658,58 @@ class DynArrayDim3 : public DynArray<T, 3>
public:
DynArrayDim3()
:DynArray<T, 3>(boost::extents[0][0][0])
,_multi_array(DynArray<T, 3>::_multi_array)

{
}

DynArrayDim3(const BaseArray<T>& b)
:DynArray<T, 3>(b)
,_multi_array(DynArray<T, 3>::_multi_array)

{
}

DynArrayDim3(size_t size1, size_t size2, size_t size3)
:DynArray<T, 3>()
,_multi_array(DynArray<T, 3>::_multi_array)

{
_multi_array.resize(boost::extents[size1][size2][size3]);
DynArray<T, 3>::_multi_array.resize(boost::extents[size1][size2][size3]);
}

virtual ~DynArrayDim3(){}

DynArrayDim3<T>& operator=(const DynArrayDim3<T>& b)
{
_multi_array.resize(b.getDims());
_multi_array = b._multi_array;
DynArray<T, 3>::_multi_array.resize(b.getDims());
DynArray<T, 3>::_multi_array = b._multi_array;
return *this;
}

void setDims(size_t size1, size_t size2, size_t size3)
{
_multi_array.resize(boost::extents[size1][size2][size3]);
DynArray<T, 3>::_multi_array.resize(boost::extents[size1][size2][size3]);
}

virtual const T& operator()(const vector<size_t>& idx) const
{
//return _multi_array[idx[0]-1][idx[1]-1][idx[2]-1];
const size_t *shape = _multi_array.shape();
return _multi_array.data()[idx[0]-1 + shape[0]*(idx[1]-1 + shape[1]*(idx[2]-1))];
const size_t *shape = DynArray<T, 3>::_multi_array.shape();
return DynArray<T, 3>::_multi_array.data()[idx[0]-1 + shape[0]*(idx[1]-1 + shape[1]*(idx[2]-1))];
}

virtual T& operator()(const vector<size_t>& idx)
{
//return _multi_array[idx[0]-1][idx[1]-1][idx[2]-1];
const size_t *shape = _multi_array.shape();
return _multi_array.data()[idx[0]-1 + shape[0]*(idx[1]-1 + shape[1]*(idx[2]-1))];
const size_t *shape = DynArray<T, 3>::_multi_array.shape();
return DynArray<T, 3>::_multi_array.data()[idx[0]-1 + shape[0]*(idx[1]-1 + shape[1]*(idx[2]-1))];
}

inline virtual T& operator()(size_t i, size_t j, size_t k)
{
//return _multi_array[i-1][j-1][k-1];
const size_t *shape = _multi_array.shape();
return _multi_array.data()[i-1 + shape[0]*(j-1 + shape[1]*(k-1))];
const size_t *shape = DynArray<T, 3>::_multi_array.shape();
return DynArray<T, 3>::_multi_array.data()[i-1 + shape[0]*(j-1 + shape[1]*(k-1))];
}

private:
boost::multi_array<T, 3> &_multi_array; // refers to base class
};
/** @} */ // end of math

0 comments on commit 2ed0fcd

Please sign in to comment.