version 3.3

VRS::File Class Reference

Collection of some usefull file functions. More...

#include <vrs/io/file.h>

Inheritance diagram for VRS::File:

VRS::SharedObj VRS::Visitable

List of all members.

Public Types

enum  WriteMode { WM_ReadOnly, WM_Create, WM_Overwrite, WM_Append }
enum  SeekMode { SM_FromStart, SM_FromCurrent, SM_FromEnd }
enum  FileTime { Access, Modification }

Public Member Functions

 VRS_SERIALIZABLE_CLASS_ENUM (WriteMode)
 VRS_SERIALIZABLE_CLASS_ENUM (SeekMode)
 File (const std::string &filename, WriteMode writeMode=WM_ReadOnly)
bool isReadOnly () const
std::string fullName () const
 Returns the full file name used for opening/creating the file.
std::string fileName () const
std::string pathName () const
std::string baseName () const
std::string extensionName () const
std::string replaceExtensionName (const std::string &extensionName) const
UINT64 size () const
 Returns the size of the file as a 64 bit integer!
UINT64 position () const
 Returns the current file pointer position!
UINT64 seek (INT64 relativePosition, SeekMode seekMode=SM_FromStart)
UINT64 read (void *writeInto, UINT64 bytes)
UINT64 write (const void *readFrom, UINT64 bytes)
UINT64 resize (UINT64 bytes)
UINT64 truncate ()
SO< DataResourcemapToMemory ()
 VRS_TYPEINFO (File, SharedObj)

Static Public Member Functions

static bool exists (const std::string &filename)
 Checks, if the given file exists.
static bool isFile (const std::string &filename)
 Checks, if the given name belongs to an existing file.
static bool isDir (const std::string &dirname)
 Checks, if the given name belongs to an existing directory.
static bool isRelative (const std::string &name)
 Checks, if the given name is a relative pathname.
static std::vector< std::string > matchingEntries (const std::string &dirName, const std::string &pattern="*", bool includeFiles=true, bool includeDirs=true, bool recurseIntoSubDirs=false)
static UINT64 size (const std::string &filename)
static bool create (const std::string &filename, UINT64 size=0, const void *copyFrom=NULL)
static bool append (const std::string &filename, UINT64 size, const void *copyFrom=NULL)
static bool rename (const std::string &oldFilename, const std::string &newFilename)
 Renames the given file to the given new filename. Returns true on success.
static bool getFileTime (const std::string &filename, FileTime type, time_t *time)
static bool setFileTime (const std::string &filename, FileTime type, time_t time)
static bool copy (const std::string &fromFilename, const std::string &toFilename)
 Copies the content of the given file to the given new file. Returns true on success.
static bool remove (const std::string &filename)
 Deletes the given file. Returns true on success.
static bool createDir (const std::string &dirname)
 creates a new directory
static bool removeDir (const std::string &dirname)
 removes a directory
static bool removeOldFiles (const std::string &dirname, const std::string &fileExtension, unsigned int numberOfFilesToRemove=20)
 removes 'numberOfFilesToRemove' old files (based on time of last data modification) does not work recursive !!! does nothing and return 'false' if directory contain less than 'numberOfFilesToRemove' files
static std::string temporaryDir ()
static void temporaryDir (const std::string &tempDir)
static std::string temporaryFileName (const std::string &fileNamePrefix="")
 Creates a unique filename for temporary files.
static SO< FilenewTemporaryFile (const std::string &fileNamePrefix="")
 Creates and returns a new temporary file.
static std::string fileName (const std::string &fullFileName)
static std::string pathName (const std::string &fullFileName)
static std::string baseName (const std::string &fullFileName)
static std::string extensionName (const std::string &fullFileName)
static std::string replaceExtensionName (const std::string &fullFileName, const std::string &extensionName)
static SO< DataResourcemapToMemory (const std::string &fileName, bool readOnly=true)
static std::string currentWorkingDir (const int drive=-1)
static std::string initialWorkingDir ()
static std::string relativePath (const std::string &absolutePath, const std::string &relativeTo=File::currentWorkingDir(), const bool absolutePathIsDir=false)
 Given an absolute file name and a directory, returns a file name relative to that directory.
static std::string absolutePath (const std::string &relativePath, const std::string &relativeTo=File::currentWorkingDir())
 Resolves a relative path to an absolute one.


Detailed Description

Collection of some usefull file functions.

Member Enumeration Documentation

Enumerator:
WM_ReadOnly 
WM_Create 
WM_Overwrite 
WM_Append 

Enumerator:
SM_FromStart 
SM_FromCurrent 
SM_FromEnd 

Enumerator:
Access 
Modification 


Constructor & Destructor Documentation

VRS::File::File ( const std::string &  filename,
WriteMode  writeMode = WM_ReadOnly 
)

