Plus  - Minimal XML for C++ (Version 0.9.2) Giancarlo Niccolai
Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

mxml_element.h

Go to the documentation of this file.
00001 /*
00002    Mini XML lib PLUS for C++
00003 
00004    Element class
00005 
00006    Author: Giancarlo Niccolai <gian@niccolai.ws>
00007 
00008    $Id: mxml_element.h,v 1.1.1.1 2003/08/13 00:13:29 jonnymind Exp $
00009 */
00010 
00011 #ifndef MXML_ELEMENT_H
00012 #define MXML_ELEMENT_H
00013 
00014 #include <ostream>
00015 #include <string>
00016 
00017 namespace MXML {
00018 
00026 class Element
00027 {
00028 private:
00030    int m_line;
00032    int m_char;
00034    int m_beginLine;
00036    int m_beginChar;
00037 
00038 protected:
00039    /* Fills current and initial line and character for the current element.
00040    This constructor can be called by the parent object that is going to
00041    deserialize a certain element (i.e. a document going to read a node),
00042    filling it with its own current processing line and character; after the
00043    deserialization is done, the line and character of the calling process
00044    should be updated with the line() and characer() method, like this:
00045    \code
00046       try {
00047       ...
00048          MXML::Node *child = new MXML::Node( in_stream, 0, line(), character() );
00049          setPosition( child->line(), child->character() );
00050       }
00051    \endcode
00052 
00053    @param line current line in file that is being processed
00054    @param char current character in current line being processed
00055    */
00056    Element( const int line=1, const int pos=0 )
00057    {
00058       setPosition( line, pos );
00059       markBegin();
00060    }
00061 
00062 public:
00064    void nextLine() { m_line++; m_char = 0; }
00066    void nextChar() { m_char++; }
00068    void setPosition( const int line, const int character ) {
00069       m_line = line;
00070       m_char = character;
00071    }
00073    const int line() const { return m_line; }
00075    const int character() const { return m_char; }
00076 
00078    const int beginLine() const { return m_beginLine; }
00080    const int beginChar() const { return m_beginChar; }
00081 
00089    void markBegin() { m_beginLine = m_line; m_beginChar = m_char; }
00090 
00102    virtual void write( std::ostream &stream, const int style ) const = 0;
00103 
00107    friend std::ostream& operator<<( std::ostream& stream, const Element& elem );
00108 };
00109 
00110 inline std::ostream& operator<<( std::ostream& stream, const Element& elem )
00111 {
00112    elem.write( stream, 0 );
00113    return stream;
00114 }
00115 
00116 } // namespace
00117 
00118 
00119 #endif

Generated on Sun Apr 11 02:08:19 2004 for Mxml Plus by doxygen 1.3.5