Go to the documentation of this file.00001 #ifndef         __XML_H__
00002 #define         __XML_H__
00003 
00004 #include        <list>
00005 #include        <string>
00006 #include        <vector>
00007 
00008 #include        <utilities/binary_data.h>
00009 
00010 #if !defined( WIN32_PLATFORM ) && !defined( NIX_PLATFORM ) && !defined( MINGW_PLATFORM ) && !defined( CYGWIN_PLATFORM )
00011         #define WIN32_PLATFORM
00012 #endif
00013 
00014 #ifdef WIN32_PLATFORM
00015         
00016         
00017         #pragma         warning( disable : 4251 )
00018 #endif
00019 
00020 #ifdef XML
00021         #if defined( WIN32_PLATFORM ) || defined( MINGW_PLATFORM ) || defined( CYGWIN_PLATFORM )
00022                 #define XML_DLL_ENTITY __declspec( dllexport )
00023         #endif
00024 
00025         #if defined( NIX_PLATFORM )
00026                 #define XML_DLL_ENTITY
00027         #endif
00028 #else
00029         #ifdef WIN32_PLATFORM
00030                 #define XML_DLL_ENTITY __declspec( dllimport )
00031                 #pragma comment( lib , "xml.lib" )
00032         #endif
00033         
00034         #if defined( CYGWIN_PLATFORM ) || defined( MINGW_PLATFORM )
00035                 #define XML_DLL_ENTITY __declspec( dllimport )
00036         #endif
00037 
00038         #if defined( NIX_PLATFORM )
00039                 #define XML_DLL_ENTITY
00040         #endif
00041 #endif
00042 
00043 namespace nitro
00044 {
00045         class           FileAbstraction;
00046 
00059         class XML_DLL_ENTITY XMLTag{
00060 
00061         public:
00062 
00077                 XMLTag( void );
00078 
00098                 XMLTag( const XMLTag & XMLTag );
00099 
00110                 std::string                                     Name;
00111 
00134                 void                                            AddAttribute( const char * AttributeName , const char * AttributeValue );
00135 
00154                 void                                            AddTag( const char * TagName );
00155 
00174                 void                                            AddTag( const XMLTag & XMLTag );
00175 
00198                 bool                                            AttributeExists( const char * AttributeName ) const;
00199 
00218                 bool                                            TagExists( char * TagName ) const;
00219 
00238                 void                                            DeleteTag( std::size_t TagCursor );
00239 
00258                 void                                            DeleteTag( const char * TagName );
00259 
00282                 float                                           GetAttribute_float( const char * AttributeName ) const;
00283 
00306                 bool                                            GetAttribute_bool( const char * AttributeName ) const;
00307 
00330                 int                                                     GetAttribute_int( const char * AttributeName ) const;
00331 
00354                 const char *                            GetAttribute_string( const char * AttributeName ) const;
00355 
00378                 int                                                     GetTagCursor( const char * TagName ) const;
00379 
00398                 std::size_t                                     CountOfChildTags( void ) const;
00399                 
00418                 std::size_t                                     CountOfAttributes( void ) const;
00419                 
00442                 const char *                            GetAttributeName( std::size_t AttributeCursor ) const;
00443 
00466                 XMLTag &                                        operator[]( const char * TagName ) const;
00467 
00490                 XMLTag &                                        operator[]( const int TagCursor ) const;
00491 
00514                 XMLTag &                                        operator[]( const std::size_t TagCursor ) const;
00515 
00538                 XMLTag &                                        GetTag( std::size_t TagCursor );
00539 
00566                 XMLTag &                                        GetTag( const char * AttributeName , const char * AttributeValue );
00567 
00586                 XMLTag &                                        LastTag( void );
00587 
00610                 void                                            MoveTag( std::size_t TagCursor , XMLTag & DestTag );
00611 
00634                 void                                            SaveXML( nitro::FileAbstraction & File , char * TabSpace ) const;
00635 
00654                 void                                            SetName( const std::string & Name );
00655 
00678                 void                                            SetAttribute( const char * AttributeName , const char * AttributeValue );
00679 
00694                 void                                            Release( void );
00695 
00706                 virtual                                         ~XMLTag();
00707                 
00708         protected:
00709 
00720                 std::vector< XMLTag * >         Tags;
00721 
00732                 std::vector< std::string >      Attributes;
00733 
00744                 std::vector< std::string >      Values;
00745 
00756                 nitro::BinaryData                       InnerData;
00757 
00780                 int                                                     ProcessAttributes( std::vector< std::string > & Lexemmas , std::size_t & i );
00781 
00804                 bool                                            IsClosingTag( std::vector< std::string > & Lexemmas , std::size_t & i );
00805 
00828                 void                                            SaveXMLToANSIString( std::string & Str , char * TabSpace );
00829 
00860                 void                                            LoadXML( std::vector< std::string > & Lexemmas , std::size_t & i , std::list< nitro::BinaryData > & CDATA , std::list< nitro::BinaryData >::iterator & j );
00861 
00862         private:
00863 
00874                 XMLTag                                          operator=( const XMLTag & ){return(*this);}
00875         };
00876 
00887         class XML_DLL_ENTITY XMLFile:public XMLTag{
00888         public:
00889         
00904                 XMLFile( void );
00905 
00924                 XMLFile( const char * FilePath );
00925 
00944                 XMLFile( const std::string & FilePath );
00945 
00964                 XMLTag &                                        GetRoot( void );
00965 
00984                 void                                            LoadXML( const char * FilePath );
00985 
01004                 void                                            LoadXML( const std::string & FilePath );
01005 
01024                 void                                            LoadXMLFromANSIString( const char * str );
01025 
01044                 void                                            SaveXML( const char * FilePath = NULL );
01045 
01056                 virtual                                         ~XMLFile();
01057                 
01058         private:
01059         
01070                 std::string                                     Version;
01071 
01082                 std::string                                     Encoding;
01083                 
01094                 std::string                                     SerializedXML;
01095 
01106                 std::string                                     OpenFilePath;
01107 
01126                 void                                            ParseHeader( std::vector< std::string > & Lexemmas , std::size_t & i );
01127         };
01128 }
01129 
01130 #endif