Opens the given file for reading and with the given write mode: WM_ReadOnly: no writing possible (file must exist) WM_Create: creates a new file of size 0 (replacing an existing one) WM_Overwrite: opens the file (if it exists) and places the file pointer at the beginning of the file or creates a new file WM_Append: opens the file (if it exists) and places the file pointer at the end of the file or creates a new file


Member Function Documentation

VRS::File::VRS_SERIALIZABLE_CLASS_ENUM ( WriteMode   ) 

VRS::File::VRS_SERIALIZABLE_CLASS_ENUM ( SeekMode   ) 

bool VRS::File::isReadOnly (  )  const

std::string VRS::File::fullName (  )  const

Returns the full file name used for opening/creating the file.

std::string VRS::File::fileName (  )  const

Returns the file name used for opening/creating the file (see same static method below).

std::string VRS::File::pathName (  )  const

Returns the path name part of name used for opening/creating the file (see smae static method below).

std::string VRS::File::baseName (  )  const

Returns the base name part of the name used for opening/creating the file (see same static method below).

std::string VRS::File::extensionName (  )  const

Returns the extension name part of the name used for opening/creating the file (see same static method below).

std::string VRS::File::replaceExtensionName ( const std::string &  extensionName  )  const

Replaces the extension name part of the name used for opening/creating the file with the given extension name (see same static method below).

UINT64 VRS::File::size (  )  const

Returns the size of the file as a 64 bit integer!

UINT64 VRS::File::position (  )  const

Returns the current file pointer position!

UINT64 VRS::File::seek ( INT64  relativePosition,
SeekMode  seekMode = SM_FromStart 
)

Positions the file pointer at the given new position. The seekMode specifies whether the new position is specified relative to the file start/end, or the current position, and returns the new position relative to the file start. Note: newPosition must be >= 0 if seekMode is SM_FromStart, can be positive or negative if seekMode is SM_FromCurrent, and must be <= 0 if seekMode is SM_FromEnd.

UINT64 VRS::File::read ( void *  writeInto,
UINT64  bytes 
)

Reads the given number of bytes from the current position into the given memory location and returns the new file pointer position.

UINT64 VRS::File::write ( const void *  readFrom,
UINT64  bytes 
)

Writes the given number of bytes from the given memory location to the current position of the file pointer and returns the new the file pointer position.

UINT64 VRS::File::resize ( UINT64  bytes  ) 

Resizes the file to the given number of bytes. If the current file size is less than the new size zeros are appended to the file; if the current file size is larger than the new size the file is truncated. If the current file pointer position is behind new file end it is moved to the new file end. The new file pointer position will be returned.

UINT64 VRS::File::truncate (  ) 

Truncates the file at the current file pointer position. The new file size (= file pointer position) will be returned.

SO<DataResource> VRS::File::mapToMemory (  ) 

Tries to map the content of the file to memory. Returns NULL in case the mapping failed.

static bool VRS::File::exists ( const std::string &  filename  )  [static]

Checks, if the given file exists.

static bool VRS::File::isFile ( const std::string &  filename  )  [static]

Checks, if the given name belongs to an existing file.

static bool VRS::File::isDir ( const std::string &  dirname  )  [static]

Checks, if the given name belongs to an existing directory.

static bool VRS::File::isRelative ( const std::string &  name  )  [static]

Checks, if the given name is a relative pathname.

static std::vector<std::string> VRS::File::matchingEntries ( const std::string &  dirName,
const std::string &  pattern = "*",
bool  includeFiles = true,
bool  includeDirs = true,
bool  recurseIntoSubDirs = false 
) [static]

Returns a list of file and directory names that match the given pattern in the given directory; use "*" and "?" as wildcards in the pattern (e.g. "vrs-??.txt", "*.dll", or "vrs.*"). The flags includeFiles and includeDirs specify if the returned list should contain file and/or directory names. The flag recurseIntoSubDirs indicates if the given pattern should be searched recursively in subdirectories, too.

static UINT64 VRS::File::size ( const std::string &  filename  )  [static]

Returns the size of the given file. Returns 0, if the file does not exist.

static bool VRS::File::create ( const std::string &  filename,
UINT64  size = 0,
const void *  copyFrom = NULL 
) [static]

Creates a new file with the given filename and with the given size (if the file already exists it will be overwritten). If "copyFrom" is not NULL, "size"-many bytes are copied into the new file. Returns true on success.

static bool VRS::File::append ( const std::string &  filename,
UINT64  size,
const void *  copyFrom = NULL 
) [static]

Appends the given number of bytes to the given file (the file will be created if it does not exist). If "copyFrom" is not NULL, "size"-many bytes from that memory location are appended. Returns true on success.

static bool VRS::File::rename ( const std::string &  oldFilename,
const std::string &  newFilename 
) [static]

Renames the given file to the given new filename. Returns true on success.

