core/vsl/vsl_basic_xml_element.cxx

Go to the documentation of this file.
00001 // This is core/vsl/vsl_basic_xml_element.cxx
00002 #include "vsl_basic_xml_element.h"
00003 //:
00004 // \file
00005 
00006 void vsl_basic_xml_element::add_attribute_list(vcl_vector<vcl_pair<vcl_string, vcl_string> > attrs)
00007 {
00008   for (unsigned int i=0; i<attrs.size(); i++) {
00009     attrs_.push_back(attrs[i]);
00010   }
00011 }
00012 
00013 void vsl_basic_xml_element::add_attribute(vcl_string attr_name, double value)
00014 {
00015   vcl_string value_str = toString(value);
00016   vcl_pair<vcl_string, vcl_string> attr(attr_name, value_str.data());
00017   attrs_.push_back(attr);
00018 }
00019 
00020 void vsl_basic_xml_element::add_attribute(vcl_string attr_name, int value)
00021 {
00022   vcl_string value_str = toString(value); 
00023   vcl_pair<vcl_string, vcl_string> attr(attr_name, value_str);
00024   attrs_.push_back(attr);
00025 }
00026 
00027 void vsl_basic_xml_element::add_attribute(vcl_string attr_name, unsigned long value)
00028 {
00029   vcl_string value_str = toString(value);
00030   vcl_pair<vcl_string, vcl_string> attr(attr_name, value_str);
00031   attrs_.push_back(attr);
00032 }
00033 
00034 void vsl_basic_xml_element::add_attribute(vcl_string attr_name, vcl_string value)
00035 {
00036   vcl_pair<vcl_string, vcl_string> attr(attr_name, value);
00037   attrs_.push_back(attr);
00038 }
00039 
00040 void vsl_basic_xml_element::append_cdata(vcl_string cdata)
00041 {
00042   if (cdata_.size() > 0)
00043     cdata_.append(" ");
00044   cdata_.append(cdata);
00045 }
00046 
00047 void vsl_basic_xml_element::append_cdata(double cdata)
00048 {
00049   if (cdata_.size() > 0)
00050     cdata_.append(" ");
00051   cdata_.append(toString(cdata));
00052 }
00053 
00054 void vsl_basic_xml_element::append_cdata(int cdata)
00055 {
00056   if (cdata_.size() > 0)
00057     cdata_.append(" ");
00058   cdata_.append(toString(cdata));
00059 }
00060 
00061 bool vsl_basic_xml_element::delete_attribute(vcl_string attr_name)
00062 {
00063   return false;
00064 }
00065 
00066 void vsl_basic_xml_element::x_write(vcl_ostream& ostr)
00067 {
00068   // put the initial bracket with element name and the attribute-value list
00069   x_write_open(ostr);
00070 
00071   // put the character data between the tags
00072   if (cdata_.size() > 0)
00073     ostr << cdata_ << '\n';
00074 
00075   // close the element
00076   x_write_close(ostr);
00077 }
00078 
00079 void vsl_basic_xml_element::x_write_open(vcl_ostream& ostr)
00080 {
00081   ostr << '<' << tag_;
00082   for (unsigned int i=0; i<attrs_.size(); i++) {
00083     ostr << ' ' << attrs_[i].first << "=\"" << attrs_[i].second << '"';
00084   }
00085   ostr << ">\n";
00086 }
00087 
00088 //: writes the closing tag to the stream
00089 void vsl_basic_xml_element::x_write_close(vcl_ostream& ostr)
00090 {
00091   ostr << "</" << tag_ << ">\n";
00092 }

Generated on Sat Oct 11 05:05:49 2008 for core/vsl by  doxygen 1.5.1