From: Egor C. <eg...@us...> - 2003-01-28 22:36:33
|
Update of /cvsroot/eas-dev/eas-dev/libs/libsxmlstream/src In directory sc8-pr-cvs1:/tmp/cvs-serv6701/libs/libsxmlstream/src Modified Files: sxml.cxx sxmlstream.cxx Log Message: Major code refactoring. _SXml struct --> SXmlNode class. Small performance optimization. *Warning* Code compiled but not tested! Index: sxml.cxx =================================================================== RCS file: /cvsroot/eas-dev/eas-dev/libs/libsxmlstream/src/sxml.cxx,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- sxml.cxx 25 Jan 2003 21:51:28 -0000 1.2 +++ sxml.cxx 28 Jan 2003 22:36:26 -0000 1.3 @@ -7,6 +7,7 @@ /* */ /* Author(s): */ /* Yurii A. Rashkovskii <yr...@op...> */ +/* Egor Cheshkov <eg...@ip...> */ /* */ /* */ /* This program is free software; you can redistribute */ @@ -22,66 +23,41 @@ using namespace std; -/* SXml creation */ - -SXml SXml_create(SXml_t aType, string aData) +SXmlNode::SXmlNode(const SXmlNode& v) { - SXml e; - e.type = aType; e.data = aData; - e.childs = new vector<SXml>(0); - return e; + type=v.type; + *descendants = *(v.descendants); + data = v.data; } -SXml SXml_Element_create(string aName) +SXmlNode& SXmlNode::operator=(const SXmlNode& v) { - return SXml_create(SXml_Element_t, aName); -} + type=v.type; + *descendants = *(v.descendants); + data = v.data; -SXml SXml_Attribute_create(string aName, string aValue) -{ - SXml e = SXml_create(SXml_Attribute_t, aName); - SXml c = SXml_create(SXml_Attribute_t, aValue); - SXml_create_child(e, c); - - return e; + return *this; } -SXml SXml_Char_create(string aData) -{ - return SXml_create(SXml_Char_t, aData); -} +/* Factory functions */ -SXml SXml_Namespace_create(string aPrefix, string aURI) +SXmlNode SXmlNode::Attribute(string aName, string aValue) { - SXml e = SXml_create(SXml_Namespace_t, aPrefix); - SXml c = SXml_create(SXml_Namespace_t, aURI); - SXml_create_child(e, c); - - return e; -} + SXmlNode e(SXmlNode_Attribute_t, aName); + SXmlNode c(SXmlNode_Attribute_t, aValue); + e.addChild(c); -/* SXml destruction */ - -void SXml_delete(SXml e) -{ - delete e.childs; + return e; } -/* Childs operations */ - -void SXml_create_child(SXml e, SXml c) +SXmlNode SXmlNode::Namespace(string aPrefix, string aURI) { - (e.childs)->push_back(c); -} + SXmlNode e(SXmlNode_Namespace_t, aPrefix); + SXmlNode c(SXmlNode_Namespace_t, aURI); + e.addChild(c); -string SXml_get_property(SXml e) -{ - if (SXml_has_property(e)) - { - return ((SXml)(e.childs)->at(0)).data; - } else - { - return 0; - } + return e; } + + Index: sxmlstream.cxx =================================================================== RCS file: /cvsroot/eas-dev/eas-dev/libs/libsxmlstream/src/sxmlstream.cxx,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- sxmlstream.cxx 28 Jan 2003 06:44:32 -0000 1.6 +++ sxmlstream.cxx 28 Jan 2003 22:36:27 -0000 1.7 @@ -28,13 +28,13 @@ using namespace std; -typedef vector<SXml>::iterator sxml_iterator; +typedef list<SXmlNode>::iterator SXmlNode_iterator; /* SXmlStream */ SXmlStream::SXmlStream() { - m_queue = new queue<SXml>(); + m_queue = new queue<SXmlNode>(); } SXmlStream::~SXmlStream() @@ -47,24 +47,20 @@ return m_queue->empty(); } -SXml SXmlStream::pop() +SXmlNode& SXmlStream::pop() { - SXml e = m_queue->front(); + SXmlNode *e = &(m_queue->front()); m_queue->pop(); - return e; + return *e; } -void SXmlStream::push(SXml e) -{ - m_queue->push(e); -} /* SXmlBinaryStream */ SXmlBinaryStream::SXmlBinaryStream() { - m_queue = new queue<SXml>(); + m_queue = new queue<SXmlNode>(); } SXmlBinaryStream::~SXmlBinaryStream() @@ -89,20 +85,20 @@ #endif -ostream& SXml_BinaryOutput(ostream& os, SXml e) +ostream& SXml_BinaryOutput(ostream& os, SXmlNode e) { - sxml_iterator iter; + SXmlNode_iterator iter; switch (e.type) { - case SXml_Element_t: + case SXmlNode_Element_t: os << BIN_LBRACKET; os << BIN_SIGN << BIN_PORTABLE_SIZE(e.data.length()) << e.data; // Output attributes - iter = (e.childs)->begin(); - while (iter!=(e.childs)->end()) + iter = (e.descendants)->begin(); + while (iter!=(e.descendants)->end()) { - if (Is_SXml_Attribute((*iter))) + if (iter->isAttribute()) { os << BIN_LBRACKET << BIN_SIGN_ATTR; SXml_BinaryOutput(os,(*iter)); @@ -110,11 +106,11 @@ } iter++; } - // Output childs - iter = (e.childs)->begin(); - while (iter!=(e.childs)->end()) + // Output descendants + iter = (e.descendants)->begin(); + while (iter!=(e.descendants)->end()) { - if (!Is_SXml_Attribute((*iter))) + if (!iter->isAttribute()) { SXml_BinaryOutput(os,(*iter)); } @@ -123,14 +119,14 @@ os << BIN_RBRACKET; break; - case SXml_Attribute_t: - if (SXml_has_property(e)) + case SXmlNode_Attribute_t: + if (e.hasProperty()) { os << BIN_LBRACKET << BIN_PORTABLE_SIZE(e.data.length()) << e.data << - BIN_PORTABLE_SIZE(SXml_get_property(e).length()) << - SXml_get_property(e) << BIN_LBRACKET; + BIN_PORTABLE_SIZE((e.getProperty()).length()) << + e.getProperty() << BIN_LBRACKET; } else { os << BIN_LBRACKET << @@ -139,16 +135,17 @@ } break; - case SXml_Char_t: + case SXmlNode_Char_t: os << BIN_SIGN_CHAR << BIN_PORTABLE_SIZE(e.data.length()) << e.data; break; - case SXml_Namespace_t: + case SXmlNode_Namespace_t: os << BIN_LBRACKET << BIN_SIGN_NS; os << BIN_PORTABLE_SIZE(e.data.length()); - if (SXml_has_property(e)) - os << BIN_PORTABLE_SIZE(SXml_get_property(e).length()) << SXml_get_property(e); + if (e.hasProperty()) + os << BIN_PORTABLE_SIZE(e.getProperty().length()) + << e.getProperty(); os << BIN_RBRACKET; break; default: @@ -159,7 +156,7 @@ ostream& operator<<(ostream& os, SXmlBinaryStream& s) { - SXml e; + SXmlNode e; while (!s.queueIsEmpty()) { e = s.pop(); @@ -178,7 +175,7 @@ SXmlTextStream::SXmlTextStream() { - m_queue = new queue<SXml>(); + m_queue = new queue<SXmlNode>(); } SXmlTextStream::~SXmlTextStream() @@ -187,18 +184,18 @@ } -ostream& SXml_TextOutput(ostream& os, SXml e) +ostream& SXml_TextOutput(ostream& os, SXmlNode e) { - sxml_iterator iter; + SXmlNode_iterator iter; switch (e.type) { - case SXml_Element_t: + case SXmlNode_Element_t: os << "(" << e.data << " "; // Output attributes - iter = (e.childs)->begin(); - while (iter!=(e.childs)->end()) + iter = (e.descendants)->begin(); + while (iter!=(e.descendants)->end()) { - if (Is_SXml_Attribute((*iter))) + if (iter->isAttribute()) { os << "(@ "; SXml_TextOutput(os,(*iter)); @@ -206,11 +203,11 @@ } iter++; } - // Output childs - iter = (e.childs)->begin(); - while (iter!=(e.childs)->end()) + // Output descendants + iter = (e.descendants)->begin(); + while (iter!=(e.descendants)->end()) { - if (!Is_SXml_Attribute((*iter))) + if (!iter->isAttribute()) { SXml_TextOutput(os,(*iter)); } @@ -219,25 +216,25 @@ os << ")"; break; - case SXml_Attribute_t: - if (SXml_has_property(e)) + case SXmlNode_Attribute_t: + if (e.hasProperty()) { os << "(" << e.data << " \"" << - SXml_get_property(e) << "\")"; + e.getProperty() << "\")"; } else { os << "(" << e.data << " )"; } break; - case SXml_Char_t: + case SXmlNode_Char_t: os << " \"" << e.data << "\" "; break; - case SXml_Namespace_t: + case SXmlNode_Namespace_t: os << "(@@ "; os << e.data << " "; - if (SXml_has_property(e)) - os << "\"" << SXml_get_property(e) << "\""; + if (e.hasProperty()) + os << "\"" << e.getProperty() << "\""; os << " )"; break; default: @@ -248,7 +245,7 @@ ostream& operator<<(ostream& os, SXmlTextStream& s) { - SXml e; + SXmlNode e; while (!s.queueIsEmpty()) { e = s.pop(); |