Public Member Functions | Private Member Functions | Private Attributes

nitro::XMLFile Class Reference

Class hides some XMLTag methods. More...

#include <loaders/xml.h>

Inherits nitro::XMLTag.

Collaboration diagram for nitro::XMLFile:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 XMLFile (void)
 XMLFile (const char *FilePath)
 XMLFile (const std::string &FilePath)
XMLTagGetRoot (void)
void LoadXML (const char *FilePath)
void LoadXML (const std::string &FilePath)
void LoadXMLFromANSIString (const char *str)
void SaveXML (const char *FilePath=NULL)
virtual ~XMLFile ()

Private Member Functions

void ParseHeader (std::vector< std::string > &Lexemmas, std::size_t &i)

Private Attributes

std::string Version
std::string Encoding
std::string SerializedXML
std::string OpenFilePath

Detailed Description

Class hides some XMLTag methods.

Definition at line 887 of file xml.h.


Constructor & Destructor Documentation

nitro::XMLFile::XMLFile ( void   ) 

Default constructor.

Exceptions:
nitro::exception An exception of that type is thrown if ahy error occured.
Author:
Dodonov A.A.

Definition at line 117 of file xml.cpp.

References nitro::exception::code(), Encoding, OpenFilePath, Version, and nitro::exception::what().

        {
                try
                {
                        Version = "";
                        Encoding = "";
                        OpenFilePath = "";
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "XMLFile::XMLFile( void )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "XMLFile::XMLFile( void )::An error occured" ) , 1 ) );
                }
        }

Here is the call graph for this function:

nitro::XMLFile::XMLFile ( const char *  FilePath  ) 

Constructor that loads XML from file.

Parameters:
FilePath - Path to loading XML file.
Exceptions:
nitro::exception An exception of that type is thrown if ahy error occured.
Author:
Dodonov A.A.

Definition at line 135 of file xml.cpp.

References nitro::exception::code(), Encoding, LoadXML(), OpenFilePath, Version, and nitro::exception::what().

        {
                try
                {
                        Version = "";
                        Encoding = "";

                        OpenFilePath = FilePath;

                        LoadXML( FilePath );
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "XMLFile::XMLFile( const char * FilePath )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "XMLFile::XMLFile( const char * FilePath )::An error occured" ) , 1 ) );
                }
        }

Here is the call graph for this function:

nitro::XMLFile::XMLFile ( const std::string &  FilePath  ) 

Constructor that loads XML from file.

Parameters:
FilePath - Path to loading XML file
Exceptions:
nitro::exception An exception of that type is thrown if ahy error occured.
Author:
Dodonov A.A.

Definition at line 156 of file xml.cpp.

References nitro::exception::code(), Encoding, LoadXML(), OpenFilePath, Version, and nitro::exception::what().

        {
                try
                {
                        Version = "";
                        Encoding = "";

                        OpenFilePath = FilePath;

                        LoadXML( FilePath );
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "XMLFile::XMLFile( const std::string & FilePath )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "XMLFile::XMLFile( const std::string & FilePath )::An error occured" ) , 1 ) );
                }
        }

Here is the call graph for this function:

nitro::XMLFile::~XMLFile (  )  [virtual]

Destructor (virtual).

Author:
Dodonov A.A.

Definition at line 824 of file xml.cpp.

References nitro::XMLTag::Release().

        {
                try
                {
                        this->Release();
                }
                catch( ... )
                {
                }
        }

Here is the call graph for this function:


Member Function Documentation

XMLTag & nitro::XMLFile::GetRoot ( void   ) 

Function return the root element of the file.

Returns:
Root element fo the file.
Exceptions:
nitro::exception An exception of that type is thrown if ahy error occured.
Author:
Dodonov A.A.

Definition at line 604 of file xml.cpp.

References nitro::exception::code(), and nitro::exception::what().

Referenced by nitro::MVC::Create().

        {
                try
                {
                        return( dynamic_cast< XMLTag & >( *this ) );
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "XMLFile::GetRoot( void )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "XMLFile::GetRoot( void )::An error occured" ) , 1 ) );
                }
        }

Here is the call graph for this function:

void nitro::XMLFile::LoadXML ( const char *  FilePath  ) 

Function loads XML file.

Parameters:
FilePath - Path to loading XML file
Exceptions:
nitro::exception An exception of that type is thrown if ahy error occured.
Author:
Dodonov A.A.

