g4tools  5.4.0
Classes | Functions
tools::xml Namespace Reference

Classes

class  aidas
 
class  default_factory
 
class  element
 
class  factory
 
class  ielem
 
class  loader
 
class  looper
 
class  styles
 
class  tree
 

Functions

void load_style (styles &a_styles, const tree &a_tree)
 
void load_plotter_style (styles &a_styles, const tree &a_tree)
 
bool scan_style_tree (styles &a_styles, const tree &a_tree)
 
bool load_style_file (std::ostream &, const std::string &a_file, tools::xml::styles &a_styles)
 
bool load_style_string (tools::xml::styles &a_styles, const std::string &a_string)
 

Function Documentation

◆ load_plotter_style()

void tools::xml::load_plotter_style ( styles a_styles,
const tree a_tree 
)
inline

Definition at line 413 of file styles.

413  {
414  std::string pname;
415  a_tree.attribute_value("name",pname);
416  if(pname.empty()) {
417  a_styles.out() << "tools::sg::gui_viewer::load_plotter_style :"
418  << " <plotter_style> without name."
419  << std::endl;
420  return;
421  }
422 
423  {styles::style_t sty;
424  sty.push_back(styles::style_item_t("tag","plotter_style"));
425 
426  {looper _for(a_tree);
427  while(element* _elem = _for.next_element()) {
428 
429  if(_elem->name()=="copy") {
430 
431  std::string from;
432  _elem->attribute_value("from",from); //expect a plotter_style name.
433  if(from.empty()) {
434  a_styles.out() << "tools::sg::gui_viewer::load_plotter_style :"
435  << " <copy> without from."
436  << std::endl;
437  return;
438  }
439 
440  const styles::style_t* csty = a_styles.find_style(from);
441  if(!csty) {
442  a_styles.out() << "tools::sg::gui_viewer::load_plotter_style :"
443  << " <copy> : from " << sout(from) << " not found."
444  << std::endl;
445  return;
446  }
447  if(csty->size()) a_styles.add_style(pname,*csty);
448 
449  if(styles::is_plotter_style(*csty)) {
450  //search all <from>.<sub_style> styles :
451  std::string head = from+".";
452  std::string::size_type l = head.size();
453 
454  styles sts(a_styles.out());
455 
456  const std::vector<styles::named_style_t>& nss = a_styles.named_styles();
457  tools_vforcit(styles::named_style_t,nss,it){
458  const std::string& name = (*it).first;
459  if(name.substr(0,l)==head) {
460  std::string tail = name.substr(l,name.size()-l);
461  const styles::style_t& ssty = (*it).second;
462  if(ssty.size()) sts.add_style(pname+"."+tail,ssty);
463  }
464  }
465 
466  a_styles.append(sts);
467 
468  }
469 
470 
471  } else {
472  sty.push_back(styles::style_item_t(_elem->name(),_elem->value()));
473  }
474 
475  }}
476 
477  if(sty.size()) a_styles.add_style(pname,sty);}
478 
479  {looper _for(a_tree);
480  while(tree* _tree = _for.next_tree()) {
481 
482  const std::string& tag = _tree->tag_name();
483  if(tag=="style") {
484 
485  std::string name;
486  _tree->attribute_value("name",name);
487  if(name.empty()) {
488  a_styles.out() << "tools::sg::gui_viewer::load_plotter_style :"
489  << " <style> without name."
490  << std::endl;
491  return;
492  }
493 
494  {styles::style_t sty;
495 
496  {looper _for2(*_tree);
497  while(element* _elem = _for2.next_element()) {
498  if(_elem->name()=="copy") {
499  std::string from;
500  _elem->attribute_value("from",from); //expect another style name.
501  if(from.empty()) {
502  a_styles.out() << "tools::sg::gui_viewer::load_plotter_style : (2) :"
503  << " <copy> without from."
504  << std::endl;
505  return;
506  }
507  const styles::style_t* csty = a_styles.find_style(from);
508  if(!csty) {
509  a_styles.out() << "tools::sg::gui_viewer::load_plotter_style : (2) :"
510  << " <copy> : from " << sout(from) << " not found."
511  << std::endl;
512  return;
513  }
514  append(sty,*csty);
515  } else {
516  sty.push_back(styles::style_item_t(_elem->name(),_elem->value()));
517  }
518  }}
519 
520  if(sty.size()) {
521  std::string path = pname+"."+name;
522  a_styles.add_style(path,sty);
523  }}
524 
525  } else {
526  a_styles.out() << "tools::sg::gui_viewer::load_plotter_style :"
527  << " unexpected tag " << sout(tag) << "."
528  << std::endl;
529  }
530 
531  }}
532 
533 }

◆ load_style()

void tools::xml::load_style ( styles a_styles,
const tree a_tree 
)
inline

Definition at line 368 of file styles.

368  {
369  std::string name;
370  a_tree.attribute_value("name",name);
371  if(name.empty()) {
372  a_styles.out() << "tools::sg::gui_viewer::load_style :"
373  << " <style> without name."
374  << std::endl;
375  return;
376  }
377 
378  styles::style_t sty;
379 
380  {looper _for(a_tree);
381  while(element* _elem = _for.next_element()) {
382 
383  if(_elem->name()=="copy") {
384 
385  std::string from;
386  _elem->attribute_value("from",from); //expect another style name.
387  if(from.empty()) {
388  a_styles.out() << "tools::sg::gui_viewer::load_style :"
389  << " <copy> without from."
390  << std::endl;
391  return;
392  }
393 
394  const styles::style_t* csty = a_styles.find_style(from);
395  if(!csty) {
396  a_styles.out() << "tools::sg::gui_viewer::load_style :"
397  << " <copy> : from " << sout(from) << " not found."
398  << std::endl;
399  return;
400  }
401 
402  append(sty,*csty);
403 
404  } else {
405  sty.push_back(styles::style_item_t(_elem->name(),_elem->value()));
406  }
407 
408  }}
409 
410  if(sty.size()) a_styles.add_style(name,sty);
411 }

◆ load_style_file()

bool tools::xml::load_style_file ( std::ostream &  ,
const std::string &  a_file,
tools::xml::styles a_styles 
)
inline

Definition at line 14 of file xml_style.

14  {
16  tools::xml::loader ml(factory,a_styles.out(),false);
17  std::vector<std::string> tags;
18  tags.push_back("styles");
19  tags.push_back("style");
20  tags.push_back("plotter_style");
21  ml.set_tags(tags);
22  if(!ml.load_file(a_file,false)) return false;
23  tools::xml::tree* top = ml.top_item();
24  if(!top) return true; //File could be empty.
25  return scan_style_tree(a_styles,*top);
26 }

◆ load_style_string()

bool tools::xml::load_style_string ( tools::xml::styles a_styles,
const std::string &  a_string 
)
inline

Definition at line 28 of file xml_style.

28  {
30  tools::xml::loader ml(factory,a_styles.out(),false);
31  std::vector<std::string> tags;
32  tags.push_back("styles");
33  tags.push_back("style");
34  tags.push_back("plotter_style");
35  ml.set_tags(tags);
36  if(!ml.load_string(a_string)) return false;
37  tools::xml::tree* top = ml.top_item();
38  if(!top) return true;
39  return scan_style_tree(a_styles,*top);
40 }

◆ scan_style_tree()

bool tools::xml::scan_style_tree ( styles a_styles,
const tree a_tree 
)
inline

Definition at line 535 of file styles.

535  {
536 
537  if(a_tree.tag_name()!="styles") return false;
538 
539  // look for aliases :
540  {looper _for(a_tree);
541  while(element* _elem = _for.next_element()) {
542 
543  std::string name;
544  _elem->attribute_value("name",name);
545  if(name.empty()) {
546  a_styles.out() << "tools::sg::gui_viewer::load_style :"
547  << " <alias> without name."
548  << std::endl;
549  continue;
550  }
551  add<std::string,std::string>(a_styles.aliases(),name,_elem->value());
552  }}
553 
554  // scan children :
555  {looper _for(a_tree);
556  while(tree* _tree = _for.next_tree()) {
557 
558  const std::string& tag = _tree->tag_name();
559  if(tag=="style") {
560  load_style(a_styles,*_tree);
561  } else if(tag=="plotter_style") {
562  load_plotter_style(a_styles,*_tree);
563  }
564 
565  }}
566 
567  return true;
568 }
tools::xml::styles::out
std::ostream & out() const
Definition: styles:35
tools::xml::default_factory
Definition: tree:989
tools::sg::top
@ top
Definition: enums:82
tools::xml::load_plotter_style
void load_plotter_style(styles &a_styles, const tree &a_tree)
Definition: styles:413
tools::append
void append(std::vector< T > &a_vec, const std::vector< T > &a_from)
Definition: vmanip:66
tools::xml::tree
Definition: tree:47
tools::xml::scan_style_tree
bool scan_style_tree(styles &a_styles, const tree &a_tree)
Definition: styles:535
tools::xml::loader
Definition: loader:42
tools_vforcit
#define tools_vforcit(a__T, a__v, a__it)
Definition: forit:7
tools::xml::load_style
void load_style(styles &a_styles, const tree &a_tree)
Definition: styles:368