Thread: [Compbench-devel] CompBenchmarks++/System XML.cpp, NONE, 1.1 XML.h, NONE, 1.1 Makefile.am, 1.9, 1.1
Brought to you by:
xfred
[Compbench-devel] CompBenchmarks++/System XML.cpp, NONE, 1.1 XML.h,
NONE, 1.1 Makefile.am, 1.9, 1.10
From: Frederic T. <xf...@us...> - 2007-01-17 19:08:54
|
Update of /cvsroot/compbench/CompBenchmarks++/System In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv14672 Modified Files: Makefile.am Added Files: XML.cpp XML.h Log Message: XML handling classes. --- NEW FILE: XML.h --- /* ---------------------------------------------------------------------------- $Id: XML.h,v 1.1 2007/01/17 19:08:35 xfred Exp $ This is free software. For details, see the GNU Public License in the COPYING file, or Look http://www.fsf.org ------------------------------------------------------------------------- */ #ifndef H_CBMXML #define H_CBMXML #include <string> #include <vector> /** \brief XML Attribute * Internal representation for an XML attribute. */ class CBMXMLAttribute { protected: std::string name; /*!< Attribute name */ std::string value; /*!< Attribute value */ public: CBMXMLAttribute(std::string _name, std::string _value = ""); virtual std::string Name(void); virtual std::string Value(void); virtual void setValue(std::string _value); virtual ~CBMXMLAttribute(); }; /** \brief XML Node * Internal representation of an XML node. */ class CBMXMLNode { protected: std::vector<CBMXMLNode*> childs; /*!< Child nodes */ std::vector<CBMXMLAttribute*> attributes; /*!< Node's attributes */ std::string name; /*!< Node's name */ std::string value; /*!< Node value */ virtual void indent(std::string& str, int _indent); public: CBMXMLNode(std::string _name, std::string _value = ""); virtual std::string Name(void); virtual std::string Value(void); virtual void setValue(std::string _value); virtual int childNumber(void); virtual CBMXMLNode *getChild(int _index); virtual int attributeNumber(void); virtual CBMXMLAttribute *getAttribute(int _index); virtual CBMXMLNode *add(CBMXMLNode *_child); virtual CBMXMLNode *addNode(std::string _name, std::string _value = ""); virtual CBMXMLAttribute *add(CBMXMLAttribute *_attribute); virtual CBMXMLAttribute *addAttribute(std::string _name, std::string _value = ""); virtual std::string str(int _indent = 0); virtual ~CBMXMLNode(); }; #endif --- NEW FILE: XML.cpp --- /* ---------------------------------------------------------------------------- $Id: XML.cpp,v 1.1 2007/01/17 19:08:35 xfred Exp $ This is free software. For details, see the GNU Public License in the COPYING file, or Look http://www.fsf.org ------------------------------------------------------------------------- */ #include <System/XML.h> CBMXMLAttribute::CBMXMLAttribute(std::string _name, std::string _value) { name=_name; value=_value; } std::string CBMXMLAttribute::Name(void) { return(name); } std::string CBMXMLAttribute::Value(void) { return(value); } void CBMXMLAttribute::setValue(std::string _value) { value=_value; } CBMXMLAttribute::~CBMXMLAttribute() { } CBMXMLNode::CBMXMLNode(std::string _name, std::string _value) { name=_name; value=_value; } void CBMXMLNode::indent(std::string& str, int _indent) { while (_indent--) str+=" "; } std::string CBMXMLNode::Name(void) { return(name); } std::string CBMXMLNode::Value(void) { return(value); } void CBMXMLNode::setValue(std::string _value) { value=_value; } int CBMXMLNode::childNumber(void) { return(childs.size()); } CBMXMLNode *CBMXMLNode::getChild(int _index) { return(childs[_index]); } int CBMXMLNode::attributeNumber(void) { return(attributes.size()); } CBMXMLAttribute *CBMXMLNode::getAttribute(int _index) { return(attributes[_index]); } CBMXMLNode *CBMXMLNode::add(CBMXMLNode *_child) { childs.push_back(_child); return(_child); } CBMXMLNode *CBMXMLNode::addNode(std::string _name, std::string _value) { CBMXMLNode *result = new CBMXMLNode(_name, _value); return(add(result)); } CBMXMLAttribute *CBMXMLNode::add(CBMXMLAttribute *_attribute) { attributes.push_back(_attribute); return(_attribute); } CBMXMLAttribute *CBMXMLNode::addAttribute(std::string _name, std::string _value) { CBMXMLAttribute *result = new CBMXMLAttribute(_name, _value); return(add(result)); } std::string CBMXMLNode::str(int _indent) { std::string result; CBMXMLAttribute *att; int i; int n_child; int n_attr; indent(result, _indent); n_attr=attributes.size(); n_child=childs.size(); result+="<" + name; if (n_attr) { result+=" "; for(i=0; i<n_attr; i++) { att=getAttribute(i); result+=att->Name() + "=\"" + att->Value() + "\""; if (i!=n_attr-1) { result+=" "; } } } if ((!n_child) && (value=="")) { result+="/>\n"; return(result); } result+=">\n"; if (n_child) { for(i=0; i<n_child; i++) { result+=childs[i]->str(_indent+1); } if (value!="") { indent(result, _indent+1); result+=value; result+="\n"; } indent(result, _indent); result+="</" + name + ">\n"; } else { if (value!="") { indent(result, _indent+1); result+=value; result+="\n"; } indent(result, _indent); result+="</" + name + ">\n"; } return(result); } CBMXMLNode::~CBMXMLNode() { } Index: Makefile.am =================================================================== RCS file: /cvsroot/compbench/CompBenchmarks++/System/Makefile.am,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Makefile.am 7 Dec 2006 22:03:43 -0000 1.9 --- Makefile.am 17 Jan 2007 19:08:35 -0000 1.10 *************** *** 14,18 **** sources = System.cpp System-Unix.cpp \ ! md5.cpp libSystem_la_SOURCES = $(sources) $(source_sys) --- 14,18 ---- sources = System.cpp System-Unix.cpp \ ! md5.cpp XML.cpp libSystem_la_SOURCES = $(sources) $(source_sys) |