Definition at line 620 of file xml.cpp.

References nitro::exception::code(), nitro::DispatchBuffer(), nitro::BinaryData::GetBuffer(), nitro::BinaryData::GetBufferLength(), nitro::File::LoadBinDataFromFile(), OpenFilePath, ParseHeader(), and nitro::exception::what().

Referenced by nitro::MVC::Create(), LoadXML(), LoadXMLFromANSIString(), and XMLFile().

        {
                try
                {
                        OpenFilePath = FilePath;

                        std::vector< std::string >                                      ProtoText;
                        std::vector< std::string >                                      Lexemmas;
                        std::list< nitro::BinaryData >                          CDATA;

                        BinaryData                                                                      BinaryData;

                        File::LoadBinDataFromFile( BinaryData , std::string( FilePath ) );

                        DispatchBuffer( BinaryData.GetBuffer() , Lexemmas , BinaryData.GetBufferLength() , CDATA );

                        std::size_t                                                                     i( 0 );
                        std::list< nitro::BinaryData >::iterator        j( CDATA.begin() );

                        ParseHeader( Lexemmas , i );

                        XMLTag::LoadXML( Lexemmas , i , CDATA , j );

                        ProtoText.clear();
                        Lexemmas.clear();
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "XMLFile::LoadXML( const char * FilePath )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "XMLFile::LoadXML( const char * FilePath )::An error occured" ) , 1 ) );
                }
        }

Here is the call graph for this function:

void nitro::XMLFile::LoadXML ( const std::string &  FilePath  ) 

Function loads XML file.

Parameters:
FilePath - Path to loading XML file
Exceptions:
nitro::exception An exception of that type is thrown if ahy error occured.
Author:
Dodonov A.A.

Definition at line 656 of file xml.cpp.

References nitro::exception::code(), LoadXML(), and nitro::exception::what().

        {
                try
                {
                        LoadXML( FilePath.c_str() );
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "XMLFile::LoadXML( const std::string & FilePath )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "XMLFile::LoadXML( const std::string & FilePath )::An error occured" ) , 1 ) );
                }
        }

Here is the call graph for this function:

void nitro::XMLFile::LoadXMLFromANSIString ( const char *  str  ) 

Function loads XML from const string.

Parameters:
str - String with XML.
Exceptions:
nitro::exception An exception of that type is thrown if ahy error occured.
Author:
Dodonov A.A.

Definition at line 576 of file xml.cpp.

References nitro::DispatchBuffer(), LoadXML(), OpenFilePath, ParseHeader(), and nitro::exception::what().

        {
                try
                {
                        OpenFilePath = "";

                        std::vector< std::string >                                      Lexemmas;
                        std::list< nitro::BinaryData >                          CDATA;

                        DispatchBuffer( str , Lexemmas , strlen( str ) , CDATA );

                        std::size_t                                                                     i( 0 );
                        std::list< nitro::BinaryData >::iterator        j( CDATA.begin() );

                        ParseHeader( Lexemmas , i );

                        XMLTag::LoadXML( Lexemmas , i , CDATA , j );
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "XMLFile::LoadXMLFromANSIString( const char * str )::" ) + e.what() , 1 ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "XMLFile::LoadXMLFromANSIString( const char * str )::An error occured" ) , 1 ) );
                }
        }

Here is the call graph for this function:

void nitro::XMLFile::ParseHeader ( std::vector< std::string > &  Lexemmas,
std::size_t &  i 
) [private]

This function parse xml header <?xml version=....?>

Parameters:
Lexemmas - XML file splitted into tag names, tag parameters and special simbols.
i - Cursor for array Lexemmas.
Author:
Dodonov A.A.

Definition at line 1016 of file xml.cpp.

References nitro::exception::code(), Encoding, nitro::IsTagName(), Version, and nitro::exception::what().

