Public Member Functions | Static Public Member Functions | Private Member Functions

nitro::File Class Reference

Class provides file manipulation routine. More...

#include <utilities/file_utilities.h>

Inherits nitro::FileAbstraction.

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

List of all members.

Public Member Functions

 File (void)
 File (const char *FilePath, const std::size_t Mode)
 File (const std::string &FilePath, const std::size_t Mode)
 ALIAS_FUNCTION_2 (Open, tstOpen, const char *, std::size_t)
 ALIAS_FUNCTION_0 (Close, tstClose)
void Write (const char *Data)
void Write (const std::string &Data)
std::size_t FileSize (void)

Static Public Member Functions

static void SaveBinDataToFile (const BinaryData &BinData, const char *Path)
static void SaveBinDataToFile (const BinaryData &BinData, const std::string &Path)
static void LoadBinDataFromFile (nitro::BinaryData &BinData, const char *Path)
static void LoadBinDataFromFile (nitro::BinaryData &BinData, const std::string &Path)
static tm GetLastModified (const char *Path)
static tm GetLastModified (const std::string &Path)
static bool FileExists (const char *FilePath)
static bool FileExists (const std::string &FilePath)
static void ForceCreateFile (const char *FilePath)
static void ForceCreateFile (const std::string &FilePath)

Private Member Functions

 File (const File &File)
File operator= (const File &File)

Detailed Description

Class provides file manipulation routine.

Timer class.

Author:
Dodonov A.A.

Definition at line 58 of file file_utilities.h.


Constructor & Destructor Documentation

nitro::File::File ( void   ) 

Default constructor.

Exceptions:
nitro::exception Throws an exception of that type with the error description.
Author:
Dodonov A.A.

Definition at line 10 of file file_utilities.cpp.

        {
        }

nitro::File::File ( const char *  FilePath,
const std::size_t  Mode 
)

Function opens file FilePath in mode Mode.

Parameters:
FilePath - Path to the opening file.
Mode - File opening mode.
Exceptions:
nitro::exception Throws an exception of that type with the error description.
Author:
Dodonov A.A.

Definition at line 14 of file file_utilities.cpp.

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

        {
                try
                {
                        nitro::FileAbstraction::Open( FilePath , Mode );
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "File::File( const char * FilePath , const std::size_t Mode )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "File::File( const char * FilePath , const std::size_t Mode )::An error occured" ) , 0 ) );
                }
        }

Here is the call graph for this function:

nitro::File::File ( const std::string &  FilePath,
const std::size_t  Mode 
)

Function opens file FilePath in mode Mode.

Parameters:
FilePath - Path to the opening file.
Mode - File opening mode.
Exceptions:
nitro::exception Throws an exception of that type with the error description.
Author:
Dodonov A.A.

Definition at line 195 of file file_utilities.cpp.

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

        {
                try
                {
                        FileAbstraction::Open( FilePath.c_str() , Mode );
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "File::File( const std::string & FilePath , const std::size_t Mode )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "File::File( const std::string & FilePath , const std::size_t Mode )::An error occured" ) , 0 ) );
                }
        }

Here is the call graph for this function:

nitro::File::File ( const File File  )  [inline, private]

Private copy constructor.

Parameters:
File - Assigning file.
Exceptions:
nitro::exception Throws an exception of that type with the error description.
Author:
Dodonov A.A.

Definition at line 456 of file file_utilities.h.

{}


Member Function Documentation

nitro::File::ALIAS_FUNCTION_0 ( Close  ,
tstClose   
)
nitro::File::ALIAS_FUNCTION_2 ( Open  ,
tstOpen  ,
const char *  ,
std::size_t   
)
bool nitro::File::FileExists ( const char *  FilePath  )  [static]

Function valiates file's existance.

Parameters:
FilePath - Path to the file.
Returns:
true if the file exists, false otherwise.
Exceptions:
nitro::exception Throws an exception of that type with the error description.
Author:
Dodonov A.A.

