Class for processing directories. More...
#include <system/directory_abstraction.h>
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 |
Class for processing directories.
Definition at line 56 of file directory_abstraction.h.
nitro::DirectoryAbstraction::DirectoryAbstraction | ( | void | ) |
Constructor.
Definition at line 17 of file directory_abstraction.cpp.
References FindData, and FindHandle.
{ FindHandle = NULL; FindData = NULL; }
nitro::DirectoryAbstraction::~DirectoryAbstraction | ( | ) | [virtual] |
Destructor (virtual).
Definition at line 367 of file directory_abstraction.cpp.
References Release().
{ try { Release(); } catch( ... ) { } }
nitro::DirectoryAbstraction::DirectoryAbstraction | ( | const DirectoryAbstraction & | DirectoryAbstraction | ) | [inline, private] |
Copy constructor.
DirectoryAbstraction | - DirectoryAbstraction object to construct *this. |
nitro::exception | Throws exception wich contains error description. |
Definition at line 454 of file directory_abstraction.h.
{}
void nitro::DirectoryAbstraction::CreateDirectory | ( | const char * | DirPath | ) | [static] |
Function creates directory.
DirPath | - Path to the creating directory. |
nitro::exception | - Throws exception of that type with the description of the error. |
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 ) ); } }
void nitro::DirectoryAbstraction::CreateDirectory | ( | const std::string & | DirPath | ) | [static] |
Function creates directory.
DirPath | - Path to the creating directory. |
nitro::exception | - Throws exception of that type with the description of the error. |
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 ) ); } }
bool nitro::DirectoryAbstraction::FindFirst | ( | const std::string & | DirectoryPath | ) |
Function sets path to be scanned.
DirectoryPath | - Path to the searched file or directory. If directory is searched then ending slash must exist. |
nitro::exception | Throws exception wich contains error description. |
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 ) ); } }
bool nitro::DirectoryAbstraction::FindFirst | ( | const char * | DirectoryPath | ) |
Function sets path to be scanned.
DirectoryPath | - Path to the searched file or directory. If directory is searched then ending slash must exist. |
nitro::exception | Throws exception wich contains error description. |
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 ); }
bool nitro::DirectoryAbstraction::FindNext | ( | void | ) |
Function searches next file system entity (directory or file).
nitro::exception | Throws exception wich contains error description. |
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 ); }
const char * nitro::DirectoryAbstraction::GetName | ( | void | ) |
Function returns name of found directory or file (including extension).
nitro::exception | Throws exception wich contains error description. |
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 ) ); } }
bool nitro::DirectoryAbstraction::IsDirectory | ( | void | ) |
Function tells us what we have found.
nitro::exception | Throws exception wich contains error description. |
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 ) ); } }
bool nitro::DirectoryAbstraction::IsDirectory | ( | const char * | DirectoryPath | ) | [static] |
Function validates path.
DirectoryPath | - Path to be validated. |
nitro::exception | Throws exception wich contains error description. |
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 ); }
bool nitro::DirectoryAbstraction::IsDirectory | ( | const std::string & | DirectoryPath | ) | [static] |
Function validates path.
DirectoryPath | - Path to be validated. |
nitro::exception | Throws exception wich contains error description. |
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 ) ); } }
bool nitro::DirectoryAbstraction::IsDots | ( | void | ) |
Function tells us what we have found.
nitro::exception | Throws exception wich contains error description. |
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 ) ); } }
bool nitro::DirectoryAbstraction::IsFile | ( | const std::string & | FilePath | ) | [static] |
Function validates path.
FilePath | - Path to be validated. |
nitro::exception | Throws exception wich contains error description. |
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 ); }
bool nitro::DirectoryAbstraction::IsFile | ( | void | ) |
Function tells us what we have found.
nitro::exception | Throws exception wich contains error description. |
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 ); }
bool nitro::DirectoryAbstraction::IsFile | ( | const char * | FilePath | ) | [static] |
Function validates path.
FilePath | - Path to be validated. |
nitro::exception | Throws exception wich contains error description. |
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 ); }
DirectoryAbstraction nitro::DirectoryAbstraction::operator= | ( | const DirectoryAbstraction & | DirectoryAbstraction | ) | [inline, private] |
Assign operator.
DirectoryAbstraction | - DirectoryAbstraction - assigning object. |
nitro::exception | Throws exception wich contains error description. |
Definition at line 478 of file directory_abstraction.h.
{return( *this );}
void nitro::DirectoryAbstraction::Release | ( | void | ) |
Function releases all allocated resources.
nitro::exception | Throws exception wich contains error description. |
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 ) ); } }
std::string nitro::DirectoryAbstraction::DirectoryPath [private] |
Path to the reading directory.
Definition at line 434 of file directory_abstraction.h.
Referenced by FindFirst(), IsDirectory(), and IsFile().
void* nitro::DirectoryAbstraction::FindData [private] |
Field contains information about opened directory.
Definition at line 398 of file directory_abstraction.h.
Referenced by DirectoryAbstraction(), FindFirst(), FindNext(), GetName(), IsFile(), and Release().
void* nitro::DirectoryAbstraction::FindHandle [private] |
Field contains information about opened directory.
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.
Definition at line 422 of file directory_abstraction.h.
Referenced by GetName().