BALL  1.4.79
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Classes | Protected Attributes | Static Protected Attributes | List of all members
BALL::File Class Reference

#include <BALL/SYSTEM/file.h>

Inheritance diagram for BALL::File:
BALL::AmiraMeshFile BALL::Bruker1DFile BALL::Bruker2DFile BALL::CCP4File BALL::CIFFile BALL::DSN6File BALL::LineBasedFile BALL::ParamFile BALL::ResourceFile BALL::TrajectoryFile

Classes

class  CannotWrite
 

Public Types

Type definitions
typedef std::ios::openmode OpenMode
 

Public Member Functions

Constructors and Destructors
 File ()
 
 File (const String &name, OpenMode open_mode=std::ios::in)
 
virtual ~File ()
 
virtual void clear ()
 
Debugging and Diagnostics
bool isValid () const
 

Static Public Attributes

Constants
static const OpenMode MODE_IN
 Open for input (default) More...
 
static const OpenMode MODE_OUT
 Open for output. More...
 
static const OpenMode MODE_APP
 Append. Seek to end before each write operation. More...
 
static const OpenMode MODE_BINARY
 Binary mode. More...
 
static const OpenMode MODE_ATE
 Seek to end directly after opening. More...
 
static const OpenMode MODE_TRUNC
 Truncate an existing file. More...
 

Protected Attributes

String name_
 
String original_name_
 
OpenMode open_mode_
 
bool is_open_
 
bool is_temporary_
 

Static Protected Attributes

static HashSet< Stringcreated_temp_filenames_
 
static TransformationManager transformation_manager_
 
static Size transformation_methods_
 

Enums

enum  Transformation { TRANSFORMATION__EXEC = 1, TRANSFORMATION__FILTER = 2, TRANSFORMATION__URL = 3 }
 
enum  Type {
  TYPE__UNKNOWN = 0, TYPE__DIRECTORY = 1, TYPE__CHAR_SPECIAL_FILE = 2, TYPE__BLOCK_SPECIAL_FILE = 3,
  TYPE__REGULAR_FILE = 4, TYPE__SYMBOLIC_LINK = 5, TYPE__SOCKET = 6, TYPE__FIFO_SPECIAL_FILE = 7
}
 
static const String TRANSFORMATION_EXEC_PREFIX
 Prefix for filenames that are created through the execution of commands "exec:". More...
 
static const String TRANSFORMATION_FILE_PREFIX
 Prefix for files (to mimick URL-like behavior) "file:". More...
 
static const String TRANSFORMATION_FTP_PREFIX
 Prefix for FTP-transfers "ftp://". More...
 
static const String TRANSFORMATION_HTTP_PREFIX
 Prefix for HTTP-transfer "http://". More...
 

Accessors

Assignment operator. Assign the filename from file . The file is not opend.

bool open (const String &name, File::OpenMode open_mode=std::ios::in)
 
bool reopen ()
 
bool reopen (File::OpenMode open_mode)
 
void close ()
 
const StringgetName () const
 
void setName (const String &name)
 
const StringgetOriginalName () const
 
Size getSize ()
 
File::OpenMode getOpenMode () const
 
Type getType (bool trace_link) const
 
bool copyTo (const String &destination_name, Size buffer_size=4096)
 
bool moveTo (const String &destination_name)
 
bool remove ()
 
bool renameTo (const String &new_path)
 
bool truncate (Size size=0)
 
std::fstream & getFileStream ()
 
static Size getSize (String name)
 
static Type getType (String name, bool trace_link)
 
static bool copy (String source_name, String destination_name, Size buffer_size=4096)
 
static bool move (const String &source_name, const String &destination_name)
 
static bool remove (String name)
 
static bool rename (String old_path, String new_path)
 
static bool truncate (String path, Size size=0)
 
static bool createTemporaryFilename (String &temporary, const String &suffix=".TMP")
 

On-the-fly file transformation

See also
TransformationManager
TransformationManagergetTransformationManager ()
 
const TransformationManagergetTransformationManager () const
 
static void enableTransformation (Transformation transformation)
 
static void disableTransformation (Transformation transformation)
 
static bool isTransformationEnabled (Transformation transformation)
 
static void registerTransformation (const String &pattern, const String &exec)
 
