Update of /cvsroot/eas-dev/eas-dev/libs/libsxmlstream/include
In directory sc8-pr-cvs1:/tmp/cvs-serv31785/include
Modified Files:
sxml.hxx sxmlstream.hxx
Log Message:
New interface for SXmlSteam class. SXmlStream now can act as SAX-alike SXml
parser emitting signals on start/end of elements and character data.
Index: sxml.hxx
===================================================================
RCS file: /cvsroot/eas-dev/eas-dev/libs/libsxmlstream/include/sxml.hxx,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- sxml.hxx 3 Feb 2003 18:59:37 -0000 1.6
+++ sxml.hxx 11 Feb 2003 08:12:03 -0000 1.7
@@ -36,6 +36,19 @@
SXmlNode_Namespace_t
};
+/* SXml attribute name with namespace */
+struct SXmlNameNS {
+ string NS;
+ string name;
+
+ // Comarison operator for containers
+ bool operator<(const SXmlNameNS& n) const
+ { return NS < n.NS && name < n.name;}
+}
+
+/* SXml Element Attributes */
+typedef map<SXmlNameNS, string> SXmlAttrs;
+
struct SXmlNode {
SXmlNode_t type;
string data;
@@ -55,6 +68,10 @@
type == descendants.front().type; }
void addChild(const SXmlNode& e) { descendants.push_back(e); }
+
+ // Syntactic sugar for addChild
+ SXmlNode& operator<<(const XmlNode& e) { addChild(e); }
+
string getProperty() const { return hasProperty() ?
descendants.front().data : 0; }
Index: sxmlstream.hxx
===================================================================
RCS file: /cvsroot/eas-dev/eas-dev/libs/libsxmlstream/include/sxmlstream.hxx,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- sxmlstream.hxx 8 Feb 2003 08:23:48 -0000 1.10
+++ sxmlstream.hxx 11 Feb 2003 08:12:03 -0000 1.11
@@ -22,6 +22,7 @@
#define _LIBSXMLSTREAM_SXMLSTREAM_HXX_
#include <queue>
+#include <ostream>
#include <sigslot.h>
#include <sxml.hxx>
@@ -31,43 +32,56 @@
namespace openeas { namespace sxmlstream {
-class SXmlStream
-{
- protected:
-
- queue<SXmlNode> m_queue;
+class SXmlStream {
+ public:
+ SXmlStream() { m_tmpnode = NULL; }
+ ~SXmlStream() { if (m_tmpnode != NULL) delete m_tmpnode; }
+
+ SXmlStream& operator<<(const string& s);
+
+ // Will throw an exception if called when the text Root element
+ // is in process of parsing.
+ SXmlStream& operator<<(const SXmlNode& n);
- public:
- signal1<SXmlNode> Received;
-
- bool queueIsEmpty();
+ // This will not emit any signals, just return one root node
+ // from buffer.
+ SXmlStream& operator>>(SXmlNode& n);
- SXmlNode pop();
- void push(const SXmlNode& e) {m_queue.push(e);}
+ friend istream& operator>>(istream&, SXmlStream&);
+
+ // True if ready to receive new root SXml element
+ bool isClean() const;
+
+ signal2<SXmlNameNS, SXmlAttrs> startElement;
+ signal1<SXmlNameNS> endElement;
+ signal1<string> characters;
-};
+ signal0<> startRootElement;
+ signal0<> endRootElement;
-class SXmlBinaryStream: public SXmlStream
-{
- public:
+ void clearBuffer() { m_queue.clear(); }
+ bool bufferEmpty() const { return m_queue.empty(); }
+
+ protected:
+ queue<SXmlNode> m_queue;
- friend ostream& operator<<(ostream&,
- SXmlBinaryStream&);
- friend SXmlBinaryStream& operator<<(SXmlBinaryStream&,
- const ostream&);
+ private:
+ void processNode const (const SXmlNode& n);
+
+ // Private members for input text processing
+ string m_textbuf;
+ SXmlNode *m_tmpnode;
};
-class SXmlTextStream: public SXmlStream
-{
- public:
-
- friend ostream& operator<<(ostream&,
- SXmlTextStream&);
-
- friend SXmlTextStream& operator<<(SXmlTextStream&,
- const ostream&);
+class SXmlBinaryStream: public SXmlStream {
+ public:
+ friend ostream& operator<<(ostream&, SXmlBinaryStream&);
+};
+class SXmlTextStream: public SXmlStream {
+ public:
+ friend ostream& operator<<(ostream&, SXmlTextStream&);
};
}; };
|