Go to the documentation of this file.
4 #ifndef tools_xml_styles
5 #define tools_xml_styles
8 #include "../sg/style_colormap"
41 typedef std::vector<style_item_t>
style_t;
47 typedef std::pair<std::string,std::string>
alias_t;
53 if((*it).first==a_name)
return &((*it).second);
70 void find_styles(
const std::string& a_pattern,std::vector<std::string>& a_v)
const {
73 if(
match((*it).first,a_pattern)) a_v.push_back((*it).first);
79 if((*it).first==a_name) {
81 (*it).second = a_style;
90 std::vector<named_style_t>::iterator it;
92 if(
match((*it).first,a_pattern)) {
108 bool is_alias(
const std::string& a_wanted,std::string& a_style)
const {
126 bool res_value(
const style_t& a_sty,
const std::string& a_key,T& a_v,
const std::string& a_msg)
const {
130 if(!
find(a_sty,a_key,_s)) {
132 m_out <<
"tools::xml::styles::res_value :"
133 <<
" key " <<
sout(a_key) <<
" not found"
134 <<
" in style " <<
sout(a_msg) <<
"."
141 m_out <<
"tools::xml::styles::res_value :"
142 <<
" for key " <<
sout(a_key) <<
" not found"
143 <<
" in style " <<
sout(a_msg) <<
"."
144 <<
" can't convert " <<
sout(_s) <<
" to value."
153 bool res_value(
const std::string& a_style,
const std::string& a_key,T& a_v)
const {
168 if(!res_value<T>(*sty,a_key,v,style))
return false;
176 if(!
find(a_sty,a_key,s)) {
178 m_out <<
"tools::xml::styles::res_color :"
179 <<
" key " <<
sout(a_key) <<
" not found"
180 <<
" in style " <<
sout(a_msg) <<
"."
186 m_out <<
"tools::xml::styles::res_color :"
187 <<
" key " <<
sout(a_key) <<
" is not a color"
188 <<
" in style " <<
sout(a_msg) <<
"."
195 bool res_color(
const std::string& a_style,
const std::string& a_key,
colorf& a_color)
const {
210 return res_color(*sty,a_key,a_color,style);
213 bool res_bool(
const style_t& a_sty,
const std::string& a_key,
bool& a_v,
const std::string& a_msg)
const {
216 if(!
find(a_sty,a_key,s)) {
218 m_out <<
"tools::xml::styles::res_bool :"
219 <<
" key " <<
sout(a_key) <<
" not found"
220 <<
" in style " <<
sout(a_msg) <<
"."
227 m_out <<
"tools::xml::styles::res_bool :"
228 <<
" for key " <<
sout(a_key) <<
" not found"
229 <<
" in style " <<
sout(a_msg) <<
"."
230 <<
" can't convert " <<
sout(s) <<
" to bool."
238 bool res_bool(
const std::string& a_style,
const std::string& a_key,
bool& a_v)
const {
253 return res_bool(*sty,a_key,a_v,style);
272 if(vit!=(*sty).begin()) _s +=
"\n";
282 std::map<std::string,cmap_t>::const_iterator it =
m_cmaps.find(a_name);
283 if(it==
m_cmaps.end())
return false;
284 a_cmap = (*it).second;
295 const std::string& key = (*it).first;
296 const std::string& sv = (*it).second;
297 if((key==
"tag")&&(sv==
"plotter_style"))
return true;
313 m_out <<
"/////////////////////////////////////" << std::endl;
314 m_out <<
"/// " << (*it).first << std::endl;
315 m_out <<
"/////////////////////////////////////" << std::endl;
317 const style_t& sty = (*it).second;
320 m_out <<
" " << (*vit).first <<
" " << (*vit).second << std::endl;
327 std::string _beg = a_style+
".";
330 const std::string& _name = (*it).first;
331 if((_name==a_style)||
is_beg(_name,_beg)) {
333 a_out << (*it).first <<
" :" << std::endl;
334 const style_t& sty = (*it).second;
336 if((*vit).first==
"tag")
continue;
337 a_out <<
" " << (*vit).first <<
" " << (*vit).second << std::endl;
346 const style_t& sty = (*it).second;
348 a_out << (*it).first << std::endl;
372 a_styles.
out() <<
"tools::sg::gui_viewer::load_style :"
373 <<
" <style> without name."
383 if(_elem->name()==
"copy") {
386 _elem->attribute_value(
"from",from);
388 a_styles.
out() <<
"tools::sg::gui_viewer::load_style :"
389 <<
" <copy> without from."
396 a_styles.
out() <<
"tools::sg::gui_viewer::load_style :"
397 <<
" <copy> : from " <<
sout(from) <<
" not found."
410 if(sty.size()) a_styles.
add_style(name,sty);
417 a_styles.
out() <<
"tools::sg::gui_viewer::load_plotter_style :"
418 <<
" <plotter_style> without name."
429 if(_elem->name()==
"copy") {
432 _elem->attribute_value(
"from",from);
434 a_styles.
out() <<
"tools::sg::gui_viewer::load_plotter_style :"
435 <<
" <copy> without from."
442 a_styles.
out() <<
"tools::sg::gui_viewer::load_plotter_style :"
443 <<
" <copy> : from " <<
sout(from) <<
" not found."
447 if(csty->size()) a_styles.
add_style(pname,*csty);
451 std::string head = from+
".";
452 std::string::size_type l = head.size();
456 const std::vector<styles::named_style_t>& nss = a_styles.
named_styles();
458 const std::string& name = (*it).first;
459 if(name.substr(0,l)==head) {
460 std::string tail = name.substr(l,name.size()-l);
462 if(ssty.size()) sts.
add_style(pname+
"."+tail,ssty);
477 if(sty.size()) a_styles.
add_style(pname,sty);}
482 const std::string& tag = _tree->tag_name();
486 _tree->attribute_value(
"name",name);
488 a_styles.
out() <<
"tools::sg::gui_viewer::load_plotter_style :"
489 <<
" <style> without name."
498 if(_elem->name()==
"copy") {
500 _elem->attribute_value(
"from",from);
502 a_styles.
out() <<
"tools::sg::gui_viewer::load_plotter_style : (2) :"
503 <<
" <copy> without from."
509 a_styles.
out() <<
"tools::sg::gui_viewer::load_plotter_style : (2) :"
510 <<
" <copy> : from " <<
sout(from) <<
" not found."
521 std::string path = pname+
"."+name;
526 a_styles.
out() <<
"tools::sg::gui_viewer::load_plotter_style :"
527 <<
" unexpected tag " <<
sout(tag) <<
"."
537 if(a_tree.
tag_name()!=
"styles")
return false;
544 _elem->attribute_value(
"name",name);
546 a_styles.
out() <<
"tools::sg::gui_viewer::load_style :"
547 <<
" <alias> without name."
551 add<std::string,std::string>(a_styles.
aliases(),name,_elem->value());
558 const std::string& tag = _tree->tag_name();
561 }
else if(tag==
"plotter_style") {
#define tools_vforit(a__T, a__v, a__it)
#define tools_vforcit(a__T, a__v, a__it)