Definition at line 113 of file file_utilities.cpp.

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

Referenced by nitro::MVC::Create(), FileExists(), nitro::MVC::LoadModule(), nitro::UnZIPAbstraction::Open(), and nitro::ZIPAbstraction::Open().

        {
                try
                {
                        if( strlen( FilePath ) == 0 )return( false );

                        std::ifstream   file( FilePath );

                        return( file.good() );
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "bool File::FileExists( const char * FilePath )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "bool File::FileExists( const char * FilePath )::An error occured" ) , 0 ) );
                }
        }

Here is the call graph for this function:

bool nitro::File::FileExists ( const std::string &  FilePath  )  [static]

Function valiates file's existance.

Parameters:
FilePath - Path to the file.
Returns:
true if the file exists, false otherwise.
Exceptions:
nitro::exception Throws an exception of that type with the error description.
Author:
Dodonov A.A.

Definition at line 264 of file file_utilities.cpp.

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

        {
                try
                {
                        return( FileExists( FilePath.c_str() ) );
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "File::FileExists( const std::string & FilePath )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "File::FileExists( const std::string & FilePath )::An error occured" ) , 0 ) );
                }
        }

Here is the call graph for this function:

std::size_t nitro::File::FileSize ( void   ) 

Function returns file size.

Returns:
File size in bytes.
Exceptions:
nitro::exception Throws an exception of that type with the error description.
Author:
Dodonov A.A.

Definition at line 171 of file file_utilities.cpp.

References nitro::exception::code(), nitro::FA_FILE_BEGIN, nitro::FA_FILE_END, nitro::FileAbstraction::Seek(), nitro::FileAbstraction::Tell(), and nitro::exception::what().

        {
                try
                {
                        std::size_t                             CurrentPosition( nitro::FileAbstraction::Tell() );

                        nitro::FileAbstraction::Seek( 0 , nitro::FA_FILE_END );

                        std::size_t                             EndPosition( nitro::FileAbstraction::Tell() );

                        FileAbstraction::Seek( CurrentPosition , nitro::FA_FILE_BEGIN );

                        return( EndPosition );
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "std::size_t File::FileSize( void )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "std::size_t File::FileSize( void )::An error occured" ) , 0 ) );
                }
        }

Here is the call graph for this function:

void nitro::File::ForceCreateFile ( const std::string &  FilePath  )  [static]

Function creates file.

Parameters:
FilePath - Path to the creating file.
Exceptions:
nitro::exception Throws an exception of that type with the error description.
Author:
Dodonov A.A.

Definition at line 296 of file file_utilities.cpp.

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

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

Here is the call graph for this function:

void nitro::File::ForceCreateFile ( const char *  FilePath  )  [static]

Function creates file.

Parameters:
FilePath - Path to the creating file.
Exceptions:
nitro::exception Throws an exception of that type with the error description.
Author:
Dodonov A.A.

Definition at line 149 of file file_utilities.cpp.

References nitro::exception::code(), nitro::FSPath::ExtractFilePath(), nitro::FA_FILE_BINARY, nitro::FA_FILE_WRITE, nitro::Directory::ForceCreateDirectory(), and nitro::exception::what().

Referenced by ForceCreateFile(), SaveBinDataToFile(), and nitro::UnZIPAbstraction::UnZIPFile().

        {
                try
                {
                        std::string                     ClearPath( nitro::FSPath::ExtractFilePath( std::string( FilePath ) ) );

                        // убеждаемся что для нового файла будет создана директория
                        Directory::ForceCreateDirectory( ClearPath.c_str() );

                        // создаем файл в только что созданной директории
                        File                            TmpFile( FilePath , nitro::FA_FILE_BINARY | nitro::FA_FILE_WRITE );
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "void File::ForceCreateFile( const char * FilePath )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "void File::ForceCreateFile( const char * FilePath )::An error occured" ) , 0 ) );
                }
        }

Here is the call graph for this function:

tm nitro::File::GetLastModified ( const std::string &  Path  )  [static]