static void unregisterTransformation (const String &pattern)
 

Predicates

bool operator== (const File &file) const
 
bool operator!= (const File &file) const
 
bool isOpen () const
 
bool isClosed () const
 
bool isAccessible () const
 
bool isCanonized () const
 
bool isReadable () const
 
bool isWritable () const
 
bool isExecutable () const
 
static bool isAccessible (String name)
 
static bool isReadable (String name)
 
static bool isWritable (String name)
 
static bool isExecutable (String name)
 

Detailed Description

File Class.

Definition at line 137 of file file.h.

Member Typedef Documentation

typedef std::ios::openmode BALL::File::OpenMode

File open modes. This type is used to describe the standard openmodes for files as described in Section 27.4.2.1.4 of the ANSI C++ standard.

Definition at line 168 of file file.h.

Member Enumeration Documentation

Transformation types for file. This enum defines some possible types for on-the-fly file transformation.

Enumerator
TRANSFORMATION__EXEC 
TRANSFORMATION__FILTER 
TRANSFORMATION__URL 

Definition at line 201 of file file.h.

Filetype

Enumerator
TYPE__UNKNOWN 
TYPE__DIRECTORY 
TYPE__CHAR_SPECIAL_FILE 
TYPE__BLOCK_SPECIAL_FILE 
TYPE__REGULAR_FILE 
TYPE__SYMBOLIC_LINK 
TYPE__SOCKET 
TYPE__FIFO_SPECIAL_FILE 

Definition at line 213 of file file.h.

Constructor & Destructor Documentation

BALL::File::File ( )

Default constructor.

BALL::File::File ( const String name,
OpenMode  open_mode = std::ios::in 
)

Construct new File object from the file name and open the file.

Parameters
namethe name of the file to be opened
open_modethe openmode to be used
See also
open
Exceptions
Exception::FileNotFoundif the file should be read but could not be found
virtual BALL::File::~File ( )
virtual

Destructor. The file is closed.

Member Function Documentation

virtual void BALL::File::clear ( )
virtual
void BALL::File::close ( )

Close the file.

static bool BALL::File::copy ( String  source_name,
String  destination_name,
Size  buffer_size = 4096 
)
static

Copy a given file to a given destination. If a file with the destination name exists already, nothing happens.

Parameters
source_namethe name of the source file
destination_namethe name of the destination file
buffer_sizethe buffer size to use while copying
Returns
true if copying was successfull
Exceptions
Exception::FileNotFoundif the file could not be found
bool BALL::File::copyTo ( const String destination_name,
Size  buffer_size = 4096 
)

Copy the file to a given destination. If a file with the destination name exists already, nothing happens.

Parameters
destination_namethe name of the destination file
buffer_sizethe buffer size to use while copying
Returns
true if copying was successfull
Exceptions
Exception::FileNotFoundif the file could not be found
static bool BALL::File::createTemporaryFilename ( String temporary,
const String suffix = ".TMP" 
)
static

Create a temporary filename. This method creates strings, starting at _AAAAAAA, adds the suffix /suffix/ which defaults to .TMP and tries if a file with this name exists. If not, the string is returned. If a file with this name exists, it continues to create names up to _ZZZZZZZ.

Parameters
temporaryreference to the temporary filename
Returns
bool true if a temporary filename could be found
static void BALL::File::disableTransformation ( Transformation  transformation)
static
static void BALL::File::enableTransformation ( Transformation  transformation)
static
std::fstream& BALL::File::getFileStream ( )

Return the stream associated with this file. Implemented just for convenience.

Returns
std::fstream the stream
const String& BALL::File::getName ( ) const

Return the name of the file.

Returns
String the name of the file
File::OpenMode BALL::File::getOpenMode ( ) const

Return the open mode. Default is IN.

Returns
int the open mode
const String& BALL::File::getOriginalName ( ) const
Size BALL::File::getSize ( )

Return the size of the file. If the file does not exist, 0 is returned.

Returns
Size the size of the file
Exceptions
Exception::FileNotFoundif the file could not be found
static Size BALL::File::getSize ( String  name)
static

Return the size of a given file.

Returns
Size the size of the file
Exceptions
Exception::FileNotFoundif the file could not be found
TransformationManager& BALL::File::getTransformationManager ( )