static bool VRS::File::getFileTime ( const std::string &  filename,
FileTime  type,
time_t *  time 
) [static]

static bool VRS::File::setFileTime ( const std::string &  filename,
FileTime  type,
time_t  time 
) [static]

static bool VRS::File::copy ( const std::string &  fromFilename,
const std::string &  toFilename 
) [static]

Copies the content of the given file to the given new file. Returns true on success.

static bool VRS::File::remove ( const std::string &  filename  )  [static]

Deletes the given file. Returns true on success.

static bool VRS::File::createDir ( const std::string &  dirname  )  [static]

creates a new directory

static bool VRS::File::removeDir ( const std::string &  dirname  )  [static]

removes a directory

static bool VRS::File::removeOldFiles ( const std::string &  dirname,
const std::string &  fileExtension,
unsigned int  numberOfFilesToRemove = 20 
) [static]

removes 'numberOfFilesToRemove' old files (based on time of last data modification) does not work recursive !!! does nothing and return 'false' if directory contain less than 'numberOfFilesToRemove' files

static std::string VRS::File::temporaryDir (  )  [static]

Returns the default temporary directory temporary files will be created in. A return value of "" denotes the default temporary directory of the OS.

static void VRS::File::temporaryDir ( const std::string &  tempDir  )  [static]

Sets the default temporary directory temporary files will be created in. A value of "" denotes the default temporary directory of the OS.

static std::string VRS::File::temporaryFileName ( const std::string &  fileNamePrefix = ""  )  [static]

Creates a unique filename for temporary files.

static SO<File> VRS::File::newTemporaryFile ( const std::string &  fileNamePrefix = ""  )  [static]

Creates and returns a new temporary file.

static std::string VRS::File::fileName ( const std::string &  fullFileName  )  [static]

Returns the file name part of the given string; e.g. "readme.txt" for "C:/programs/readme.txt".

static std::string VRS::File::pathName ( const std::string &  fullFileName  )  [static]

Returns the path name part of the given string; e.g. "C:/programs/" for "C:/programs/readme.txt". Note: DOS-like path seperators "\" are converted automatically to UNIX-like path seperators "/".

static std::string VRS::File::baseName ( const std::string &  fullFileName  )  [static]

Returns the base name part of the given string; e.g. "readme" for "C:/programs/readme.txt".

static std::string VRS::File::extensionName ( const std::string &  fullFileName  )  [static]

Returns the extension name part of the given string; e.g. "txt" for "C:/programs/readme.txt". Note: the extension will be returned in lowercase letters (e.g., "me" for "C:/programs/READ.ME")!

static std::string VRS::File::replaceExtensionName ( const std::string &  fullFileName,
const std::string &  extensionName 
) [static]

Replaces the extension name part of the given file name with the given extension name.

static SO<DataResource> VRS::File::mapToMemory ( const std::string &  fileName,
bool  readOnly = true 
) [static]

Tries to map the content of the given file to memory in read only or writable mode. Returns NULL in case the mapping failed.

static std::string VRS::File::currentWorkingDir ( const int  drive = -1  )  [static]

Returns the current working directory of the application as an absolute path.

Parameters:
drive [windows only] specifies the drive for which the cwd should be returned, e.g. 0 = default, 1 = A, 2 = B, etc.

static std::string VRS::File::initialWorkingDir (  )  [static]

static std::string VRS::File::relativePath ( const std::string &  absolutePath,
const std::string &  relativeTo = File::currentWorkingDir(),
const bool  absolutePathIsDir = false 
) [static]

Given an absolute file name and a directory, returns a file name relative to that directory.

For example, if relativeTo is C: and the filename C:.txt is given as absolutePath, it will return ...txt. If it is not possible to build a relative path (e.g. relativeTo is on a different drive under windows), the absolute path is returned. Note: if absolutePath or relativeTo are relative paths, they will be made absolute regarding the current directory.

Parameters:
absolutePath the path to be converted to a relative path
relativeTo [optional] the path to which the result should be relative. Must be a directory.
absolutePathIsDir [optional, windows only] indicates if the absolutePath is a directory

static std::string VRS::File::absolutePath ( const std::string &  relativePath,
const std::string &  relativeTo = File::currentWorkingDir() 
) [static]

Resolves a relative path to an absolute one.

The path can also be an absolute path that contains a relative part, e.g. "c:\Programme\..\Windows", but in this case the referenced path must exist on disk to be resolved. Note: if relativeTo is a relative paths, it will be made absolute regarding the current directory.

Parameters:
relativePath the path to be converted to an absolute one
relativeTo [optional] the path that relativePath is relative to

VRS::File::VRS_TYPEINFO ( File  ,
SharedObj   
)


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

Generated on Mon May 21 06:00:18 2012 by Doxygen 1.5.6
© 2001-2010 Hasso-Plattner-Institut | Impressum | Contact