Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights 1 // Copyright (C) 2010, Guy Barrand. All rights reserved. 2 // See the file tools.license for terms. 2 // See the file tools.license for terms. 3 3 4 #ifndef toolx_xml_style 4 #ifndef toolx_xml_style 5 #define toolx_xml_style 5 #define toolx_xml_style 6 6 7 #include <tools/xml/styles> 7 #include <tools/xml/styles> 8 8 9 #include "loader" 9 #include "loader" 10 10 11 namespace toolx { 11 namespace toolx { 12 namespace xml { 12 namespace xml { 13 13 14 inline bool load_style_file(std::ostream&,cons 14 inline bool load_style_file(std::ostream&,const std::string& a_file,tools::xml::styles& a_styles) { 15 tools::xml::default_factory factory; 15 tools::xml::default_factory factory; 16 toolx::xml::loader ml(factory,a_styles.out() 16 toolx::xml::loader ml(factory,a_styles.out(),false); 17 std::vector<std::string> tags; 17 std::vector<std::string> tags; 18 tags.push_back("styles"); 18 tags.push_back("styles"); 19 tags.push_back("style"); 19 tags.push_back("style"); 20 tags.push_back("plotter_style"); 20 tags.push_back("plotter_style"); 21 ml.set_tags(tags); 21 ml.set_tags(tags); 22 if(!ml.load_file(a_file,false)) return false 22 if(!ml.load_file(a_file,false)) return false; 23 tools::xml::tree* top = ml.top_item(); 23 tools::xml::tree* top = ml.top_item(); 24 if(!top) return true; //File could be empty. 24 if(!top) return true; //File could be empty. 25 return scan_style_tree(a_styles,*top); 25 return scan_style_tree(a_styles,*top); 26 } 26 } 27 27 28 inline bool load_style_string(tools::xml::styl 28 inline bool load_style_string(tools::xml::styles& a_styles,const std::string& a_string) { 29 tools::xml::default_factory factory; 29 tools::xml::default_factory factory; 30 toolx::xml::loader ml(factory,a_styles.out() 30 toolx::xml::loader ml(factory,a_styles.out(),false); 31 std::vector<std::string> tags; 31 std::vector<std::string> tags; 32 tags.push_back("styles"); 32 tags.push_back("styles"); 33 tags.push_back("style"); 33 tags.push_back("style"); 34 tags.push_back("plotter_style"); 34 tags.push_back("plotter_style"); 35 ml.set_tags(tags); 35 ml.set_tags(tags); 36 if(!ml.load_string(a_string)) return false; 36 if(!ml.load_string(a_string)) return false; 37 tools::xml::tree* top = ml.top_item(); 37 tools::xml::tree* top = ml.top_item(); 38 if(!top) return true; 38 if(!top) return true; 39 return scan_style_tree(a_styles,*top); 39 return scan_style_tree(a_styles,*top); 40 } 40 } 41 41 42 }} 42 }} 43 43 44 #endif 44 #endif