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

nitro::DirectoryAbstraction Class Reference

Class for processing directories. More...

#include <system/directory_abstraction.h>

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

List of all members.

Public Member Functions

 DirectoryAbstraction (void)
bool FindFirst (const char *DirectoryPath)
bool FindFirst (const std::string &DirectoryPath)
bool FindNext (void)
bool IsDirectory (void)
bool IsFile (void)
bool IsDots (void)
const char * GetName (void)
void Release (void)
virtual ~DirectoryAbstraction ()

Static Public Member Functions

static bool IsDirectory (const char *DirectoryPath)
static bool IsDirectory (const std::string &DirectoryPath)
static bool IsFile (const char *FilePath)
static bool IsFile (const std::string &FilePath)
static void CreateDirectory (const char *DirPath)
static void CreateDirectory (const std::string &DirPath)

Private Member Functions

 DirectoryAbstraction (const DirectoryAbstraction &DirectoryAbstraction)
DirectoryAbstraction operator= (const DirectoryAbstraction &DirectoryAbstraction)

Private Attributes

void * FindData
void * FindHandle
std::string PathBuffer
std::string DirectoryPath

Detailed Description

Class for processing directories.

Author:
Dodonov A.A.

Definition at line 56 of file directory_abstraction.h.


Constructor & Destructor Documentation

nitro::DirectoryAbstraction::DirectoryAbstraction ( void   ) 

Constructor.

Author:
Dodonov A.A.

Definition at line 17 of file directory_abstraction.cpp.

References FindData, and FindHandle.

        {
                FindHandle = NULL;

                FindData = NULL;
        }

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

Destructor (virtual).

Author:
Dodonov A.A.

Definition at line 367 of file directory_abstraction.cpp.

References Release().

        {
                try
                {
                        Release();
                }
                catch( ... )
                {
                }
        }

Here is the call graph for this function:

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

Copy constructor.

Parameters:
DirectoryAbstraction - DirectoryAbstraction object to construct *this.
Exceptions:
nitro::exception Throws exception wich contains error description.
Author:
Dodonov A.A.

Definition at line 454 of file directory_abstraction.h.

{}


Member Function Documentation

void nitro::DirectoryAbstraction::CreateDirectory ( const char *  DirPath  )  [static]

Function creates directory.

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

Definition at line 323 of file directory_abstraction.cpp.

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

Referenced by CreateDirectory(), and nitro::Directory::ForceCreateDirectory().

        {
                try
                {
                #if defined( WIN32_PLATFORM ) || defined( MINGW_PLATFORM )
                        if( !::CreateDirectoryA( DirPath , NULL ) )
                        {
                                throw( nitro::exception( std::string( "An error occured while creating directory" ) , 0 ) );
                        }
                #endif

                #if     defined( NIX_PLATFORM ) || defined( CYGWIN_PLATFORM )
                        if( mkdir( DirPath , S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH ) == -1 )
                        {
                                throw( nitro::exception( std::string( "An error occured while creating directory" ) , 0 ) );
                        }
                #endif
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "DirectoryAbstraction::CreateDirectory( const char * DirPath )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "DirectoryAbstraction::CreateDirectory( const char * DirPath )::An error occured" ) , 0 ) );
                }
        }

Here is the call graph for this function:

void nitro::DirectoryAbstraction::CreateDirectory ( const std::string &  DirPath  )  [static]

Function creates directory.

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

Definition at line 351 of file directory_abstraction.cpp.

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

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

Here is the call graph for this function:

bool nitro::DirectoryAbstraction::FindFirst ( const std::string &  DirectoryPath  ) 

Function sets path to be scanned.

Parameters:
DirectoryPath - Path to the searched file or directory. If directory is searched then ending slash must exist.
Returns:
Nonzero if an error occured. Zero otherwise.
Exceptions:
nitro::exception Throws exception wich contains error description.
Author:
Dodonov A.A.

Definition at line 65 of file directory_abstraction.cpp.

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

        {
                try
                {
                        return( FindFirst( DirectoryPath.c_str() ) );
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "DirectoryAbstraction::FindFirst( const std::string & DirectoryPath )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "DirectoryAbstraction::FindFirst( const std::string & DirectoryPath )::An error occured while setting folder path" ) , 0 ) );
                }
        }

Here is the call graph for this function:

bool nitro::DirectoryAbstraction::FindFirst ( const char *  DirectoryPath  ) 

Function sets path to be scanned.

