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

- has_history default for locations is working if variables are explicilty mentioned

- parser accepts comments in xml file
parent 696b8619
No related branches found
No related tags found
No related merge requests found
......@@ -63,7 +63,7 @@ namespace ChimeraTK{
struct LocationInfo: public PropertyAttributes{
bool useHasHistoryDefault;
bool useIsWriteableDefault;
LocationInfo(bool useHasHistoryDefault_, bool useIsWriteableDefault_)
LocationInfo(bool useHasHistoryDefault_=false, bool useIsWriteableDefault_=false)
: useHasHistoryDefault(useHasHistoryDefault_), useIsWriteableDefault(useIsWriteableDefault_){
}
};
......@@ -82,9 +82,14 @@ namespace ChimeraTK{
/// printing the map is useful for debugging
void print(std::ostream & os = std::cout) const;
/// Note on the input: we intentionally make a because we modify it inside.
/// Function to get a bool out of the texts true/True/TRUE/false/False/FALSE/1/0.
/// Note on the input: we intentionally make a copy because we modify it inside.
static bool evaluateBool(std::string txt);
/// Loop through the sub nodes and take the string from the first non-empty
/// which can be casted to a string-node
static std::string getContentString(xmlpp::Node const *node);
protected:
VariableMapper()=default;
......@@ -96,7 +101,7 @@ namespace ChimeraTK{
void import(std::string importSource, std::string importLocationName, std::string directory="");
std::map<std::string, PropertyAttributes> _locationDefaults;
std::map<std::string, LocationInfo> _locationDefaults;
PropertyAttributes _globalDefaults;
// PropertyDescriptions, sorted by input, i.e. the ChimeraTK PV name
......
......@@ -29,13 +29,19 @@ namespace ChimeraTK{
for (auto const & node : location->get_children()){
if (nodeIsWhitespace(node)) continue;
if (dynamic_cast<xmlpp::CommentNode const *>(node)) continue;
if (node->get_name() == "property"){
processPropertyNode(node, locationName);
}else if (node->get_name() == "import"){
processImportNode(node, locationName);
}else if (node->get_name() == "has_history"){
std::cout << "FIXME: implement has_history" << std::endl;
std::cout << "FIXME: implementing has_history" << std::endl;
auto & locationInfo = _locationDefaults[locationName];
locationInfo.useHasHistoryDefault = true;
locationInfo.hasHistory = evaluateBool(getContentString(node));
std::cout << "locationName " << locationName << ", stringContent " << getContentString(node)<< std::endl;
// FIXME: I need a one-liner to extract true/false from the node and place it into locationInfo
}else if (node->get_name() == "is_writeable"){
std::cout << "FIXME: implement is_writeable" << std::endl;
}else{
......@@ -85,8 +91,23 @@ namespace ChimeraTK{
// fixme : there is a check on location xml missing if it has the has_history
if (useDefaultHasHistory){
std::cout << "setting hasHistory default of "<< name << " to " << propertyDescription.hasHistory << std::endl;
propertyDescription.hasHistory = _globalDefaults.hasHistory;
std::cout << "useDefaultHasHistory in " << locationName << std::endl;
auto locationInfoIter = _locationDefaults.find(locationName);
if (locationInfoIter != _locationDefaults.end()){
std::cout << "found info on location " << locationName << std::endl;
auto locationInfo =locationInfoIter->second;
if (locationInfo.useHasHistoryDefault){
propertyDescription.hasHistory = locationInfo.hasHistory;
std::cout << "setting hasHistory default from location info of "<< name << " to " << propertyDescription.hasHistory << std::endl;
}else{
propertyDescription.hasHistory = _globalDefaults.hasHistory;
std::cout << "locationInfo does not have default settings. setting global hasHistory default of "<< name << " to " << propertyDescription.hasHistory << std::endl;
}
}else{
propertyDescription.hasHistory = _globalDefaults.hasHistory;
std::cout << "setting hasHistory default of "<< name << " to " << propertyDescription.hasHistory << std::endl;
}
}
std::string absoluteSource;
......@@ -254,5 +275,19 @@ namespace ChimeraTK{
}
}
std::string VariableMapper::getContentString(xmlpp::Node const *node){
for (auto const & subNode : node->get_children()){
const xmlpp::TextNode* nodeAsText = dynamic_cast<const xmlpp::TextNode*>(subNode);
if(nodeAsText){
if (nodeAsText->is_white_space()){
continue;
}
return nodeAsText->get_content();
}
}
throw std::invalid_argument(std::string("Error parsing xml file: node ") + node->get_name() +
" does not have text nodes as children.");
}
} // namespace ChimeraTK
......@@ -74,7 +74,7 @@ bool mapCompare (Map const &lhs, Map const &rhs) {
void testXmlParsing(std::string xmlFile, std::map< std::string, VariableMapper::PropertyDescription > propertyMap){
VariableMapper & vm = VariableMapper::getInstance();
vm.prepareOutput(xmlFile, generateInputVariables());
vm.print();
// vm.print();
BOOST_CHECK( mapCompare( vm.getAllProperties(), propertyMap) );
}
......@@ -261,8 +261,8 @@ BOOST_AUTO_TEST_CASE( testUnkownLocationNode ){
}
BOOST_AUTO_TEST_CASE( testLocationTurnOffOn ){
testXmlParsing("variableTreeXml/locationTurnOffOn.xml", { {"/A/a/di", {"DUMMY_LOCATION","a.di",true}},
{"/A/a/do", {"DUMMY_LOCATION","A.a.do",false}},
testXmlParsing("variableTreeXml/locationTurnOffOn.xml", { {"/A/a/di", {"DUMMY_LOCATION","a.di",false}},
{"/A/a/do", {"DUMMY_LOCATION","A.a.do",true}},
{"/A/b", {"DUMMY_LOCATION","b",true}},
{"/B/a/dr", {"ANOTHER_LOCATION","a.dr",true}},
{"/B/c/de", {"ANOTHER_LOCATION","c.de",true}},
......
......@@ -3,8 +3,12 @@
<location name="DUMMY_LOCATION">
<has_history>false</has_history>
<property source="/A/a/do">
<has_history>false</has_history>
<has_history>true</has_history>
</property>
<!-- to test that it picks up the default when explicitly mentiones as property-->
<property source="/A/a/di" name="a.di">
</property>
<!-- to test that it picks up the default when being imported-->
<import>/A</import>
</location>
<location name="ANOTHER_LOCATION">
......
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