core/vsl/vsl_basic_xml_element.h

Go to the documentation of this file.
00001 // This is core/vsl/vsl_basic_xml_element.h
00002 #ifndef vsl_basic_xml_element_h_
00003 #define vsl_basic_xml_element_h_
00004 //:
00005 // \file
00006 // \brief  creates basic xml nodes and writes them out to the stream
00007 // \author Gamze Tunali (gamze@lems.brown.edu)
00008 // \date   12/21/2005
00009 //
00010 // \verbatim
00011 //  Modifications
00012 // \endverbatim
00013 
00014 #include <vcl_vector.h>
00015 #include <vcl_utility.h>
00016 #include <vcl_string.h>
00017 #include <vcl_sstream.h>
00018 #include <vcl_iostream.h>
00019 #include <vcl_iomanip.h> // for vcl_fixed
00020 
00021 template<typename T> vcl_string toString(const T& t)
00022 {
00023   vcl_stringstream strm;
00024 
00025   strm << vcl_fixed << t;
00026   vcl_string str(strm.str());
00027   return str;
00028 }
00029 
00030 class vsl_basic_xml_element
00031 {
00032  public:
00033   //: constructs with a name
00034   vsl_basic_xml_element(vcl_string tag)
00035     : tag_(tag) {}
00036 
00037   //: constructs with a name and a list of (attibute,value) pair
00038   vsl_basic_xml_element(vcl_string tag, vcl_vector<vcl_pair<vcl_string, vcl_string> > attrs)
00039     : tag_(tag), attrs_(attrs) {}
00040 
00041   //destructor
00042   ~vsl_basic_xml_element() {}
00043 
00044   //: overloaded add_attribute methods to add different types of values as string
00045   void add_attribute(vcl_string attr_name, double value);
00046   void add_attribute(vcl_string attr_name, int value);
00047   void add_attribute(vcl_string attr_name, unsigned long value);
00048   void add_attribute(vcl_string attr_name, vcl_string value);
00049 #if 0
00050   void add_attribute(vcl_pair<vcl_string, vcl_string> attr);
00051 #endif
00052 
00053   void add_attribute_list(vcl_vector<vcl_pair<vcl_string, vcl_string> > attrs);
00054 
00055   bool delete_attribute(vcl_string attr_name);
00056 
00057   void append_cdata(vcl_string cdata);
00058   void append_cdata(double cdata);
00059   void append_cdata(int cdata);
00060 
00061   void x_write(vcl_ostream& ostr);
00062   //: writes the opening tag to the stream
00063   void x_write_open(vcl_ostream& ostr);
00064 
00065   //: writes the closing tag to the stream
00066   void x_write_close(vcl_ostream& ostr); 
00067 
00068  protected:
00069   vcl_string tag_;
00070   vcl_vector<vcl_pair<vcl_string, vcl_string> > attrs_;
00071   vcl_string cdata_;
00072 };
00073 
00074 #endif // vsl_basic_xml_element_h_

Generated on Mon Oct 6 05:05:50 2008 for core/vsl by  doxygen 1.5.1