11 #include "../S_STRING"
42 typedef std::pair<std::string,std::string>
atb;
44 virtual tree*
create(
const std::string& a_tag_name,
const std::vector<atb>& a_atbs,
tree* a_parent) = 0;
53 if(
void* p = cmp_cast<tree>(
this,a_class)) {
return p;}
57 typedef std::pair<std::string,std::string>
atb;
72 mem::increment(s_class().c_str());
79 mem::decrement(s_class().c_str());
96 mem::increment(s_class().c_str());
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;
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;
146 return to<T>(sv,a_value);
150 std::vector<atb>::iterator it;
152 if((*it).first==a_atb) {
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) {
176 void add_element(
const std::string& a_name,
const std::vector<atb>& a_atbs,
const std::string& a_value){
182 if(
element* _elem = id_cast<ielem,element>(*(*it))) {
183 if(a_name==_elem->name()) {
184 a_value = _elem->value();
223 bool element_atb_value(
const std::string& a_elem,
const std::string& a_atb,std::string& a_value)
const {
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;
239 return to<T>(sv,a_value);
247 if(
element* _elem = id_cast<ielem,element>(*(*it))) {
248 if(a_name==_elem->name())
return true;
257 if(
element* _elem = id_cast<ielem,element>(*(*it))) {
258 if(a_name==_elem->name()) {
260 _elem->set_value(a_value);
269 std::vector<atb> atts;
276 if((*it).first==a_atb) {
277 (*it).second = a_value;
303 if(!a_function)
return;
305 if(!a_function(*
this,a_tag))
return;
308 if(
tree* _tree = id_cast<ielem,tree>(*(*it))) {
309 _tree->post_execute(a_function,a_tag);
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;
323 visitor->
f_out <<
"check_item :"
325 <<
", attribute " <<
sout(_atb) <<
" has an empty value."
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;
339 visitor->
f_out <<
"ItemM::check_item :"
341 <<
", attribute " <<
sout(_atb) <<
" has an empty value."
352 if(a_tree.
tag_name()==a_tag) a_items.push_back(&a_tree);
354 if(
tree* _tree = id_cast<ielem,tree>(*(*it))) {
364 if(
tree* _tree = id_cast<ielem,tree>(*(*it))) {
366 if(itemML)
return itemML;
371 static void unique(std::vector<tree*>& a_items) {
372 std::vector<tree*> items2;
376 if(!(*it)->attribute_value(
"name",name))
continue;
377 if(name.empty())
continue;
382 (*it2)->attribute_value(
"name",name2);
389 items2.push_back(*it);
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);
407 if(
tree* _tree = id_cast<ielem,tree>(*(*it))) {
409 if(item)
return item;
415 const std::string& a_name)
const {
419 if(a_name==s)
return const_cast<tree*
>(
this);
424 if(
tree* _tree = id_cast<ielem,tree>(*(*it))) {
426 if(item)
return item;
433 std::list<ielem*>::iterator it;
435 if(
element* _elem = id_cast<ielem,element>(*(*it))) {
436 if(a_name==_elem->name()) {
452 if(!itemML)
return 0;
457 if(
element* _elem = id_cast<ielem,element>(*(*it))) {
462 if(
tree* _tree = id_cast<ielem,tree>(*(*it))) {
477 bool a_clear =
true){
481 if(a_clear)
m_atbs.clear();
488 if(
element* _elem = id_cast<ielem,element>(*(*it))) {
497 if(
tree* _tree = id_cast<ielem,tree>(*(*it))) {
516 void replace(
const std::string& a_old,
const std::string& a_new) {
518 {
size_t atbn =
m_atbs.size();
519 for(
size_t index=0;index<atbn;index++) {
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);
534 const std::string& a_tag,
535 std::vector<tree*>& a_items) {
539 if(
tree* _tree = id_cast<ielem,tree>(*(*it))) {
546 std::vector<std::string>& a_values)
const {
549 if(
element* _elem = id_cast<ielem,element>(*(*it))) {
550 if(a_name==_elem->name()) {
551 a_values.push_back(_elem->value());
559 if(!a_function)
return;
561 if(
tree* _tree = id_cast<ielem,tree>(*(*it))) {
562 _tree->post_execute_backward(a_function,a_tag);
565 if(!a_function(*
this,a_tag))
return;
569 bool a_up_down =
true,
bool a_left_right =
true)
const {
573 if(s==a_value)
return const_cast<tree*
>(
this);
577 if(
tree* _tree = id_cast<ielem,tree>(*(*it))) {
580 if(itemML)
return itemML;
584 std::list<ielem*>::const_reverse_iterator it;
586 if(
tree* _tree = id_cast<ielem,tree>(*(*it))) {
589 if(itemML)
return itemML;
595 if(
tree* _tree = id_cast<ielem,tree>(*(*it))) {
598 if(itemML)
return itemML;
601 std::list<ielem*>::const_reverse_iterator it;
603 if(
tree* _tree = id_cast<ielem,tree>(*(*it))) {
606 if(itemML)
return itemML;
612 if(s==a_value)
return const_cast<tree*
>(
this);
618 void dump_xml(std::ostream& a_out,
const std::string& a_spaces =
"") {
622 {
size_t atbn =
m_atbs.size();
623 for(
size_t index=0;index<atbn;index++) {
624 a_out <<
" " <<
m_atbs[index].first <<
"="
627 a_out <<
">" << std::endl;
630 if(
element* _elem = id_cast<ielem,element>(*(*it))) {
632 const std::vector<atb>& atbs = _elem->attributes();
634 bool isCallback =
false;
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;
643 if(_elem->value().empty()) {
644 a_out <<
"/>" << std::endl;
649 if(
value.find(
"\\n\\")==std::string::npos) {
657 size_t l =
value.size();
658 if(l &&
value[l-1]!=
'\n') a_out << std::endl;
659 a_out << a_spaces <<
" ";
664 a_out <<
"</" << _elem->name() <<
">" << std::endl;
669 a_out << a_spaces <<
"</" <<
m_tag_name <<
">" << std::endl;
673 const std::string& a_atb,
674 const std::string& a_value,
int a_index = 0){
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;
689 if(
element* _elem = id_cast<ielem,element>(*(*it))) {
690 if(a_elem==_elem->name()) {
692 _elem->set_attribute_value(a_atb,a_value);
707 if(
tree* _tree = id_cast<ielem,tree>(*(*it))) {
708 a_list.push_back(_tree);
714 if(
element* _elem = id_cast<ielem,element>(*(*it))) {
715 a_list.push_back(_elem);
721 if(
tree* _tree = id_cast<ielem,tree>(*(*it))) {
731 virtual void*
cast(
const std::string& a_class)
const {
732 if(
void* p = cmp_cast<tree>(
this,a_class)) {
return p;}
738 if(
element* _elem = id_cast<ielem,element>(*(*it))) {
739 if(a_name==_elem->name()) {
749 if(
element* _elem = id_cast<ielem,element>(*(*it))) {
750 if(_elem==a_element) {
759 std::list<ielem*>::iterator it;
761 if(
tree* _tree = id_cast<ielem,tree>(*(*it))) {
771 std::list<ielem*>::iterator it;
773 if(
element* _elem = id_cast<ielem,element>(*(*it))) {
783 const std::string& a_value)
const {
786 if(
tree* _tree = id_cast<ielem,tree>(*(*it))) {
788 if(_tree->element_value(a_name,s) && (a_value==s))
return _tree;
803 if(
tree* _tree = id_cast<ielem,tree>(*(*it))) {
805 if(_tree->element_value(
"label",slabel)) {
833 unsigned int number = 0;
835 if(id_cast<ielem,tree>(*(*it))) number++;
898 void set_data(
void* a_data_1,
void* a_data_2,
int a_data_int) {
903 void get_data(
void*& a_data_1,
void*& a_data_2,
int& a_data_int)
const {
972 tree* _tree = id_cast<ielem,tree>(*(*
m_it));
973 if(_tree) {
m_it++;
return _tree;}
980 if(_elem) {
m_it++;
return _elem;}
985 std::list<ielem*>::const_iterator
m_it;
986 std::list<ielem*>::const_iterator
m_end;
994 virtual tree*
create(
const std::string& a_tag_name,
const std::vector<tree::atb>& a_atbs,
tree* a_parent) {
996 tree* itemML =
new tree(a_tag_name,*
this,a_parent);
1003 mem::increment(s_class().c_str());
1008 mem::decrement(s_class().c_str());
1015 mem::increment(s_class().c_str());