Function returns time of the last modification.

Parameters:
Path - Path to the file.
Returns:
Date and time of the last modification.
Exceptions:
nitro::exception Throws an exception of that type with the error description.
Author:
Dodonov A.A.

Definition at line 248 of file file_utilities.cpp.

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

        {
                try
                {
                        return( GetLastModified( Path.c_str() ) );
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "File::GetLastModified( const std::string & Path )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "File::GetLastModified( const std::string & Path )::An error occured" ) , 0 ) );
                }
        }

Here is the call graph for this function:

tm nitro::File::GetLastModified ( const char *  Path  )  [static]

Function returns time of the last modification.

Parameters:
Path - Path to the file.
Returns:
Date and time of the last modification.
Exceptions:
nitro::exception Throws an exception of that type with the error description.
Author:
Dodonov A.A.

Definition at line 86 of file file_utilities.cpp.

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

Referenced by nitro::ZIPAbstraction::AddFile(), and GetLastModified().

        {
                try
                {
                        struct stat                     FileInfo;

                        if( stat( Path , & FileInfo ) != 0 )
                        {
                                throw( nitro::exception( std::string( "GetLastModified( const char * Path )::An error occured while getting info for file/folder" ) , 0 ) );
                        }

                        struct tm                       ModificationDate;

                        ModificationDate = * localtime( & FileInfo.st_mtime );

                        return( ModificationDate );
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "tm File::GetLastModified( const char * Path )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "tm File::GetLastModified( const char * Path )::An error occured" ) , 0 ) );
                }
        }

Here is the call graph for this function:

void nitro::File::LoadBinDataFromFile ( nitro::BinaryData BinData,
const char *  Path 
) [static]

Function loas binary data from file.

Parameters:
BinData - Binary data to store.
Path - Path to the reading file.
Exceptions:
nitro::exception Throws an exception of that type with the error description.
Author:
Dodonov A.A.

Definition at line 57 of file file_utilities.cpp.

References nitro::BinaryData::AppendData(), nitro::exception::code(), nitro::FA_FILE_READ, nitro::FileAbstraction::Open(), nitro::FileAbstraction::Read(), and nitro::exception::what().

Referenced by nitro::ZIPAbstraction::AddFile(), LoadBinDataFromFile(), nitro::INIFile::LoadINIFile(), nitro::TemplateEngine::LoadTemplateFromFile(), and nitro::XMLFile::LoadXML().

        {
                try
                {
                        nitro::FileAbstraction          File;
                        
                        File.Open( Path , nitro::FA_FILE_READ );
                        
                        char                                    Buffer[ 1024 ];
                        
                        std::size_t                             ReadBytes( 0 );

                        do
                        {
                                ReadBytes = File.Read( Buffer , 1024 );
                                BinData.AppendData( Buffer , ReadBytes );
                        }
                        while( ReadBytes == 1024 );
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "void File::LoadBinDataFromFile( BinaryData & BinData , const char * Path )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "void File::LoadBinDataFromFile( BinaryData & BinData , const char * Path )::An error occured" ) , 0 ) );
                }
        }

Here is the call graph for this function:

void nitro::File::LoadBinDataFromFile ( nitro::BinaryData BinData,
const std::string &  Path 
) [static]

Function loas binary data from file.

Parameters:
BinData - Binary data to store.
Path - Path to the reading file.
Exceptions:
nitro::exception Throws an exception of that type with the error description.
Author:
Dodonov A.A.

Definition at line 232 of file file_utilities.cpp.

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

        {
                try
                {
                        LoadBinDataFromFile( BinData , Path.c_str() );
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "File::LoadBinDataFromFile( BinaryData & BinData , const std::string & Path )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "File::LoadBinDataFromFile( BinaryData & BinData , const std::string & Path )::An error occured" ) , 0 ) );
                }
        }

Here is the call graph for this function:

File nitro::File::operator= ( const File File  )  [inline, private]

Private assign operator.

