• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

spl/xml/XmlAttribute.h

00001 /*
00002  *  Much of this code is extracted from the tinyxml project, attributed below.
00003  */
00004 /*
00005 www.sourceforge.net/projects/tinyxml
00006 Original code (2.0 and earlier )copyright (c) 2000-2006 Lee Thomason (www.grinninglizard.com)
00007 
00008 This software is provided 'as-is', without any express or implied
00009 warranty. In no event will the authors be held liable for any
00010 damages arising from the use of this software.
00011 
00012 Permission is granted to anyone to use this software for any
00013 purpose, including commercial applications, and to alter it and
00014 redistribute it freely, subject to the following restrictions:
00015 
00016 1. The origin of this software must not be misrepresented; you must
00017 not claim that you wrote the original software. If you use this
00018 software in a product, an acknowledgment in the product documentation
00019 would be appreciated but is not required.
00020 
00021 2. Altered source versions must be plainly marked as such, and
00022 must not be misrepresented as being the original software.
00023 
00024 3. This notice may not be removed or altered from any source
00025 distribution.
00026 */
00027 #ifndef _xmlattribute_h
00028 #define _xmlattribute_h
00029 
00030 #include <spl/Double.h>
00031 #include <spl/Int32.h>
00032 #include <spl/String.h>
00033 #include <spl/xml/XmlDocument.h>
00034 #include <spl/xml/XmlNode.h>
00035 
00043 class XmlAttribute : public XmlNode
00044 {
00045 protected:
00046 friend class XmlElement;
00047 friend class XmlDeclaration;
00048 
00049         XmlDocumentRef  m_document;     // A pointer back to a document, for error reporting.
00050         String m_name;
00051                         
00052         /*      Attribute parsing starts: first letter of the name
00053                                                  returns: the next char after the value end quote
00054         */
00055         virtual const char* _Parse( const char* p, XmlParsingData* data, XmlEncoding encoding );
00056 
00058         XmlAttribute();
00059 
00061         XmlAttribute( const String& _name, const String& _value );
00062 
00063 public:
00064         virtual ~XmlAttribute();
00065                         
00066         virtual XmlNodePtr Clone() const;
00067                         
00069         virtual String Name() const;
00070         
00071         void SetName( const String& _name )     { m_name = _name; }                             
00072         void SetValue( const String& _value )   { m_value = _value; }                           
00073         void SetValue( int _value ) { m_value = Int32::ToString(_value); }                                      
00074         void SetValue( double _value ) { m_value = Double::ToString(_value); }                          
00075 
00076         // [internal use]
00077         // Set the document pointer so the attribute can report errors.
00078         inline void SetDocument( XmlDocumentRef doc )
00079         { 
00080                 m_document = doc; 
00081         }
00082         
00083         virtual StringPtr ToString() const;
00084         virtual void WriteTo(TextWriter& writer) const;
00085                         
00086 #ifdef DEBUG
00087         virtual void ValidateMem() const;
00088         virtual void CheckMem() const;
00089 #endif
00090 };
00091 
00092 REGISTER_TYPEOF( 526, XmlAttribute );
00093 
00096 #endif