Skip to content

Commit

Permalink
- added XmlPropertyReader-Class
Browse files Browse the repository at this point in the history
- Fix for FMU shared object generation
  • Loading branch information
Marcus Walther committed Jun 17, 2015
1 parent 2c70f15 commit cf1058a
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
80 changes: 80 additions & 0 deletions SimulationRuntime/cpp/Core/DataExchange/XmlPropertyReader.cpp
@@ -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;
}
3 changes: 3 additions & 0 deletions SimulationRuntime/cpp/FMU/CMakeLists.txt
Expand Up @@ -7,6 +7,9 @@ add_library(${FMUName}_static STATIC FMULogger.cpp)

set_target_properties(${FMUName}_static PROPERTIES COMPILE_DEFINITIONS "DRUNTIME_STATIC_LINKING")

target_link_libraries (${FMUName} ${ExtensionUtilitiesName} )
target_link_libraries (${FMUName}_static ${ExtensionUtilitiesName}_static )

add_precompiled_header(${FMUName} Include/Core/Modelica.h)
add_precompiled_header(${FMUName}_static Include/Core/Modelica.h)

Expand Down
@@ -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;
};

0 comments on commit cf1058a

Please sign in to comment.