Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

xml.h

Go to the documentation of this file.
00001 
00002 //
00003 // Copyright (C) 2001
00004 // Ralf Westram
00005 // Time-stamp: <Wed Nov/13/2002 08:30 MET Coder@ReallySoft.de>
00006 //
00007 // Permission to use, copy, modify, distribute and sell this software
00008 // and its documentation for any purpose is hereby granted without fee,
00009 // provided that the above copyright notice appear in all copies and
00010 // that both that copyright notice and this permission notice appear
00011 // in supporting documentation.  Ralf Westram makes no
00012 // representations about the suitability of this software for any
00013 // purpose.  It is provided "as is" without express or implied warranty.
00014 //
00015 // This code is part of my library.
00016 // You may find a more recent version at http://www.reallysoft.de/
00017 //
00019 
00020 #ifndef XML_H
00021 #define XML_H
00022 
00023 #ifndef __STRING__
00024 #include <string>
00025 #endif
00026 #ifndef __IOSTREAM__
00027 #include <iostream>
00028 #endif
00029 #ifndef BOOST_UTIL_H
00030 #include <boost_util.h>
00031 #endif
00032 
00033 
00034 namespace rs {
00035 
00044     namespace xml {
00045 
00046 //         class                XML_Document;
00047 //         extern XML_Document *theDocument; // there can only be one
00048 
00049         //  ----------------------------
00050         //      class XML_Attribute
00051         //  ----------------------------
00052 
00055         class XML_Attribute {
00056         private:
00057             std::string    name;
00058             std::string    content;
00059             XML_Attribute *next;
00060 
00061         public:
00062             XML_Attribute(const std::string& name_, const std::string& content_);
00063             virtual ~XML_Attribute();
00064 
00065             XML_Attribute *append_to(XML_Attribute *queue);
00066 
00067             void print(std::ostream& out) const;
00068         };
00069 
00070 
00071         //  -----------------------
00072         //      class XML_Node
00073         //  -----------------------
00074 
00076         class XML_Node {
00077         protected:
00078             XML_Node *father;
00079             bool      opened;
00080             int       indent;
00081 
00082         public:
00083             XML_Node();
00084             virtual ~XML_Node();
00085 
00086             int Indent() const { return indent; }
00087             bool Opened() const { return opened; }
00088 //             void set_Opened(bool opened_) { opened = opened_; }
00089 
00090             virtual void add_son(XML_Node *son_)    = 0;
00091             virtual void remove_son(XML_Node *son_) = 0;
00092             virtual void open(std::ostream& out)         = 0;
00093             virtual void close(std::ostream& out)        = 0;
00094         };
00095 
00096         //  ----------------------------------------
00097         //      class XML_Tag : public XML_Node
00098         //  ----------------------------------------
00099 
00101         class XML_Tag : public XML_Node {
00102         private:
00103             std::string    name;
00104             XML_Node      *son;
00105             XML_Attribute *attribute;
00106 
00107         public:
00111             XML_Tag(const std::string &name_);
00112             virtual ~XML_Tag();
00113 
00118             void add_attribute(const std::string& name_, const std::string& content_);
00119             virtual void add_son(XML_Node *son_);
00120             virtual void remove_son(XML_Node *son_);
00121             virtual void open(std::ostream& out);
00122             virtual void close(std::ostream& out);
00123         };
00124 
00125         //  -----------------------------------------
00126         //      class XML_Text : public XML_Node
00127         //  -----------------------------------------
00129         class XML_Text : public XML_Node {
00130         private:
00131             std::string content;
00132 
00133         public:
00137             XML_Text(const std::string& content_) : content(content_) {}
00138             virtual ~XML_Text();
00139 
00140             virtual void add_son(XML_Node *son_);
00141             virtual void remove_son(XML_Node *son_);
00142             virtual void open(std::ostream& out);
00143             virtual void close(std::ostream& out);
00144         };
00145 
00146 
00147         //  ---------------------------
00148         //      class XML_Document
00149         //  ---------------------------
00151         class XML_Document : rs_boost::singleton<XML_Document> {
00152         private:
00153             std::string    dtd;
00154             XML_Tag       *root;
00155             XML_Node      *latest_son;
00156             std::ostream&  out;
00157 
00158         public:
00164             XML_Document(const std::string& name_, const std::string& dtd_, std::ostream& out_);
00165             virtual ~XML_Document();
00166 
00167             XML_Node* LatestSon() { return latest_son; }
00168             void set_LatestSon(XML_Node* latest_son_) { latest_son = latest_son_; }
00169 
00170             std::ostream& Out() { return out; }
00171         };
00172     };                          // end of namespace xml
00173 };                              // end of namespace rs
00174 
00175 #else
00176 #error xml.h included twice
00177 #endif // XML_H

Contact me in case of errors or questions.
This documentation is powered by Doxygen.
(C) 2000-2002 Doxygen