Parameters:
DirectoryPath - Path to the searched file or directory. If directory is searched then ending slash must exist.
Returns:
Nonzero if an error occured. Zero otherwise.
Exceptions:
nitro::exception Throws exception wich contains error description.
Author:
Dodonov A.A.

Definition at line 24 of file directory_abstraction.cpp.

References nitro::FSPath::AddEndSlash(), nitro::exception::code(), DirectoryPath, FindData, FindHandle, IsDirectory(), Release(), and nitro::exception::what().

Referenced by nitro::Directory::DirectoryExists(), FindFirst(), and nitro::WalkThroughDirectory().

        {
                try
                {
                        Release();
                        
                        if( IsDirectory( theDirectoryPath ) == false )
                        {
                                throw( nitro::exception( std::string( "Path " ) + theDirectoryPath + " must lead to directory" , 1 ) );
                        }
                        
                        DirectoryPath = theDirectoryPath;
                        
                #if defined( WIN32_PLATFORM ) || defined( MINGW_PLATFORM )
                
                        FindData = ( void * ) new WIN32_FIND_DATA;

                        FindHandle = ( void * ) new HANDLE;

                        * ( ( HANDLE * )FindHandle ) = ::FindFirstFile( ( nitro::FSPath::AddEndSlash( std::string( theDirectoryPath ) ) + "*" ).c_str() , ( WIN32_FIND_DATA * )FindData );
                        
                        return( * ( ( HANDLE * )FindHandle ) == INVALID_HANDLE_VALUE );
                #endif

                #if     defined( NIX_PLATFORM ) || defined( CYGWIN_PLATFORM )
                        FindHandle = ( void * )opendir( theDirectoryPath );
                        
                        return( FindHandle == NULL );
                #endif
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "DirectoryAbstraction::FindFirst( const char * theDirectoryPath )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "DirectoryAbstraction::FindFirst( const char * theDirectoryPath )::An error occured while setting folder path" ) , 0 ) );
                }
                return( true );
        }

Here is the call graph for this function:

bool nitro::DirectoryAbstraction::FindNext ( void   ) 

Function searches next file system entity (directory or file).

Returns:
true if an error occured. false otherwise.
Exceptions:
nitro::exception Throws exception wich contains error description.
Author:
Dodonov A.A.

Definition at line 81 of file directory_abstraction.cpp.

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

Referenced by nitro::WalkThroughDirectory().

        {
                try
                {
                #if defined( WIN32_PLATFORM ) || defined( MINGW_PLATFORM )
                        return( ::FindNextFile( * ( HANDLE * )FindHandle , ( WIN32_FIND_DATA * )FindData ) == 0 );
                #endif

                #if     defined( NIX_PLATFORM ) || defined( CYGWIN_PLATFORM )
                        return( ( FindData = readdir( ( DIR * )FindHandle ) ) == NULL );
                #endif
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "DirectoryAbstraction::FindNext( void )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "DirectoryAbstraction::FindNext( void )::An error occured while finding next item" ) , 0 ) );
                }
                return( true );
        }

Here is the call graph for this function:

const char * nitro::DirectoryAbstraction::GetName ( void   ) 

Function returns name of found directory or file (including extension).

Returns:
Name of the founded file or directory.
Exceptions:
nitro::exception Throws exception wich contains error description.
Author:
Dodonov A.A.

Definition at line 269 of file directory_abstraction.cpp.

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

Referenced by IsDirectory(), IsDots(), IsFile(), and nitro::WalkThroughDirectory().

        {
                try
                {
                #if defined( WIN32_PLATFORM ) || defined( MINGW_PLATFORM )
                        PathBuffer = ( ( WIN32_FIND_DATA * )FindData )->cFileName;
                #endif

                #if     defined( NIX_PLATFORM ) || defined( CYGWIN_PLATFORM )
                        PathBuffer = ( ( dirent * )FindData )->d_name;
                #endif

                        return( PathBuffer.c_str() );
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "DirectoryAbstraction::GetName( void )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "DirectoryAbstraction::GetName( void )::An error occured" ) , 0 ) );
                }
        }

Here is the call graph for this function:

bool nitro::DirectoryAbstraction::IsDirectory ( void   ) 

Function tells us what we have found.

Returns:
true if directory was found. Otherwise false.
Exceptions:
nitro::exception Throws exception wich contains error description.
Author:
Dodonov A.A.

Definition at line 104 of file directory_abstraction.cpp.