Referenced by LoadXML(), and LoadXMLFromANSIString().

        {
                try
                {
                        if( Lexemmas.size() < 6 )
                        {
                                throw( nitro::exception( "Bad XML structure" , 1 ) );
                        }
                        if( Lexemmas[ 0 ] != "<" || Lexemmas[ 1 ] != "?" || Lexemmas[ 2 ] != "xml" )
                        {
                                return;
                        }

                        i = 3;

                        for( std::size_t k( 3 ) ; k < Lexemmas.size() ; k += 5 , i += 5 )
                        {
                                if( IsTagName( Lexemmas[ k ] ) && Lexemmas[ k + 1 ] == "=" && Lexemmas[ k + 2 ] == "\"" )
                                {
                                        if( Lexemmas[ k ] == "version" )
                                        {
                                                Version = Lexemmas[ k + 3 ];
                                                goto next_iter;
                                        }
                                        if( Lexemmas[ k ] == "encoding" )
                                        {
                                                Encoding = Lexemmas[ k + 3 ];
                                                goto next_iter;
                                        }
                                }
                                else
                                {
                                        if( Lexemmas[ k ] == "?" && Lexemmas[ k + 1 ] == ">" )
                                        {
                                                i += 2;
                                                return;
                                        }
                                        else
                                        {
                                                throw( nitro::exception( "Bad XML structure" , 1 ) );
                                        }
                                }
                next_iter:;
                        }
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "XMLFile::ParseHeader( std::vector< std::string > & Lexemmas , std::size_t & i )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "XMLFile::ParseHeader( std::vector< std::string > & Lexemmas , std::size_t & i )::An error occured" ) , 1 ) );
                }
        }

Here is the call graph for this function:

void nitro::XMLFile::SaveXML ( const char *  FilePath = NULL  ) 

Function saves XML faile into file.

Parameters:
FilePath - Path to the destination file.
Exceptions:
nitro::exception An exception of that type is thrown if ahy error occured.
Author:
Dodonov A.A.

Definition at line 770 of file xml.cpp.

References nitro::exception::code(), Encoding, nitro::FA_FILE_BINARY, nitro::FA_FILE_TRUNCATE, nitro::FA_FILE_WRITE, nitro::FileAbstraction::Open(), OpenFilePath, Version, nitro::exception::what(), and nitro::FileAbstraction::Write().

        {
                try
                {
                        nitro::FileAbstraction          File;

                        if( FilePath )
                        {
                                OpenFilePath = FilePath;
                                File.Open( FilePath , nitro::FA_FILE_WRITE | nitro::FA_FILE_BINARY | nitro::FA_FILE_TRUNCATE );
                        }
                        else
                        {
                                File.Open( OpenFilePath.c_str() , nitro::FA_FILE_WRITE | nitro::FA_FILE_BINARY | nitro::FA_FILE_TRUNCATE );
                        }

                        if( Version != "" || Encoding != "" )
                        {
                                std::string             str;

                                str = "<?xml ";
                                File.Write( str.c_str() , str.length() );

                                if( Version != "" )
                                {
                                        str = "version=\"";
                                        str += Version;
                                        str += "\" ";
                                        File.Write( str.c_str() , str.length() );
                                }
                                if( Encoding != "" )
                                {
                                        str = "encoding=\"";
                                        str += Encoding;
                                        str += "\" ";
                                        File.Write( str.c_str() , str.length() );
                                }

                                str = "?>\n";
                                File.Write( str.c_str() , str.length() );
                        }

                        XMLTag::SaveXML( File , "" );
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "XMLFile::SaveXML( const char * FilePath /* = NULL */ )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "XMLFile::SaveXML( const char * FilePath /* = NULL */ )::An error occured" ) , 1 ) );
                }
        }

Here is the call graph for this function:


Member Data Documentation

std::string nitro::XMLFile::Encoding [private]

File encoding.

Author:
Dodonov A.A.

Definition at line 1082 of file xml.h.

Referenced by ParseHeader(), SaveXML(), and XMLFile().

std::string nitro::XMLFile::OpenFilePath [private]

Path to the opened file.

Author:
Dodonov A.A.

Definition at line 1106 of file xml.h.

Referenced by LoadXML(), LoadXMLFromANSIString(), SaveXML(), and XMLFile().

std::string nitro::XMLFile::SerializedXML [private]

Temporary buffer.

Author:
Dodonov A.A.

Definition at line 1094 of file xml.h.

std::string nitro::XMLFile::Version [private]

Version of the XML format.

Author:
Dodonov A.A.

Definition at line 1070 of file xml.h.

Referenced by ParseHeader(), SaveXML(), and XMLFile().


The documentation for this class was generated from the following files:

Generated by  doxygen 1.6.1