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

importing locations works

parent 5fd4308f
No related branches found
No related tags found
No related merge requests found
......@@ -66,6 +66,8 @@ namespace ChimeraTK{
protected:
VariableMapper()=default;
std::set< std::string > _inputVariables;
void processLocation(xmlpp::Node const * locationNode);
void processProperty(xmlpp::Node const * propertyNode, std::string locationName);
void processLocationImport(xmlpp::Node const * importNode, std::string locationName);
......
......@@ -2,6 +2,7 @@
#include <libxml++/libxml++.h>
#include <iostream>
#include <regex>
namespace ChimeraTK{
void print_indentation(unsigned int indentation)
......@@ -156,12 +157,33 @@ void print_node(const xmlpp::Node* node, unsigned int indentation = 0)
void VariableMapper::processLocationImport(xmlpp::Node const * importNode, std::string locationName){
for (auto const & node : importNode->get_children()){
const xmlpp::TextNode* nodeAsText = dynamic_cast<const xmlpp::TextNode*>(node);
std::cout << "Importing location: " << nodeAsText->get_content() << std::endl;
// loop source tree, cut beginning, replace / with _ and add a property
std::string importSource = nodeAsText->get_content();
std::cout << "Importing in location '"<<locationName <<"': " << importSource << std::endl;
// loop source tree, cut beginning, replace / with _ and add a property
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 ){
// processVariable starts with wanted source
std::cout << "importing " << processVariable << " from " << importSource << " into "
<< locationName << std::endl;
auto propertyNameSource = processVariable.substr( importSource.size() + 1); // add the slash to be removed
std::cout << "propertyNameSource " << propertyNameSource << std::endl;
auto propertyName = std::regex_replace(propertyNameSource, std::regex("/"), ".");
std::cout << "new property name is " << propertyName << std::endl;
_inputSortedDescriptions[processVariable] = PropertyDescription(locationName, propertyName);
}
}
}
}
void VariableMapper::prepareOutput(std::string xmlFile, std::set< std::string > inputVariables){
_inputVariables=inputVariables;
xmlpp::DomParser parser;
// parser.set_validate();
parser.set_substitute_entities(); //We just want the text to be resolved/unescaped automatically.
......@@ -175,8 +197,8 @@ void print_node(const xmlpp::Node* node, unsigned int indentation = 0)
//Walk the tree:
const xmlpp::Node* rootNode = parser.get_document()->get_root_node(); //deleted by DomParser.
std::cout << "****************************\nPredefined printout in "<< xmlFile<<":\n" << std::endl;
print_node(rootNode);
// std::cout << "****************************\nPredefined printout in "<< xmlFile<<":\n" << std::endl;
// print_node(rootNode);
std::cout << "\n My interpretation for "<< xmlFile << "\n===================================" << std::endl;
......
......@@ -64,9 +64,11 @@ std::set< std::string > generateInputVariables(){
template <typename Map>
bool mapCompare (Map const &lhs, Map const &rhs) {
// No predicate needed because there is operator== for pairs already.
std::cout << "lhs.size() " << lhs.size() << ", rhs.size() " << rhs.size() << std::endl;
return lhs.size() == rhs.size()
&& std::equal(lhs.begin(), lhs.end(), rhs.begin());
if ( lhs.size() != rhs.size() ){
std::cout << "Map size comparison failed: lhs.size() " << lhs.size() << ", rhs.size() " << rhs.size() << std::endl;
return false;
}
return std::equal(lhs.begin(), lhs.end(), rhs.begin());
}
void testXmlParsing(std::string xmlFile, std::map< std::string, VariableMapper::PropertyDescription > propertyMap){
......@@ -82,27 +84,27 @@ BOOST_AUTO_TEST_CASE( testRename ){
}
BOOST_AUTO_TEST_CASE( testImportLocation ){
testXmlParsing("variableTreeXml/importLocation.xml", { {"/A/a/di", {"B","a_di"}},
{"/A/a/do", {"B","a_do"}},
testXmlParsing("variableTreeXml/importLocation.xml", { {"/A/a/di", {"B","a.di"}},
{"/A/a/do", {"B","a.do"}},
{"/A/b", {"B","b"}}
});
}
BOOST_AUTO_TEST_CASE( testImportAll ){
testXmlParsing("variableTreeXml/importAll.xml", { {"/A/a/di", {"A","a_di"}},
{"/A/a/do", {"A","a_do"}},
testXmlParsing("variableTreeXml/importAll.xml", { {"/A/a/di", {"A","a.di"}},
{"/A/a/do", {"A","a.do"}},
{"/A/b", {"A","b"}},
{"/B/a/dr", {"B","a_dr"}},
{"/B/c/de", {"B","c_de"}},
{"/B/c/gne", {"B","c_gne"}},
{"/C/a/da", {"C","a_da"}},
{"/C/b/ge", {"C","b_ge"}},
{"/C/c/be", {"C","c_be"}},
{"/C/c/de", {"C","c_de"}},
{"/B/a/dr", {"B","a.dr"}},
{"/B/c/de", {"B","c.de"}},
{"/B/c/gne", {"B","c.gne"}},
{"/C/a/da", {"C","a.da"}},
{"/C/b/ge", {"C","b.ge"}},
{"/C/c/be", {"C","c.be"}},
{"/C/c/de", {"C","c.de"}},
{"/DIRECT/DOUBLE", {"DIRECT","DOUBLE"}},
{"/DIRECT/DOUBLE", {"DIRECT","DOUBLE_ARRAY"}},
{"/DIRECT/DOUBLE_ARRAY", {"DIRECT","DOUBLE_ARRAY"}},
{"/DIRECT/INT", {"DIRECT","INT"}},
{"/DIRECT/INT", {"DIRECT","INT_ARRAY"}}
{"/DIRECT/INT_ARRAY", {"DIRECT","INT_ARRAY"}}
});
}
......
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