Mutable access the TransformationManager. File defines a static instance of TransformationManager to handle on-the-fly conversions of files (e.g. compression, charset conversion, etc.).

const TransformationManager& BALL::File::getTransformationManager ( ) const

Constant access to the TransformationManager. File defines a static instance of TransformationManager to handle on-the-fly conversions of files (e.g. compression, charset conversion, etc.).

static Type BALL::File::getType ( String  name,
bool  trace_link 
)
static

Return the filetype of a given file.

Parameters
namethe name of the file.
trace_linktrue to follow links
Returns
Type the filetype
Exceptions
Exception::FileNotFoundif the file could not be found
Type BALL::File::getType ( bool  trace_link) const

Return the filetype.

Parameters
trace_linktrue to follow links
Returns
Type the filetype
Exceptions
Exception::FileNotFoundif the file could not be found
static bool BALL::File::isAccessible ( String  name)
static

Test if a given file can be accessed.

Parameters
namethe name of the file to be tested
Returns
bool true if the file can be accessed
bool BALL::File::isAccessible ( ) const

Test if the file can be accessed.

Returns
bool true if the file can be accessed
Exceptions
Exception::FileNotfoundif the file could not be found
bool BALL::File::isCanonized ( ) const

Test if the path of the file is canonized. The path is compared before and after call of FileSystem::canonizePath(canonized_name).

See also
FileSystem::canonizePath
Returns
bool true if the path is canonized.
Exceptions
Exception::FileNotfoundif the file could not be found
bool BALL::File::isClosed ( ) const

Test if the file is closed. The standard constructor opens the file.

Returns
bool true if the file is closed
static bool BALL::File::isExecutable ( String  name)
static

Test if a given file is executable.

Parameters
namethe name of the file
Returns
true if the file is executable
Exceptions
Exception::FileNotfoundif the file could not be found
bool BALL::File::isExecutable ( ) const

Test if the file is executable.

Returns
true if the file is executable
Exceptions
Exception::FileNotfoundif the file could not be found
bool BALL::File::isOpen ( ) const

Test if the file is opend. The standard constructor opens the file.

Returns
bool true if the file is closed
static bool BALL::File::isReadable ( String  name)
static

Test if a given file is readable.

Parameters
namethe name of the file
Returns
true if the file can be read
Exceptions
Exception::FileNotfoundif the file could not be found
bool BALL::File::isReadable ( ) const

Test if the file is readable.

Returns
true if the file can be read
Exceptions
Exception::FileNotfoundif the file could not be found
static bool BALL::File::isTransformationEnabled ( Transformation  transformation)
static
bool BALL::File::isValid ( ) const

Test if the file is valid. If the filename was not set, false is returned. This function uses std::fstream::good().

Returns
bool true if the file is valid
static bool BALL::File::isWritable ( String  name)
static

Test if a given file is writeable.

Parameters
namethe name of the file
Returns
true if the file is writeable
Exceptions
Exception::FileNotfoundif the file could not be found
bool BALL::File::isWritable ( ) const

Test if the file is writeable.

Returns
true if the file is writeable
Exceptions
Exception::FileNotfoundif the file could not be found
static bool BALL::File::move ( const String source_name,
const String destination_name 
)
static

Move a given file to a given destination. If a file with the destination name exists already, nothing happens.

Parameters
source_namethe name of the source file
destination_namethe name of the destination file
Returns
true if copying was successfull
Exceptions
Exception::FileNotFoundif the file could not be found
bool BALL::File::moveTo ( const String destination_name)

Move the file to a given destination. If a file with the destination name exists already, nothing happens.

Parameters
destination_namethe name of the destination file
Returns
true if copying was successfull
Exceptions
Exception::FileNotFoundif the file could not be found
bool BALL::File::open ( const String name,
File::OpenMode  open_mode = std::ios::in 
)

Open a given file. The standard constructor uses this method.

Parameters
namethe name of the file
open_modethe open mode, default is IN
Returns
bool true if the file could be opened
Exceptions
Exception::FileNotFoundif the file should be read but could not be found
bool BALL::File::operator!= ( const File file) const

Inequality comparison operator. Two File objects are inequal if they point not to the same canonized filename.

