Skip to content
Snippets Groups Projects
Commit 9004bbe0 authored by Martin Killenberg's avatar Martin Killenberg
Browse files

implemented global import. much copy and paste, needs code cleanup, but tests are passing

parent 117a193e
No related branches found
No related tags found
No related merge requests found
......@@ -71,6 +71,7 @@ namespace ChimeraTK{
void processLocation(xmlpp::Node const * locationNode);
void processProperty(xmlpp::Node const * propertyNode, std::string locationName);
void processLocationImport(xmlpp::Node const * importNode, std::string locationName);
void processGlobalImport(xmlpp::Node const * importNode);
std::map<std::string, PropertyAttributes> _locationDefaults;
PropertyAttributes _globalDefaults;
......
......@@ -3,6 +3,7 @@
#include <libxml++/libxml++.h>
#include <iostream>
#include <regex>
#include "splitStringAtFirstSlash.h"
namespace ChimeraTK{
void print_indentation(unsigned int indentation)
......@@ -180,6 +181,40 @@ void print_node(const xmlpp::Node* node, unsigned int indentation = 0)
}
}
}
void VariableMapper::processGlobalImport(xmlpp::Node const * importNode){
for (auto const & node : importNode->get_children()){
const xmlpp::TextNode* nodeAsText = dynamic_cast<const xmlpp::TextNode*>(node);
std::string importSource = nodeAsText->get_content();
std::cout << "Globaly importing in : " << importSource << std::endl;
// a slash will be added, so we make the source empty for a global import of everything
if (importSource == "/"){
importSource = "";
}
for (auto const & processVariable : _inputVariables){
if (_inputSortedDescriptions.find(processVariable) != _inputSortedDescriptions.end()){
std::cout << processVariable << " alread in the map. Not importing" << std::endl;
continue;
}
if ( processVariable.find( importSource+"/") == 0 ){
std::cout << "about to import " << processVariable << std::endl;
// This variable is to be imported
auto nameSource = processVariable.substr( importSource.size() + 1); // add the slash to be removed
auto locationAndPropertyName = splitStringAtFirstSlash(nameSource);
auto locationName = locationAndPropertyName.first;
auto propertyName = locationAndPropertyName.second;
if (locationName.empty() ){
throw std::logic_error(std::string("Invalid XML content in global import of ") + importSource + ": Cannot create location name from '" + nameSource + "', one hirarchy level is missing.");
}
_inputSortedDescriptions[processVariable] = PropertyDescription(locationName, propertyName);
}
}
}
}
void VariableMapper::prepareOutput(std::string xmlFile, std::set< std::string > inputVariables){
_inputVariables=inputVariables;
......@@ -207,6 +242,8 @@ void print_node(const xmlpp::Node* node, unsigned int indentation = 0)
if (mainNode->get_name() == "location"){
processLocation(mainNode);
}else if (mainNode->get_name() == "import"){
processGlobalImport(mainNode);
}else{
std::cout << "FIXME: Implement main node '" << mainNode->get_name()
<< "'! Current implementation does nothing" << std::endl;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment