g4tools  5.4.0
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
tools::xml::tree Class Reference
Inheritance diagram for tools::xml::tree:
Inheritance graph
[legend]
Collaboration diagram for tools::xml::tree:
Collaboration graph
[legend]

Classes

class  empty_visitor
 

Public Types

enum  copy_what { copy_attributes, copy_elements, copy_children, copy_all }
 
typedef std::pair< std::string, std::string > atb
 
typedef bool(* exec_func) (tree &, void *)
 

Public Member Functions

virtual void * cast (cid a_class) const
 
 tree (const std::string &a_tag_name, factory &a_factory, tree *a_parent)
 
virtual ~tree ()
 
virtual bool invalidate ()
 
const std::list< ielem * > & childs () const
 
const std::vector< atb > & attributes () const
 attributes //////////////////////////////////////// More...
 
void add_attribute (const std::string &a_name, const std::string &a_value)
 
bool is_attribute (const std::string &a_name) const
 
void set_attributes (const std::vector< atb > &a_atbs)
 
const std::string & tag_name () const
 
bool attribute_value (const std::string &a_atb, std::string &a_value) const
 
template<class T >
bool attribute_value (const std::string &a_atb, T &a_value) const
 
void remove_attributes (const std::string &a_atb)
 
bool remove_attribute (const std::string &a_name)
 
void add_element (const std::string &a_name, const std::vector< atb > &a_atbs, const std::string &a_value)
 elements ////////////////////////////////////////// More...
 
bool element_value (const std::string &a_name, std::string &a_value) const
 
bool element_atb_value (const std::string &a_elem, const std::string &a_atb, std::string &a_value) const
 
template<class T >
bool element_atb_value (const std::string &a_elem, const std::string &a_atb, T &a_value) const
 
bool is_element (const std::string &a_name) const
 for osc ////////////////////////////////////// More...
 
bool set_element_value (const std::string &a_name, const std::string &a_value, int a_index=0)
 
bool set_attribute_value (const std::string &a_atb, const std::string &a_value)
 
bool has_empty_attribute_value (std::ostream &a_out) const
 
void post_execute (exec_func a_function, void *a_tag)
 
treefind_by_tag (const std::string &a_tag) const
 
treefind_item (const std::string &a_name) const
 
treefind_item_with_tag (const std::string &a_tag, const std::string &a_name) const
 
void remove_elements (const std::string &a_name)
 
void add_child (tree *a_tree)
 
treecreate_copy (tree *a_parent)
 
bool copy (const tree &a_from, copy_what a_what=copy_all, bool a_clear=true)
 
void replace (const std::string &a_old, const std::string &a_new)
 
bool element_values (const std::string &a_name, std::vector< std::string > &a_values) const
 
void post_execute_backward (exec_func a_function, void *a_tag)
 
treefind_by_attribute (const std::string &a_atb, const std::string &a_value, bool a_up_down=true, bool a_left_right=true) const
 
void dump_xml (std::ostream &a_out, const std::string &a_spaces="")
 
bool set_element_atb_value (const std::string &a_elem, const std::string &a_atb, const std::string &a_value, int a_index=0)
 
void sub_trees (std::list< tree * > &a_list) const
 
void sub_elems (std::list< element * > &a_list) const
 
bool replace_child (tree *a_old, tree *a_new)
 
virtual void * cast (const std::string &a_class) const
 
void delete_element (const std::string &a_name)
 
void delete_element (element *a_element)
 
void delete_sub_trees ()
 
void delete_sub_elems ()
 
const treefind_by_element_in_same_level (const std::string &a_name, const std::string &a_value) const
 
bool element_value_boolean (const std::string &a_name, bool &a_value) const
 
void update_tree (const tree &a_old)
 
treeparent () const
 end osc ////////////////////////////////////// More...
 
void set_parent (tree *a_parent)
 
unsigned int number_of_trees () const
 
void remove_child (tree *&a_tree, bool a_delete=true)
 
void set_data (void *a_data_1, void *a_data_2, int a_data_int)
 
void get_data (void *&a_data_1, void *&a_data_2, int &a_data_int) const
 
void * get_data1 () const
 
void * get_data2 () const
 
int get_data_int () const
 
void set_depth (unsigned int a_depth)
 
unsigned int depth () const
 
void set_save_flag (bool a_value)
 
bool save_flag () const
 
void set_file (const std::string &a_file)
 
const std::string & file () const
 
- Public Member Functions inherited from tools::xml::ielem
virtual ~ielem ()
 

Static Public Member Functions

static cid id_class ()
 
static bool check_item (tree &a_tree, void *a_tag)
 
static void collect_by_tag (tree &a_tree, const std::string &a_tag, std::vector< tree * > &a_items)
 
static void unique (std::vector< tree * > &a_items)
 
static void collect_by_attribute (tree &a_tree, const std::string &a_tag, std::vector< tree * > &a_items)
 

Protected Member Functions

 tree (const tree &a_from)
 
treeoperator= (const tree &)
 
void clear ()
 

Protected Attributes

std::string m_tag_name
 
factorym_factory
 
treem_parent
 
std::list< ielem * > m_childs
 
std::vector< atbm_atbs
 
std::string m_file
 
bool m_save
 
void * m_data_1
 
void * m_data_2
 
int m_data_int
 
int m_depth
 

Detailed Description

Definition at line 47 of file tree.

Member Typedef Documentation

◆ atb

typedef std::pair<std::string,std::string> tools::xml::tree::atb

Definition at line 57 of file tree.

◆ exec_func

typedef bool(* tools::xml::tree::exec_func) (tree &, void *)

Definition at line 58 of file tree.

Member Enumeration Documentation

◆ copy_what

Enumerator
copy_attributes 
copy_elements 
copy_children 
copy_all 

Definition at line 59 of file tree.

Constructor & Destructor Documentation

◆ tree() [1/2]

tools::xml::tree::tree ( const std::string &  a_tag_name,
factory a_factory,
tree a_parent 
)
inline

Definition at line 61 of file tree.

62  :m_tag_name(a_tag_name)
63  ,m_factory(a_factory)
64  ,m_parent(a_parent)
65  ,m_save(true)
66  ,m_data_1(0)
67  ,m_data_2(0)
68  ,m_data_int(0)
69  ,m_depth(0)
70  {
71 #ifdef TOOLS_MEM
72  mem::increment(s_class().c_str());
73 #endif
74  }

◆ ~tree()

virtual tools::xml::tree::~tree ( )
inlinevirtual

Definition at line 76 of file tree.

76  {
77  clear();
78 #ifdef TOOLS_MEM
79  mem::decrement(s_class().c_str());
80 #endif
81  }

◆ tree() [2/2]

tools::xml::tree::tree ( const tree a_from)
inlineprotected

Definition at line 84 of file tree.

85  :ielem(a_from)
86  ,m_tag_name(a_from.m_tag_name)
87  ,m_factory(a_from.m_factory)
88  ,m_parent(0)
89  ,m_save(0)
90  ,m_data_1(0)
91  ,m_data_2(0)
92  ,m_data_int(0)
93  ,m_depth(0)
94  {
95 #ifdef TOOLS_MEM
96  mem::increment(s_class().c_str());
97 #endif
98  }

Member Function Documentation

◆ add_attribute()

void tools::xml::tree::add_attribute ( const std::string &  a_name,
const std::string &  a_value 
)
inline

Definition at line 112 of file tree.

112  {
113  // No check is done about an existing a_name.
114  m_atbs.push_back(atb(a_name,a_value));
115  }

◆ add_child()

void tools::xml::tree::add_child ( tree a_tree)
inline

Definition at line 448 of file tree.

448 {m_childs.push_back(a_tree);}

◆ add_element()

void tools::xml::tree::add_element ( const std::string &  a_name,
const std::vector< atb > &  a_atbs,
const std::string &  a_value 
)
inline

elements //////////////////////////////////////////

Definition at line 176 of file tree.

176  {
177  m_childs.push_back(new element(a_name,a_atbs,a_value));
178  }

◆ attribute_value() [1/2]

bool tools::xml::tree::attribute_value ( const std::string &  a_atb,
std::string &  a_value 
) const
inline

Definition at line 130 of file tree.

130  {
131  a_value.clear();
132  size_t linen = m_atbs.size();
133  for(size_t count=0;count<linen;count++) {
134  if(m_atbs[count].first==a_atb) {
135  a_value = m_atbs[count].second;
136  return true;
137  }
138  }
139  return false;
140  }

◆ attribute_value() [2/2]

template<class T >
bool tools::xml::tree::attribute_value ( const std::string &  a_atb,
T &  a_value 
) const
inline

Definition at line 143 of file tree.

143  {
144  std::string sv;
145  if(!attribute_value(a_atb,sv)) {a_value=T();return false;}
146  return to<T>(sv,a_value);
147  }

◆ attributes()

const std::vector<atb>& tools::xml::tree::attributes ( ) const
inline

attributes ////////////////////////////////////////

Definition at line 110 of file tree.

110 {return m_atbs;}

◆ cast() [1/2]

virtual void* tools::xml::tree::cast ( cid  a_class) const
inlinevirtual

Implements tools::xml::ielem.

Definition at line 52 of file tree.

52  {
53  if(void* p = cmp_cast<tree>(this,a_class)) {return p;}
54  else return 0;
55  }

◆ cast() [2/2]

virtual void* tools::xml::tree::cast ( const std::string &  a_class) const
inlinevirtual

Definition at line 731 of file tree.

731  {
732  if(void* p = cmp_cast<tree>(this,a_class)) {return p;}
733  else return 0;
734  }

◆ check_item()

static bool tools::xml::tree::check_item ( tree a_tree,
void *  a_tag 
)
inlinestatic

Definition at line 314 of file tree.

314  {
315  empty_visitor* visitor = (empty_visitor*)a_tag;
316 
317  {const std::vector<atb>& atbs = a_tree.attributes();
318  size_t atbn = atbs.size();
319  for(size_t index=0;index<atbn;index++) {
320  const std::string& _atb = atbs[index].first;
321  const std::string& atbv = atbs[index].second;
322  if(atbv.empty()) {
323  visitor->f_out << "check_item :"
324  << " for XML item " << sout(a_tree.tag_name())
325  << ", attribute " << sout(_atb) << " has an empty value."
326  << std::endl;
327  visitor->m_status = false;
328  }
329  }}
330 
331  {tools_lforcit(ielem*,a_tree.m_childs,it) {
332  if(element* _elem = id_cast<ielem,element>(*(*it))) {
333  const std::vector<atb>& atbs = _elem->attributes();
334  size_t atbn = atbs.size();
335  for(size_t index=0;index<atbn;index++) {
336  const std::string& _atb = atbs[index].first;
337  const std::string& atbv = atbs[index].second;
338  if(atbv.empty()) {
339  visitor->f_out << "ItemM::check_item :"
340  << " for XML item " << sout(a_tree.tag_name())
341  << ", attribute " << sout(_atb) << " has an empty value."
342  << std::endl;
343  visitor->m_status = false;
344  }
345  }
346  }}}
347 
348  return true;
349  }

◆ childs()

const std::list<ielem*>& tools::xml::tree::childs ( ) const
inline

Definition at line 105 of file tree.

105 {return m_childs;}

◆ clear()

void tools::xml::tree::clear ( )
inlineprotected

Definition at line 919 of file tree.

919  {
920  m_atbs.clear();
921 
922  // TOOLS_STL : no std::list::erase.
923  //{std::list<tree*>::iterator it;
924  // for(it=m_children.begin();
925  // it!=m_children.end();
926  // it = m_children.erase(it))
927  // delete (*it);}
928  //
929  //{std::list<element*>::iterator it;
930  // for(it=m_elems.begin();it!=m_elems.end();it = m_elems.erase(it))
931  // delete (*it);}
932 
933  while(!m_childs.empty()) {
934  ielem* item = m_childs.front();
935  m_childs.remove(item);
936  delete item;
937  }
938  }

◆ collect_by_attribute()

static void tools::xml::tree::collect_by_attribute ( tree a_tree,
const std::string &  a_tag,
std::vector< tree * > &  a_items 
)
inlinestatic

Definition at line 533 of file tree.

535  {
536  std::string value;
537  if(a_tree.attribute_value(a_tag,value)) a_items.push_back(&a_tree);
538  tools_lforcit(ielem*,a_tree.m_childs,it) {
539  if(tree* _tree = id_cast<ielem,tree>(*(*it))) {
540  collect_by_attribute(*_tree,a_tag,a_items);
541  }
542  }
543  }

◆ collect_by_tag()

static void tools::xml::tree::collect_by_tag ( tree a_tree,
const std::string &  a_tag,
std::vector< tree * > &  a_items 
)
inlinestatic

Definition at line 351 of file tree.

351  {
352  if(a_tree.tag_name()==a_tag) a_items.push_back(&a_tree);
353  tools_lforcit(ielem*,a_tree.m_childs,it) {
354  if(tree* _tree = id_cast<ielem,tree>(*(*it))) {
355  collect_by_tag(*_tree,a_tag,a_items);
356  }
357  }
358  }

◆ copy()

bool tools::xml::tree::copy ( const tree a_from,
copy_what  a_what = copy_all,
bool  a_clear = true 
)
inline

Definition at line 475 of file tree.

477  {
478 
479  // Copy data (atbs, propertis, children) of a_from onto this.
480  if((a_what==copy_all)||(a_what==copy_attributes)) {
481  if(a_clear) m_atbs.clear();
482  tools_vforcit(atb,a_from.m_atbs,it) m_atbs.push_back(*it);
483  }
484 
485  if((a_what==copy_all)||(a_what==copy_elements)) {
486  if(a_clear) delete_sub_elems();
487  tools_lforcit(ielem*,a_from.m_childs,it) {
488  if(element* _elem = id_cast<ielem,element>(*(*it))) {
489  m_childs.push_back(new element(*_elem));
490  }
491  }
492  }
493 
494  if((a_what==copy_all)||(a_what==copy_children)) {
495  if(a_clear) delete_sub_trees();
496  tools_lforcit(ielem*,a_from.m_childs,it) {
497  if(tree* _tree = id_cast<ielem,tree>(*(*it))) {
498  //FIXME : could we have mismatch parent/child ?
499  tree* obj = _tree->create_copy(this);
500  if(!obj) {
501  // Something wrong, cleanup this.
502  clear();
503  return false;
504  }
505  add_child(obj);
506  }
507  }
508  }
509 
510  //FIXME : m_save
511 
512  return true;
513  }

◆ create_copy()

tree* tools::xml::tree::create_copy ( tree a_parent)
inline

Definition at line 450 of file tree.

450  {
451  tree* itemML = m_factory.create(m_tag_name,m_atbs,a_parent);
452  if(!itemML) return 0;
453  itemML->m_atbs = m_atbs;
454  //FIXME : m_save
455 
456  {tools_lforcit(ielem*,m_childs,it) {
457  if(element* _elem = id_cast<ielem,element>(*(*it))) {
458  itemML->m_childs.push_back(new element(*_elem));
459  }}}
460 
461  {tools_lforcit(ielem*,m_childs,it) {
462  if(tree* _tree = id_cast<ielem,tree>(*(*it))) {
463  //FIXME : could we have mismatch parent/child ?
464  tree* obj = _tree->create_copy(itemML);
465  if(!obj) {
466  delete itemML;
467  return 0;
468  }
469  itemML->add_child(obj);
470  }}}
471 
472  return itemML;
473  }

◆ delete_element() [1/2]

void tools::xml::tree::delete_element ( const std::string &  a_name)
inline

Definition at line 736 of file tree.

736  {
737  tools_lforit(ielem*,m_childs,it) {
738  if(element* _elem = id_cast<ielem,element>(*(*it))) {
739  if(a_name==_elem->name()) {
740  m_childs.erase(it);
741  delete _elem;
742  break;
743  }
744  }}
745  }

◆ delete_element() [2/2]

void tools::xml::tree::delete_element ( element a_element)
inline

Definition at line 747 of file tree.

747  {
748  tools_lforit(ielem*,m_childs,it) {
749  if(element* _elem = id_cast<ielem,element>(*(*it))) {
750  if(_elem==a_element) {
751  m_childs.erase(it);
752  delete _elem;
753  break;
754  }
755  }}
756  }

◆ delete_sub_elems()

void tools::xml::tree::delete_sub_elems ( )
inline

Definition at line 770 of file tree.

770  {
771  std::list<ielem*>::iterator it;
772  for(it=m_childs.begin();it!=m_childs.end();) {
773  if(element* _elem = id_cast<ielem,element>(*(*it))) {
774  it = m_childs.erase(it);
775  delete _elem;
776  } else {
777  it++;
778  }
779  }
780  }

◆ delete_sub_trees()

void tools::xml::tree::delete_sub_trees ( )
inline

Definition at line 758 of file tree.

758  {
759  std::list<ielem*>::iterator it;
760  for(it=m_childs.begin();it!=m_childs.end();) {
761  if(tree* _tree = id_cast<ielem,tree>(*(*it))) {
762  it = m_childs.erase(it);
763  delete _tree;
764  } else {
765  it++;
766  }
767  }
768  }

◆ depth()

unsigned int tools::xml::tree::depth ( ) const
inline

Definition at line 912 of file tree.

912 {return m_depth;}

◆ dump_xml()

void tools::xml::tree::dump_xml ( std::ostream &  a_out,
const std::string &  a_spaces = "" 
)
inline

Definition at line 618 of file tree.

618  {
619 
620  // begin tag :
621  a_out << a_spaces << "<" << m_tag_name;
622  {size_t atbn = m_atbs.size();
623  for(size_t index=0;index<atbn;index++) {
624  a_out << " " << m_atbs[index].first << "="
625  << sout(m_atbs[index].second);
626  }}
627  a_out << ">" << std::endl;
628 
629  {tools_lforcit(ielem*,m_childs,it) {
630  if(element* _elem = id_cast<ielem,element>(*(*it))) {
631 
632  const std::vector<atb>& atbs = _elem->attributes();
633 
634  bool isCallback = false;
635 
636  a_out << a_spaces << " <" << _elem->name();
637  size_t atbn = atbs.size();
638  for(size_t index=0;index<atbn;index++) {
639  a_out << " " << atbs[index].first << "="
640  << sout(atbs[index].second);
641  if(atbs[index].first=="exec") isCallback = true;
642  }
643  if(_elem->value().empty()) {
644  a_out << "/>" << std::endl;
645  } else {
646  a_out << ">";
647  std::string value = to_xml(_elem->value());
648  if(isCallback) {
649  if(value.find("\\n\\")==std::string::npos) {
650  a_out << value;
651  } else {
652  a_out << std::endl;
653  replace_(value,"\\n\\","@OnX@");
654  replace_(value,"@OnX@","\\n\\\n");
655  strip(value,trailing,' ');
656  a_out << value;
657  size_t l = value.size();
658  if(l && value[l-1]!='\n') a_out << std::endl;
659  a_out << a_spaces << " ";
660  }
661  } else {
662  a_out << value;
663  }
664  a_out << "</" << _elem->name() << ">" << std::endl;
665  }
666  }}}
667 
668  // End tag :
669  a_out << a_spaces << "</" << m_tag_name << ">" << std::endl;
670  }

◆ element_atb_value() [1/2]

bool tools::xml::tree::element_atb_value ( const std::string &  a_elem,
const std::string &  a_atb,
std::string &  a_value 
) const
inline

Definition at line 223 of file tree.

223  {
224  a_value.clear();
225  tools_lforcit(ielem*,m_childs,it) {
226  if(element* _elem = id_cast<ielem,element>(*(*it))) {
227  if(a_elem==_elem->name()) {
228  if(_elem->attribute_value(a_atb,a_value)) return true;
229  }
230  }
231  }
232  return false;
233  }

◆ element_atb_value() [2/2]

template<class T >
bool tools::xml::tree::element_atb_value ( const std::string &  a_elem,
const std::string &  a_atb,
T &  a_value 
) const
inline

Definition at line 236 of file tree.

236  {
237  std::string sv;
238  if(!element_atb_value(a_elem,a_atb,sv)) {a_value=T();return false;}
239  return to<T>(sv,a_value);
240  }

◆ element_value()

bool tools::xml::tree::element_value ( const std::string &  a_name,
std::string &  a_value 
) const
inline

Definition at line 180 of file tree.

180  {
181  tools_lforcit(ielem*,m_childs,it) {
182  if(element* _elem = id_cast<ielem,element>(*(*it))) {
183  if(a_name==_elem->name()) {
184  a_value = _elem->value();
185  return true;
186  }
187  }
188  }
189  a_value.clear();
190  return false;
191  }

◆ element_value_boolean()

bool tools::xml::tree::element_value_boolean ( const std::string &  a_name,
bool &  a_value 
) const
inline

Definition at line 793 of file tree.

793  {
794  std::string value;
795  if(!element_value(a_name,value)) return false;
796  return to(value,a_value);
797  }

◆ element_values()

bool tools::xml::tree::element_values ( const std::string &  a_name,
std::vector< std::string > &  a_values 
) const
inline

Definition at line 545 of file tree.

546  {
547  a_values.clear();
548  tools_lforcit(ielem*,m_childs,it) {
549  if(element* _elem = id_cast<ielem,element>(*(*it))) {
550  if(a_name==_elem->name()) {
551  a_values.push_back(_elem->value());
552  }
553  }
554  }
555  return true;
556  }

◆ file()

const std::string& tools::xml::tree::file ( ) const
inline

Definition at line 916 of file tree.

916 {return m_file;}

◆ find_by_attribute()

tree* tools::xml::tree::find_by_attribute ( const std::string &  a_atb,
const std::string &  a_value,
bool  a_up_down = true,
bool  a_left_right = true 
) const
inline

Definition at line 568 of file tree.

569  {
570  if(a_up_down) {
571  std::string s;
572  attribute_value(a_atb,s);
573  if(s==a_value) return const_cast<tree*>(this);
574 
575  if(a_left_right) {
576  tools_lforcit(ielem*,m_childs,it) {
577  if(tree* _tree = id_cast<ielem,tree>(*(*it))) {
578  tree* itemML =
579  _tree->find_by_attribute(a_atb,a_value,a_up_down,a_left_right);
580  if(itemML) return itemML;
581  }
582  }
583  } else {
584  std::list<ielem*>::const_reverse_iterator it;
585  for(it=m_childs.rbegin();it!=m_childs.rend();++it) {
586  if(tree* _tree = id_cast<ielem,tree>(*(*it))) {
587  tree* itemML =
588  _tree->find_by_attribute(a_atb,a_value,a_up_down,a_left_right);
589  if(itemML) return itemML;
590  }}
591  }
592  } else {
593  if(a_left_right) {
594  tools_lforcit(ielem*,m_childs,it) {
595  if(tree* _tree = id_cast<ielem,tree>(*(*it))) {
596  tree* itemML =
597  _tree->find_by_attribute(a_atb,a_value,a_up_down,a_left_right);
598  if(itemML) return itemML;
599  }}
600  } else {
601  std::list<ielem*>::const_reverse_iterator it;
602  for(it=m_childs.rbegin();it!=m_childs.rend();++it) {
603  if(tree* _tree = id_cast<ielem,tree>(*(*it))) {
604  tree* itemML =
605  _tree->find_by_attribute(a_atb,a_value,a_up_down,a_left_right);
606  if(itemML) return itemML;
607  }}
608  }
609 
610  std::string s;
611  attribute_value(a_atb,s);
612  if(s==a_value) return const_cast<tree*>(this);
613 
614  }
615  return 0;
616  }

◆ find_by_element_in_same_level()

const tree* tools::xml::tree::find_by_element_in_same_level ( const std::string &  a_name,
const std::string &  a_value 
) const
inline

Definition at line 782 of file tree.

783  {
784  // Look children :
785  tools_lforcit(ielem*,m_childs,it) {
786  if(tree* _tree = id_cast<ielem,tree>(*(*it))) {
787  std::string s;
788  if(_tree->element_value(a_name,s) && (a_value==s)) return _tree;
789  }}
790  return 0;
791  }

◆ find_by_tag()

tree* tools::xml::tree::find_by_tag ( const std::string &  a_tag) const
inline

Definition at line 360 of file tree.

360  {
361  if(tag_name()==a_tag) return const_cast<tree*>(this);
362  // Look children :
363  tools_lforcit(ielem*,m_childs,it) {
364  if(tree* _tree = id_cast<ielem,tree>(*(*it))) {
365  tree* itemML = _tree->find_by_tag(a_tag);
366  if(itemML) return itemML;
367  }}
368  return 0;
369  }

◆ find_item()

tree* tools::xml::tree::find_item ( const std::string &  a_name) const
inline

Definition at line 396 of file tree.

396  {
397  {size_t linen = m_atbs.size();
398  for(unsigned int count=0;count<linen;count++) {
399  if(m_atbs[count].first=="name") {
400  if(m_atbs[count].second==a_name) return const_cast<tree*>(this);
401  break;
402  }
403  }}
404 
405  // Look children :
406  tools_lforcit(ielem*,m_childs,it) {
407  if(tree* _tree = id_cast<ielem,tree>(*(*it))) {
408  tree* item = _tree->find_item(a_name);
409  if(item) return item;
410  }}
411  return 0;
412  }

◆ find_item_with_tag()

tree* tools::xml::tree::find_item_with_tag ( const std::string &  a_tag,
const std::string &  a_name 
) const
inline

Definition at line 414 of file tree.

415  {
416  if(a_tag==tag_name()) {
417  std::string s;
418  attribute_value("name",s);
419  if(a_name==s) return const_cast<tree*>(this);
420  }
421 
422  // Look children :
423  tools_lforcit(ielem*,m_childs,it) {
424  if(tree* _tree = id_cast<ielem,tree>(*(*it))) {
425  tree* item = _tree->find_item_with_tag(a_tag,a_name);
426  if(item) return item;
427  }}
428  return 0;
429  }

◆ get_data()

void tools::xml::tree::get_data ( void *&  a_data_1,
void *&  a_data_2,
int &  a_data_int 
) const
inline

Definition at line 903 of file tree.

903  {
904  a_data_1 = m_data_1;
905  a_data_2 = m_data_2;
906  a_data_int = m_data_int;
907  }

◆ get_data1()

void* tools::xml::tree::get_data1 ( ) const
inline

Definition at line 908 of file tree.

908 {return m_data_1;}

◆ get_data2()

void* tools::xml::tree::get_data2 ( ) const
inline

Definition at line 909 of file tree.

909 {return m_data_2;}

◆ get_data_int()

int tools::xml::tree::get_data_int ( ) const
inline

Definition at line 910 of file tree.

910 {return m_data_int;}

◆ has_empty_attribute_value()

bool tools::xml::tree::has_empty_attribute_value ( std::ostream &  a_out) const
inline

Definition at line 286 of file tree.

286  {
287  empty_visitor visitor(a_out);
288  visitor.m_status = true;
289  const_cast<tree*>(this)->post_execute(check_item,&visitor);
290  return visitor.m_status;
291  }

◆ id_class()

static cid tools::xml::tree::id_class ( )
inlinestatic

Definition at line 51 of file tree.

51 {return 1;}

◆ invalidate()

virtual bool tools::xml::tree::invalidate ( )
inlinevirtual

Definition at line 103 of file tree.

103 {return true;}

◆ is_attribute()

bool tools::xml::tree::is_attribute ( const std::string &  a_name) const
inline

Definition at line 117 of file tree.

117  {
118  size_t number = m_atbs.size();
119  for(size_t index=0;index<number;index++) {
120  if(m_atbs[index].first==a_name) return true;
121  }
122  return false;
123  }

◆ is_element()

bool tools::xml::tree::is_element ( const std::string &  a_name) const
inline

for osc //////////////////////////////////////

Definition at line 245 of file tree.

245  {
246  tools_lforcit(ielem*,m_childs,it) {
247  if(element* _elem = id_cast<ielem,element>(*(*it))) {
248  if(a_name==_elem->name()) return true;
249  }
250  }
251  return false;
252  }

◆ number_of_trees()

unsigned int tools::xml::tree::number_of_trees ( ) const
inline

Definition at line 832 of file tree.

832  {
833  unsigned int number = 0;
834  tools_lforcit(ielem*,m_childs,it) {
835  if(id_cast<ielem,tree>(*(*it))) number++;
836  }
837  return number;
838  }

◆ operator=()

tree& tools::xml::tree::operator= ( const tree )
inlineprotected

Definition at line 100 of file tree.

100 {return *this;}

◆ parent()

tree* tools::xml::tree::parent ( ) const
inline

end osc //////////////////////////////////////

sub trees /////////////////////////////////////////

Definition at line 828 of file tree.

828 {return m_parent;}

◆ post_execute()

void tools::xml::tree::post_execute ( exec_func  a_function,
void *  a_tag 
)
inline

Definition at line 302 of file tree.

302  {
303  if(!a_function) return;
304 
305  if(!a_function(*this,a_tag)) return;
306 
307  tools_lforcit(ielem*,m_childs,it) {
308  if(tree* _tree = id_cast<ielem,tree>(*(*it))) {
309  _tree->post_execute(a_function,a_tag);
310  }
311  }
312  }

◆ post_execute_backward()

void tools::xml::tree::post_execute_backward ( exec_func  a_function,
void *  a_tag 
)
inline

Definition at line 558 of file tree.

558  {
559  if(!a_function) return;
560  tools_lforcit(ielem*,m_childs,it) {
561  if(tree* _tree = id_cast<ielem,tree>(*(*it))) {
562  _tree->post_execute_backward(a_function,a_tag);
563  }
564  }
565  if(!a_function(*this,a_tag)) return;
566  }

◆ remove_attribute()

bool tools::xml::tree::remove_attribute ( const std::string &  a_name)
inline

Definition at line 160 of file tree.

160  {
161  //TOOLS_STL : to be checked :
162  std::vector<atb>::iterator it = m_atbs.begin();
163  size_t linen = m_atbs.size();
164  for(size_t count=0;count<linen;count++,++it) {
165  if(m_atbs[count].first==a_name) {
166  m_atbs.erase(it);
167  return true; //Found and removed.
168  }
169  }
170  return false; //Not found.
171  }

◆ remove_attributes()

void tools::xml::tree::remove_attributes ( const std::string &  a_atb)
inline

Definition at line 149 of file tree.

149  {
150  std::vector<atb>::iterator it;
151  for(it=m_atbs.begin();it!=m_atbs.end();) {
152  if((*it).first==a_atb) {
153  it = m_atbs.erase(it);
154  } else {
155  ++it;
156  }
157  }
158  }

◆ remove_child()

void tools::xml::tree::remove_child ( tree *&  a_tree,
bool  a_delete = true 
)
inline

Definition at line 840 of file tree.

840  {
841  m_childs.remove(a_tree);
842  if(a_delete) {
843  delete a_tree;
844  a_tree = 0;
845  }
846  }

◆ remove_elements()

void tools::xml::tree::remove_elements ( const std::string &  a_name)
inline

Definition at line 431 of file tree.

431  {
432  // TOOLS_STL : to be checked :
433  std::list<ielem*>::iterator it;
434  for(it=m_childs.begin();it!=m_childs.end();) {
435  if(element* _elem = id_cast<ielem,element>(*(*it))) {
436  if(a_name==_elem->name()) {
437  it = m_childs.erase(it);
438  delete _elem;
439  } else {
440  ++it;
441  }
442  } else {
443  ++it;
444  }
445  }
446  }

◆ replace()

void tools::xml::tree::replace ( const std::string &  a_old,
const std::string &  a_new 
)
inline

Definition at line 516 of file tree.

516  {
517  // Used by the obuild template system.
518  {size_t atbn = m_atbs.size();
519  for(size_t index=0;index<atbn;index++) {
520  std::string& value = m_atbs[index].second;
521  replace_(value,a_old,a_new);
522  }}
523 
524  tools_lforit(ielem*,m_childs,it) {
525  if(tree* _tree = id_cast<ielem,tree>(*(*it))) {
526  _tree->replace(a_old,a_new);
527  } else if(element* _elem = id_cast<ielem,element>(*(*it))) {
528  _elem->replace(a_old,a_new);
529  }
530  }
531  }

◆ replace_child()

bool tools::xml::tree::replace_child ( tree a_old,
tree a_new 
)
inline

Definition at line 719 of file tree.

719  {
720  tools_lforit(ielem*,m_childs,it) {
721  if(tree* _tree = id_cast<ielem,tree>(*(*it))) {
722  if(_tree==a_old) {
723  (*it) = a_new;
724  return true; //replacement done.
725  }
726  }}
727  return false; //no replacement done.
728  }

◆ save_flag()

bool tools::xml::tree::save_flag ( ) const
inline

Definition at line 914 of file tree.

914 {return m_save;}

◆ set_attribute_value()

bool tools::xml::tree::set_attribute_value ( const std::string &  a_atb,
const std::string &  a_value 
)
inline

Definition at line 274 of file tree.

274  {
275  tools_vforit(atb,m_atbs,it) {
276  if((*it).first==a_atb) {
277  (*it).second = a_value;
278  return true;
279  }
280  }
281  // Not found, add one :
282  m_atbs.push_back(atb(a_atb,a_value));
283  return true;
284  }

◆ set_attributes()

void tools::xml::tree::set_attributes ( const std::vector< atb > &  a_atbs)
inline

Definition at line 125 of file tree.

125  {
126  m_atbs = a_atbs;
127  }

◆ set_data()

void tools::xml::tree::set_data ( void *  a_data_1,
void *  a_data_2,
int  a_data_int 
)
inline

Definition at line 898 of file tree.

898  {
899  m_data_1 = a_data_1;
900  m_data_2 = a_data_2;
901  m_data_int = a_data_int;
902  }

◆ set_depth()

void tools::xml::tree::set_depth ( unsigned int  a_depth)
inline

Definition at line 911 of file tree.

911 {m_depth = a_depth;}

◆ set_element_atb_value()

bool tools::xml::tree::set_element_atb_value ( const std::string &  a_elem,
const std::string &  a_atb,
const std::string &  a_value,
int  a_index = 0 
)
inline

Definition at line 672 of file tree.

674  {
675  if(a_elem.empty()) {
676  size_t linen = m_atbs.size();
677  for(size_t count=0;count<linen;count++) {
678  if(m_atbs[count].first==a_atb) {
679  m_atbs[count].second = a_value;
680  return true;
681  }
682  }
683  // Not found, add it :
684  m_atbs.push_back(atb(a_atb,a_value));
685  return true;
686  } else {
687  int index = 0;
688  tools_lforcit(ielem*,m_childs,it) {
689  if(element* _elem = id_cast<ielem,element>(*(*it))) {
690  if(a_elem==_elem->name()) {
691  if(index==a_index) {
692  _elem->set_attribute_value(a_atb,a_value);
693  return true;
694  } else {
695  index++;
696  }
697  }
698  }}
699  return false;
700  }
701  }

◆ set_element_value()

bool tools::xml::tree::set_element_value ( const std::string &  a_name,
const std::string &  a_value,
int  a_index = 0 
)
inline

Definition at line 254 of file tree.

254  {
255  int index = 0;
256  tools_lforcit(ielem*,m_childs,it) {
257  if(element* _elem = id_cast<ielem,element>(*(*it))) {
258  if(a_name==_elem->name()) {
259  if(index==a_index) {
260  _elem->set_value(a_value);
261  return true;
262  } else {
263  index ++;
264  }
265  }
266  }
267  }
268  // Not found, add one :
269  std::vector<atb> atts;
270  add_element(a_name,atts,a_value);
271  return true;
272  }

◆ set_file()

void tools::xml::tree::set_file ( const std::string &  a_file)
inline

Definition at line 915 of file tree.

915 {m_file = a_file;}

◆ set_parent()

void tools::xml::tree::set_parent ( tree a_parent)
inline

Definition at line 830 of file tree.

830 {m_parent = a_parent;}

◆ set_save_flag()

void tools::xml::tree::set_save_flag ( bool  a_value)
inline

Definition at line 913 of file tree.

913 {m_save = a_value;}

◆ sub_elems()

void tools::xml::tree::sub_elems ( std::list< element * > &  a_list) const
inline

Definition at line 711 of file tree.

711  {
712  a_list.clear();
713  tools_lforcit(ielem*,m_childs,it) {
714  if(element* _elem = id_cast<ielem,element>(*(*it))) {
715  a_list.push_back(_elem);
716  }}
717  }

◆ sub_trees()

void tools::xml::tree::sub_trees ( std::list< tree * > &  a_list) const
inline

Definition at line 704 of file tree.

704  {
705  a_list.clear();
706  tools_lforcit(ielem*,m_childs,it) {
707  if(tree* _tree = id_cast<ielem,tree>(*(*it))) {
708  a_list.push_back(_tree);
709  }}
710  }

◆ tag_name()

const std::string& tools::xml::tree::tag_name ( ) const
inline

Definition at line 128 of file tree.

128 {return m_tag_name;}

◆ unique()

static void tools::xml::tree::unique ( std::vector< tree * > &  a_items)
inlinestatic

Definition at line 371 of file tree.

371  {
372  std::vector<tree*> items2;
373 
374  tools_vforcit(tree*,a_items,it) {
375  std::string name;
376  if(!(*it)->attribute_value("name",name)) continue;
377  if(name.empty()) continue;
378 
379  bool found = false;
380  {tools_vforit(tree*,items2,it2) {
381  std::string name2;
382  (*it2)->attribute_value("name",name2);
383  if(name2==name) {
384  found = true;
385  break;
386  }
387  }}
388  if(!found) {
389  items2.push_back(*it);
390  }
391  }
392 
393  a_items = items2;
394  }

◆ update_tree()

void tools::xml::tree::update_tree ( const tree a_old)
inline

Definition at line 799 of file tree.

799  {
800  // We map the opened elements in the old tree within this tree.
801  // Algorithm based on the existence of a "label" element.
802  tools_lforit(ielem*,m_childs,it) {
803  if(tree* _tree = id_cast<ielem,tree>(*(*it))) {
804  std::string slabel;
805  if(_tree->element_value("label",slabel)) {
806  // Try to find a same label in the same level :
807  const tree* item =
808  a_old.find_by_element_in_same_level("label",slabel);
809  if(item) {
810  bool sopened;
811  if(item->element_value_boolean("opened",sopened) && sopened) {
812  _tree->set_element_value("opened","true");
813  }
814  if(a_old.number_of_trees()) _tree->update_tree(*item);
815  }
816  }
817  }}
818  }

Member Data Documentation

◆ m_atbs

std::vector<atb> tools::xml::tree::m_atbs
protected

Definition at line 947 of file tree.

◆ m_childs

std::list<ielem*> tools::xml::tree::m_childs
protected

Definition at line 946 of file tree.

◆ m_data_1

void* tools::xml::tree::m_data_1
protected

Definition at line 950 of file tree.

◆ m_data_2

void* tools::xml::tree::m_data_2
protected

Definition at line 951 of file tree.

◆ m_data_int

int tools::xml::tree::m_data_int
protected

Definition at line 952 of file tree.

◆ m_depth

int tools::xml::tree::m_depth
protected

Definition at line 953 of file tree.

◆ m_factory

factory& tools::xml::tree::m_factory
protected

Definition at line 942 of file tree.

◆ m_file

std::string tools::xml::tree::m_file
protected

Definition at line 948 of file tree.

◆ m_parent

tree* tools::xml::tree::m_parent
protected

Definition at line 943 of file tree.

◆ m_save

bool tools::xml::tree::m_save
protected

Definition at line 949 of file tree.

◆ m_tag_name

std::string tools::xml::tree::m_tag_name
protected

Definition at line 941 of file tree.


The documentation for this class was generated from the following file:
tools::xml::tree::add_element
void add_element(const std::string &a_name, const std::vector< atb > &a_atbs, const std::string &a_value)
elements //////////////////////////////////////////
Definition: tree:176
tools::xml::tree::m_parent
tree * m_parent
Definition: tree:943
tools::xml::tree::clear
void clear()
Definition: tree:919
tools::xml::tree::m_data_2
void * m_data_2
Definition: tree:951
tools::xml::tree::collect_by_tag
static void collect_by_tag(tree &a_tree, const std::string &a_tag, std::vector< tree * > &a_items)
Definition: tree:351
tools::xml::tree::copy_elements
@ copy_elements
Definition: tree:59
tools::xml::tree::m_depth
int m_depth
Definition: tree:953
tools::xml::tree::attribute_value
bool attribute_value(const std::string &a_atb, std::string &a_value) const
Definition: tree:130
tools::xml::tree::delete_sub_trees
void delete_sub_trees()
Definition: tree:758
tools::xml::tree::m_save
bool m_save
Definition: tree:949
tools::xml::tree::add_child
void add_child(tree *a_tree)
Definition: tree:448
tools::trailing
@ trailing
Definition: strip:12
tools::xml::tree::element_value
bool element_value(const std::string &a_name, std::string &a_value) const
Definition: tree:180
tools_lforcit
#define tools_lforcit(a__T, a__l, a__it)
Definition: forit:40
tools::to_xml
std::string to_xml(const std::string &a_string)
Definition: srep:68
tools::xml::factory::create
virtual tree * create(const std::string &a_tag_name, const std::vector< atb > &a_atbs, tree *a_parent)=0
tools::xml::tree::post_execute
void post_execute(exec_func a_function, void *a_tag)
Definition: tree:302
tools::xml::tree::m_data_int
int m_data_int
Definition: tree:952
tools::xml::tree::m_factory
factory & m_factory
Definition: tree:942
tools::xml::tree::m_atbs
std::vector< atb > m_atbs
Definition: tree:947
tools::to
std::vector< std::string > to(int a_argc, char **a_argv)
Definition: args:507
tools_vforit
#define tools_vforit(a__T, a__v, a__it)
Definition: forit:13
tools::xml::tree::tree
tree(const std::string &a_tag_name, factory &a_factory, tree *a_parent)
Definition: tree:61
tools::xml::tree::element_atb_value
bool element_atb_value(const std::string &a_elem, const std::string &a_atb, std::string &a_value) const
Definition: tree:223
tools::xml::tree::delete_sub_elems
void delete_sub_elems()
Definition: tree:770
tools::replace_
bool replace_(std::string &a_string, const std::string &a_old, const std::string &a_new)
Definition: srep:44
tools::xml::tree::m_tag_name
std::string m_tag_name
Definition: tree:941
tools::xml::tree::m_file
std::string m_file
Definition: tree:948
tools::xml::tree::m_data_1
void * m_data_1
Definition: tree:950
tools_lforit
#define tools_lforit(a__T, a__l, a__it)
Definition: forit:43
tools::xml::tree::copy_children
@ copy_children
Definition: tree:59
tools::file::found
bool found(const std::string &a_file, const std::string &a_what, std::vector< std::string > &a_found)
Definition: file:507
tools::xml::tree::tag_name
const std::string & tag_name() const
Definition: tree:128
tools::strip
bool strip(std::string &a_string, what a_type=both, char a_char=' ')
Definition: strip:14
tools::xml::tree::copy_attributes
@ copy_attributes
Definition: tree:59
tools_vforcit
#define tools_vforcit(a__T, a__v, a__it)
Definition: forit:7
tools::xml::tree::collect_by_attribute
static void collect_by_attribute(tree &a_tree, const std::string &a_tag, std::vector< tree * > &a_items)
Definition: tree:533
tools::xml::tree::atb
std::pair< std::string, std::string > atb
Definition: tree:57
tools::xml::tree::copy_all
@ copy_all
Definition: tree:59
tools::xml::tree::m_childs
std::list< ielem * > m_childs
Definition: tree:946
tools::xml::tree::check_item
static bool check_item(tree &a_tree, void *a_tag)
Definition: tree:314