References nitro::exception::code(), DirectoryPath, GetName(), IsDots(), IsFile(), and nitro::exception::what().

Referenced by FindFirst(), IsDirectory(), and nitro::WalkThroughDirectory().

        {
                try
                {
                #if defined( WIN32_PLATFORM ) || defined( MINGW_PLATFORM )
                        return( IsFile() == false && IsDots() == false );
                #endif

                #if     defined( NIX_PLATFORM ) || defined( CYGWIN_PLATFORM )
                        DIR *                   d( opendir( ( DirectoryPath + GetName() ).c_str() ) );
                        
                        if( d )
                        {
                                closedir( d );
                                return( true );
                        }
                        else
                        {
                                return( false );
                        }
                #endif
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "DirectoryAbstraction::IsDirectory( void )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "DirectoryAbstraction::IsDirectory( void )::An error occured while getting info (f)" ) , 0 ) );
                }
        }

Here is the call graph for this function:

bool nitro::DirectoryAbstraction::IsDirectory ( const char *  DirectoryPath  )  [static]

Function validates path.

Parameters:
DirectoryPath - Path to be validated.
Returns:
true if directory was found. Otherwise false.
Exceptions:
nitro::exception Throws exception wich contains error description.
Author:
Dodonov A.A.

Definition at line 204 of file directory_abstraction.cpp.

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

        {
                try
                {
                #if defined( WIN32_PLATFORM ) || defined( MINGW_PLATFORM )
                        return( ( GetFileAttributes( theDirectoryPath ) & FILE_ATTRIBUTE_DIRECTORY ) != 0 );
                #endif

                #if     defined( NIX_PLATFORM ) || defined( CYGWIN_PLATFORM )
                        DIR *                   d( opendir( theDirectoryPath ) );
                        
                        if( d )
                        {
                                closedir( d );
                                return( true );
                        }
                        else
                        {
                                return( false );
                        }
                #endif
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "DirectoryAbstraction::IsDirectory( const char * theDirectoryPath )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "DirectoryAbstraction::IsDirectory( const char * theDirectoryPath )::An error occured while getting info (d)" ) , 0 ) );
                }
                return( true );
        }

Here is the call graph for this function:

bool nitro::DirectoryAbstraction::IsDirectory ( const std::string &  DirectoryPath  )  [static]

Function validates path.

Parameters:
DirectoryPath - Path to be validated.
Returns:
true if directory was found. Otherwise false.
Exceptions:
nitro::exception Throws exception wich contains error description.
Author:
Dodonov A.A.

Definition at line 237 of file directory_abstraction.cpp.

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

        {
                try
                {
                        return( IsDirectory( theDirectoryPath.c_str() ) );
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "DirectoryAbstraction::IsDirectory( const std::string & theDirectoryPath )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "DirectoryAbstraction::IsDirectory( const std::string & theDirectoryPath )::An error occured while getting info (d)" ) , 0 ) );
                }
        }

Here is the call graph for this function:

bool nitro::DirectoryAbstraction::IsDots ( void   ) 

Function tells us what we have found.

Returns:
true if "." or ".." was found. Otherwise false.
Exceptions:
nitro::exception Throws exception wich contains error description.
Author:
Dodonov A.A.

Definition at line 253 of file directory_abstraction.cpp.

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

Referenced by IsDirectory(), and nitro::WalkThroughDirectory().

        {
                try
                {
                        return( std::string( GetName() ) == "." || std::string( GetName() ) == ".." );
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "DirectoryAbstraction::IsDots( void )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "DirectoryAbstraction::IsDots( void )::An error occured while getting info (d)" ) , 0 ) );
                }
        }

Here is the call graph for this function:

bool nitro::DirectoryAbstraction::IsFile ( const std::string &  FilePath  )  [static]

Function validates path.

Parameters:
FilePath - Path to be validated.
Returns:
true if file was found. Otherwise false.
Exceptions:
nitro::exception Throws exception wich contains error description.
Author:
Dodonov A.A.

Definition at line 187 of file directory_abstraction.cpp.

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

        {
                try
                {
                        return( IsFile( FilePath.c_str() ) );
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "DirectoryAbstraction::IsFile( const std::string & FilePath )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "DirectoryAbstraction::IsFile( const std::string & FilePath )::An error occured while getting info (d)" ) , 0 ) );
                }
                return( true );
        }

Here is the call graph for this function:

bool nitro::DirectoryAbstraction::IsFile ( void   ) 

Function tells us what we have found.

