Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Fix for FMU shared object generation
- Loading branch information
Marcus Walther
committed
Jun 17, 2015
1 parent
2c70f15
commit cf1058a
Showing
3 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
SimulationRuntime/cpp/Core/DataExchange/XmlPropertyReader.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#include <Core/DataExchange/XmlPropertyReader.h> | ||
#include <boost/property_tree/xml_parser.hpp> | ||
#include <boost/property_tree/ptree.hpp> | ||
#include <boost/foreach.hpp> | ||
#include <fstream> | ||
#include <iostream> | ||
|
||
XmlPropertyReader::XmlPropertyReader(std::string propertyFile) : IPropertyReader(), propertyFile(propertyFile) | ||
{ | ||
} | ||
|
||
XmlPropertyReader::~XmlPropertyReader() | ||
{ | ||
|
||
} | ||
|
||
void XmlPropertyReader::readInitialValues(boost::shared_ptr<ISimVars> sim_vars) | ||
{ | ||
using boost::property_tree::ptree; | ||
std::ifstream file(propertyFile); | ||
|
||
if(file) | ||
{ | ||
double *realVars = sim_vars->getRealVarsVector(); | ||
int *intVars = sim_vars->getIntVarsVector(); | ||
bool *boolVars = sim_vars->getBoolVarsVector(); | ||
|
||
ptree tree; | ||
read_xml(file, tree); | ||
|
||
ptree modelDescription = tree.get_child("ModelDescription"); | ||
|
||
BOOST_FOREACH(ptree::value_type const& vars, modelDescription.get_child("ModelVariables")) | ||
{ | ||
if(vars.first == "ScalarVariable") | ||
{ | ||
int refIdx = vars.second.get<int>("<xmlattr>.valueReference"); | ||
BOOST_FOREACH(ptree::value_type const& var, vars.second.get_child("")) | ||
{ | ||
if(var.first == "Real") | ||
{ | ||
boost::optional<float> v = var.second.get_optional<float>("<xmlattr>.start"); | ||
std::cerr << "Setting real variable for " << vars.second.get<std::string>("<xmlattr>.name") << " with reference " << refIdx << " to " << *v << std::endl; | ||
if(v) | ||
realVars[refIdx] = *v; | ||
} | ||
else if(var.first == "Int") | ||
{ | ||
boost::optional<int> v = var.second.get_optional<int>("<xmlattr>.start"); | ||
std::cerr << "Setting int variable for " << vars.second.get<std::string>("<xmlattr>.name") << " with reference " << refIdx << " to " << *v << std::endl; | ||
if(v) | ||
intVars[refIdx] = *v; | ||
} | ||
else if(var.first == "Boolean") | ||
{ | ||
boost::optional<bool> v = var.second.get_optional<bool>("<xmlattr>.start"); | ||
std::cerr << "Setting bool variable for " << vars.second.get<std::string>("<xmlattr>.name") << " with reference " << refIdx << " to " << *v << std::endl; | ||
if(v) | ||
realVars[refIdx] = *v; | ||
} | ||
} | ||
} | ||
sim_vars->setRealVarsVector(realVars); | ||
sim_vars->setIntVarsVector(intVars); | ||
sim_vars->setBoolVarsVector(boolVars); | ||
} | ||
|
||
file.close(); | ||
} | ||
} | ||
|
||
std::string XmlPropertyReader::getPropertyFile() | ||
{ | ||
return propertyFile; | ||
} | ||
|
||
void XmlPropertyReader::setPropertyFile(std::string file) | ||
{ | ||
propertyFile = file; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
SimulationRuntime/cpp/Include/Core/DataExchange/XmlPropertyReader.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#pragma once | ||
|
||
#include <Core/DataExchange/IPropertyReader.h> | ||
#include <string> | ||
|
||
class XmlPropertyReader : public IPropertyReader | ||
{ | ||
public: | ||
XmlPropertyReader(std::string propertyFile); | ||
~XmlPropertyReader(); | ||
|
||
void readInitialValues(boost::shared_ptr<ISimVars> sim_vars); | ||
|
||
std::string getPropertyFile(); | ||
void setPropertyFile(std::string file); | ||
|
||
private: | ||
std::string propertyFile; | ||
}; |