bool BALL::File::operator== ( const File file) const

Equality comparison operator. Two File objects are equal if they point to the same canonized filename.

static void BALL::File::registerTransformation ( const String pattern,
const String exec 
)
static
static bool BALL::File::remove ( String  name)
static

Remove the given file.

Parameters
namethe name of the file to be removed
Returns
bool true if the file could be removed
bool BALL::File::remove ( )

Remove the file.

Returns
bool true if the file could be removed
static bool BALL::File::rename ( String  old_path,
String  new_path 
)
static

Rename a file.

Parameters
old_paththe path and name of the file to be renamed
new_paththe new path and name of the file
Returns
bool true if the file could be renamed
Exceptions
Exception::FileNotFoundif the file could not be found
bool BALL::File::renameTo ( const String new_path)

Rename the file to a given name. If a file with the destination name exists already, nothing happens.

Parameters
new_paththe new path and name of the file
Returns
bool true if the file could be renamed
Exceptions
Exception::FileNotFoundif the file could not be found
bool BALL::File::reopen ( )

Reopen the file. The file is closed and reopend.

Returns
bool true if the file could be reopened
Exceptions
Exception::FileNotFoundif the file should be read but could not be found
bool BALL::File::reopen ( File::OpenMode  open_mode)

Reopen the file with a different mode. The file is closed and reopend.

Parameters
open_modethe new mode
Returns
bool true if the file could be reopend
Exceptions
Exception::FileNotFoundif the file should be read but could not be found
void BALL::File::setName ( const String name)

Close the file and point to an other file.

Parameters
namethe new file
static bool BALL::File::truncate ( String  path,
Size  size = 0 
)
static

Truncate a given file.

Parameters
paththe path to the file
sizethe new size of the file
Returns
bool true if the file could be truncated
Exceptions
Exception::FileNotFoundif the file could not be found
bool BALL::File::truncate ( Size  size = 0)

Truncate the file.

Parameters
sizethe new size of the file
Returns
bool true if the file could be truncated
Exceptions
Exception::FileNotFoundif the file could not be found
static void BALL::File::unregisterTransformation ( const String pattern)
static

Member Data Documentation

HashSet<String> BALL::File::created_temp_filenames_
staticprotected

Definition at line 609 of file file.h.

bool BALL::File::is_open_
protected

Definition at line 607 of file file.h.

bool BALL::File::is_temporary_
protected

Definition at line 608 of file file.h.

const OpenMode BALL::File::MODE_APP
static

Append. Seek to end before each write operation.

Definition at line 182 of file file.h.

const OpenMode BALL::File::MODE_ATE
static

Seek to end directly after opening.

Definition at line 188 of file file.h.

const OpenMode BALL::File::MODE_BINARY
static

Binary mode.

Definition at line 185 of file file.h.

const OpenMode BALL::File::MODE_IN
static

Open for input (default)

Definition at line 176 of file file.h.

const OpenMode BALL::File::MODE_OUT
static

Open for output.

Definition at line 179 of file file.h.

const OpenMode BALL::File::MODE_TRUNC
static

Truncate an existing file.

Definition at line 191 of file file.h.

String BALL::File::name_
protected

Definition at line 604 of file file.h.

OpenMode BALL::File::open_mode_
protected

Definition at line 606 of file file.h.

String BALL::File::original_name_
protected

Definition at line 605 of file file.h.

const String BALL::File::TRANSFORMATION_EXEC_PREFIX
static

Prefix for filenames that are created through the execution of commands "exec:".

Definition at line 234 of file file.h.

const String BALL::File::TRANSFORMATION_FILE_PREFIX
static

Prefix for files (to mimick URL-like behavior) "file:".

Definition at line 237 of file file.h.

const String BALL::File::TRANSFORMATION_FTP_PREFIX
static

Prefix for FTP-transfers "ftp://".

Definition at line 240 of file file.h.

const String BALL::File::TRANSFORMATION_HTTP_PREFIX
static

Prefix for HTTP-transfer "http://".

Definition at line 243 of file file.h.

TransformationManager BALL::File::transformation_manager_
staticprotected

Definition at line 611 of file file.h.

Size BALL::File::transformation_methods_
staticprotected

Definition at line 612 of file file.h.