Returns:
true if file was found. Otherwise false.
Exceptions:
nitro::exception Throws exception wich contains error description.
Author:
Dodonov A.A.

Definition at line 136 of file directory_abstraction.cpp.

References nitro::exception::code(), DirectoryPath, FindData, GetName(), and nitro::exception::what().

Referenced by IsDirectory(), and IsFile().

        {
                try
                {
                #if defined( WIN32_PLATFORM ) || defined( MINGW_PLATFORM )
                        return( ( ( ( WIN32_FIND_DATA * )FindData )->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) == 0 );
                #endif

                #if     defined( NIX_PLATFORM ) || defined( CYGWIN_PLATFORM )
                        struct stat             s;
                        
                        return( stat( ( std::string( DirectoryPath ) + GetName() ).c_str() , & s ) == 0 );
                #endif

                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "DirectoryAbstraction::IsFile( void )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "DirectoryAbstraction::IsDots( void )::An error occured while getting info (d)" ) , 0 ) );
                }
                return( true );
        }

Here is the call graph for this function:

bool nitro::DirectoryAbstraction::IsFile ( const char *  FilePath  )  [static]

Function validates path.

Parameters:
FilePath - Path to be validated.
Returns:
true if file was found. Otherwise false.
Exceptions:
nitro::exception Throws exception wich contains error description.
Author:
Dodonov A.A.

Definition at line 162 of file directory_abstraction.cpp.

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

        {
                try
                {
                #if defined( WIN32_PLATFORM ) || defined( MINGW_PLATFORM )
                        return( ( GetFileAttributes( FilePath ) & FILE_ATTRIBUTE_DIRECTORY ) == 0 );
                #endif

                #if     defined( NIX_PLATFORM ) || defined( CYGWIN_PLATFORM )
                        struct stat             s;

                        return( stat( FilePath , & s ) == 0 );
                #endif
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "DirectoryAbstraction::IsFile( const char * FilePath )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "DirectoryAbstraction::IsFile( const char * FilePath )::An error occured while getting info (d)" ) , 0 ) );
                }
                return( true );
        }

Here is the call graph for this function:

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

Assign operator.

Parameters:
DirectoryAbstraction - DirectoryAbstraction - assigning object.
Returns:
Copy of *this;
Exceptions:
nitro::exception Throws exception wich contains error description.
Author:
Dodonov A.A.

Definition at line 478 of file directory_abstraction.h.

{return( *this );}

void nitro::DirectoryAbstraction::Release ( void   ) 

Function releases all allocated resources.

Exceptions:
nitro::exception Throws exception wich contains error description.
Author:
Dodonov A.A.

Definition at line 293 of file directory_abstraction.cpp.

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

Referenced by FindFirst(), and ~DirectoryAbstraction().

        {
                try
                {
                        if( FindHandle )
                        {
                        #if defined( WIN32_PLATFORM ) || defined( MINGW_PLATFORM )
                                ::FindClose( * ( ( HANDLE * )FindHandle ) );

                                delete ( HANDLE * ) FindHandle;
                                delete ( WIN32_FIND_DATA * ) FindData;
                        #endif

                        #if     defined( NIX_PLATFORM ) || defined( CYGWIN_PLATFORM )
                                closedir( ( DIR * )FindHandle );
                        #endif

                                FindData = FindHandle = NULL;
                        }
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "DirectoryAbstraction::Release( void )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "DirectoryAbstraction::Release( void )::An error occured" ) , 0 ) );
                }
        }

Here is the call graph for this function:


Member Data Documentation

Path to the reading directory.

Author:
Dodonov A.A.

Definition at line 434 of file directory_abstraction.h.

Referenced by FindFirst(), IsDirectory(), and IsFile().

Field contains information about opened directory.

Author:
Dodonov A.A.

Definition at line 398 of file directory_abstraction.h.

Referenced by DirectoryAbstraction(), FindFirst(), FindNext(), GetName(), IsFile(), and Release().

Field contains information about opened directory.

Author:
Dodonov A.A.

Definition at line 410 of file directory_abstraction.h.

Referenced by DirectoryAbstraction(), FindFirst(), FindNext(), and Release().

std::string nitro::DirectoryAbstraction::PathBuffer [mutable, private]

Temporary buffer to store file's of directory's path.

Author:
Dodonov A.A.

Definition at line 422 of file directory_abstraction.h.

Referenced by GetName().


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

Generated by  doxygen 1.6.1