Parameters:
File - Assigning file.
Returns:
Copy of the assigned object.
Exceptions:
nitro::exception Throws an exception of that type with the error description.
Author:
Dodonov A.A.

Definition at line 480 of file file_utilities.h.

{return( *this );}

void nitro::File::SaveBinDataToFile ( const BinaryData BinData,
const char *  Path 
) [static]

Function saves binary data to file.

Parameters:
BinData - Binary data to save.
Path - Path to the saving file.
Exceptions:
nitro::exception Throws an exception of that type with the error description.
Author:
Dodonov A.A.

Definition at line 30 of file file_utilities.cpp.

References nitro::exception::code(), nitro::FA_FILE_BINARY, nitro::FA_FILE_TRUNCATE, nitro::FA_FILE_WRITE, ForceCreateFile(), nitro::BinaryData::GetBuffer(), nitro::BinaryData::GetBufferLength(), nitro::FileAbstraction::Open(), nitro::exception::what(), and nitro::FileAbstraction::Write().

Referenced by nitro::UnTARAbstraction::ExtractFile(), SaveBinDataToFile(), and nitro::INIFile::SaveINIFile().

        {
                try
                {
                        if( Path == NULL || std::string( Path ).size() == 0 )
                        {
                                throw( nitro::exception( std::string( "File path was not specified" ) , 1 ) );
                        }

                        nitro::FileAbstraction          File;
                        
                        File::ForceCreateFile( Path );

                        File.Open( Path , nitro::FA_FILE_WRITE | nitro::FA_FILE_BINARY | nitro::FA_FILE_TRUNCATE );
                        
                        File.Write( BinData.GetBuffer() , ( unsigned int )BinData.GetBufferLength() );
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "void File::SaveBinDataToFile( const BinaryData & BinData , const char * Path )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "void File::SaveBinDataToFile( const BinaryData & BinData , const char * Path )::An error occured" ) , 0 ) );
                }
        }

Here is the call graph for this function:

void nitro::File::SaveBinDataToFile ( const BinaryData BinData,
const std::string &  Path 
) [static]

Function saves binary data to file.

Parameters:
BinData - Binary data to save.
Path - Path to the saving file.
Exceptions:
nitro::exception Throws an exception of that type with the error description.
Author:
Dodonov A.A.

Definition at line 211 of file file_utilities.cpp.

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

        {
                try
                {
                        if( Path.size() == 0 )
                        {
                                throw( nitro::exception( std::string( "File path was not specified" ) , 1 ) );
                        }

                        SaveBinDataToFile( BinData , Path.c_str() );
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "File::SaveBinDataToFile( const BinaryData & BinData , const std::string & Path )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "File::SaveBinDataToFile( const BinaryData & BinData , const std::string & Path )::An error occured" ) , 0 ) );
                }
        }

Here is the call graph for this function:

void nitro::File::Write ( const char *  Data  ) 

Function writes NULL-terminated string into file.

Parameters:
Data - Writing string.
Exceptions:
nitro::exception Throws an exception of that type with the error description.
Author:
Dodonov A.A.

Definition at line 133 of file file_utilities.cpp.

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

Referenced by nitro::UnZIPAbstraction::UnZIPFile(), and Write().

        {
                try
                {
                        nitro::FileAbstraction::Write( Data , strlen( Data ) );
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "void File::Write( const char * Data )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "void File::Write( const char * Data )::An error occured" ) , 0 ) );
                }
        }

Here is the call graph for this function:

void nitro::File::Write ( const std::string &  Data  ) 

Function writes NULL-terminated string into file.

Parameters:
Data - writing string.
Exceptions:
nitro::exception Throws an exception of that type with the error description.
Author:
Dodonov A.A.

Definition at line 280 of file file_utilities.cpp.

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

        {
                try
                {
                        Write( Data.c_str() );
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "File::Write( const std::string & Data )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "File::Write( const std::string & Data )::An error occured" ) , 0 ) );
                }
        }

Here is the call graph for this function:


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

Generated by  doxygen 1.6.1