Main Page | Modules | Namespace List | Class Hierarchy | Class List | Namespace Members | Class Members

File Class Reference
[Operating system support]

File Class. More...

#include <file.h>

Inheritance diagram for File:

Bruker1DFile Bruker2DFile DSN6File LineBasedFile ResourceFile TrajectoryFile XYZFile GenericMolFile JCAMPFile NMRStarFile SCWRLRotamerFile DCDFile TRRFile GAMESSDatFile GAMESSLogFile HINFile KCFFile MOL2File MOLFile PDBFile SDFile List of all members.

Enums

enum  Transformation { TRANSFORMATION__EXEC = 1, TRANSFORMATION__FILTER = 2, TRANSFORMATION__URL = 3 }
 Transformation types for file. More...
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
}
 Filetype.
const String TRANSFORMATION_EXEC_PREFIX
 Prefix for filenames that are created through the execution of commands "exec:".
const String TRANSFORMATION_FILE_PREFIX
 Prefix for files (to mimick URL-like behavior) "file:".
const String TRANSFORMATION_FTP_PREFIX
 Prefix for FTP-transfers "ftp://".
const String TRANSFORMATION_HTTP_PREFIX
 Prefix for HTTP-transfer "http://".

Accessors

bool open (const String &name, File::OpenMode open_mode=std::ios::in) throw (Exception::FileNotFound)
 Open a given file.
bool reopen () throw (Exception::FileNotFound)
 Reopen the file.
bool reopen (File::OpenMode open_mode) throw (Exception::FileNotFound)
 Reopen the file with a different mode.
void close () throw ()
 Close the file.
const StringgetName () const throw ()
 Return the name of the file.
void setName (const String &name) throw ()
 Close the file and point to an other file.
const StringgetOriginalName () const throw ()
Size getSize () throw (Exception::FileNotFound)
 Return the size of the file.
File::OpenMode getOpenMode () const throw ()
 Return the open mode.
Type getType (bool trace_link) const throw (Exception::FileNotFound)
 Return the filetype.
bool copyTo (const String &destination_name, Size buffer_size=4096) throw (Exception::FileNotFound)
 Copy the file to a given destination.
bool moveTo (const String &destination_name) throw (Exception::FileNotFound)
 Move the file to a given destination.
bool remove () throw ()
 Remove the file.
bool renameTo (const String &new_path) throw (Exception::FileNotFound)
 Rename the file to a given name.
bool truncate (Size size=0) throw (Exception::FileNotFound)
 Truncate the file.
std::fstream & getFileStream ()
 Return the stream associated with this file.
Size getSize (String name) throw (Exception::FileNotFound)
 Return the size of a given file.
Type getType (String name, bool trace_link) throw (Exception::FileNotFound)
 Return the filetype of a given file.
bool copy (String source_name, String destination_name, Size buffer_size=4096) throw (Exception::FileNotFound)
 Copy a given file to a given destination.
bool move (const String &source_name, const String &destination_name) throw (Exception::FileNotFound)
 Move a given file to a given destination.
bool remove (String name) throw ()
 Remove the given file.
bool rename (String old_path, String new_path) throw (Exception::FileNotFound)
 Rename a file.
bool truncate (String path, Size size=0) throw (Exception::FileNotFound)
 Truncate a given file.
bool createTemporaryFilename (String &temporary) throw ()
 Create a temporary filename.

On-the-fly file transformation

See also:
TransformationManager


TransformationManagergetTransformationManager ()
 Mutable access the TransformationManager.
const TransformationManagergetTransformationManager () const
 Constant access to the TransformationManager.
void enableTransformation (Transformation transformation)
void disableTransformation (Transformation transformation)
bool isTransformationEnabled (Transformation transformation)
void registerTransformation (const String &pattern, const String &exec)
void unregisterTransformation (const String &pattern)

Predicates

bool operator== (const File &file) const throw ()
 Equality comparison operator.
bool operator!= (const File &file) const throw ()
 Inequality comparison operator.
bool isOpen () const throw ()
 Test if the file is opend.
bool isClosed () const throw ()
 Test if the file is closed.
bool isAccessible () const throw (Exception::FileNotFound)
 Test if the file can be accessed.
bool isCanonized () const throw (Exception::FileNotFound)
 Test if the path of the file is canonized.
bool isReadable () const throw (Exception::FileNotFound)
 Test if the file is readable.
bool isWritable () const throw (Exception::FileNotFound)
 Test if the file is writeable.
bool isExecutable () const throw (Exception::FileNotFound)
 Test if the file is executable.
bool isAccessible (String name) throw ()
 Test if a given file can be accessed.
bool isReadable (String name) throw (Exception::FileNotFound)
 Test if a given file is readable.
bool isWritable (String name) throw (Exception::FileNotFound)
 Test if a given file is writeable.
bool isExecutable (String name) throw (Exception::FileNotFound)
 Test if a given file is executable.

Public Types

Type definitions
typedef std::ios::openmode OpenMode
 File open modes.

Public Member Functions

Constructors and Destructors
 File () throw ()
 Default constructor.
 File (const String &name, OpenMode open_mode=std::ios::in) throw (Exception::FileNotFound)
 Construct new File object from the file name and open the file.
 File (const File &file) throw (Exception::FileNotFound)
 Copy constructor.
virtual ~File () throw ()
 Destructor.
virtual void clear () throw ()
 Clear the File object.
Assignment
const Fileoperator= (const File &file) throw ()
 Assignment operator.
Debugging and Diagnostics
bool isValid () const throw ()
 Test if the file is valid.

Static Public Attributes

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

Protected Attributes

String name_
String original_name_
OpenMode open_mode_
bool is_open_
bool is_temporary_

Static Protected Attributes

TransformationManager transformation_manager_
Size transformation_methods_

Detailed Description

File Class.


Member Typedef Documentation

typedef std::ios::openmode 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.


Member Enumeration Documentation

enum File::Transformation
 

Transformation types for file.

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


Constructor & Destructor Documentation

File::File  )  throw ()
 

Default constructor.

File::File const String name,
OpenMode  open_mode = std::ios::in
throw (Exception::FileNotFound)
 

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

Parameters:
name the name of the file to be opend
open_mode the openmode to be used
See also:
open

File::File const File file  )  throw (Exception::FileNotFound)
 

Copy constructor.

The file is not opend.

Parameters:
file the File object to be copied (cloned)
See also:
open

virtual File::~File  )  throw () [virtual]
 

Destructor.

The file is closed.


Member Function Documentation

virtual void File::clear  )  throw () [virtual]
 

Clear the File object.

Reimplemented in DCDFile, DSN6File, LineBasedFile, NMRStarFile, ResourceFile, TrajectoryFile, and TRRFile.

void File::close  )  throw ()
 

Close the file.

Reimplemented in ResourceFile.

bool File::copy String  source_name,
String  destination_name,
Size  buffer_size = 4096
throw (Exception::FileNotFound) [static]
 

Copy a given file to a given destination.

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

Parameters:
source_name the name of the source file
destination_name the name of the destination file
buffer_size the buffer size to use while copying
Returns:
true if copying was successfull

bool File::copyTo const String destination_name,
Size  buffer_size = 4096
throw (Exception::FileNotFound)
 

Copy the file to a given destination.

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

Parameters:
destination_name the name of the destination file
buffer_size the buffer size to use while copying
Returns:
true if copying was successfull

bool File::createTemporaryFilename String temporary  )  throw () [static]
 

Create a temporary filename.

This method creates strings, starting at _AAAAAAA.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.TMP.

Parameters:
temporary reference to the temporary filename
Returns:
bool true if a temporary filename could be found

std::fstream& File::getFileStream  ) 
 

Return the stream associated with this file.

Implemented just for convenience.

Returns:
std::fstream the stream

const String& File::getName  )  const throw ()
 

Return the name of the file.

Returns:
String the name of the file

File::OpenMode File::getOpenMode  )  const throw ()
 

Return the open mode.

Default is IN.

Returns:
int the open mode

Size File::getSize String  name  )  throw (Exception::FileNotFound) [static]
 

Return the size of a given file.

Returns:
Size the size of the file

Size File::getSize  )  throw (Exception::FileNotFound)
 

Return the size of the file.

If the file does not exist, 0 is returned.

Returns:
Size the size of the file

const TransformationManager& 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.).

TransformationManager& 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.).

Type File::getType bool  trace_link  )  const throw (Exception::FileNotFound)
 

Return the filetype.

Parameters:
trace_link true to follow links
Returns:
Type the filetype

Type File::getType String  name,
bool  trace_link
throw (Exception::FileNotFound) [static]
 

Return the filetype of a given file.

Parameters:
name the name of the file.
trace_link true to follow links
Returns:
Type the filetype

bool File::isAccessible  )  const throw (Exception::FileNotFound)
 

Test if the file can be accessed.

Returns:
bool true if the file can be accessed

bool File::isAccessible String  name  )  throw () [static]
 

Test if a given file can be accessed.

Parameters:
name the name of the file to be tested
Returns:
bool true if the file can be accessed

bool File::isCanonized  )  const throw (Exception::FileNotFound)
 

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.

bool File::isClosed  )  const throw ()
 

Test if the file is closed.

The standard constructor opens the file.

Returns:
bool true if the file is closed

bool File::isExecutable  )  const throw (Exception::FileNotFound)
 

Test if the file is executable.

Returns:
true if the file is executable

bool File::isExecutable String  name  )  throw (Exception::FileNotFound) [static]
 

Test if a given file is executable.

Parameters:
name the name of the file
Returns:
true if the file is executable

bool File::isOpen  )  const throw ()
 

Test if the file is opend.

The standard constructor opens the file.

Returns:
bool true if the file is closed

bool File::isReadable  )  const throw (Exception::FileNotFound)
 

Test if the file is readable.

Returns:
true if the file can be read

bool File::isReadable String  name  )  throw (Exception::FileNotFound) [static]
 

Test if a given file is readable.

Parameters:
name the name of the file
Returns:
true if the file can be read

bool File::isValid  )  const throw ()
 

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

Reimplemented in ResourceFile.

bool File::isWritable  )  const throw (Exception::FileNotFound)
 

Test if the file is writeable.

Returns:
true if the file is writeable

bool File::isWritable String  name  )  throw (Exception::FileNotFound) [static]
 

Test if a given file is writeable.

Parameters:
name the name of the file
Returns:
true if the file is writeable

bool File::move const String source_name,
const String destination_name
throw (Exception::FileNotFound) [static]
 

Move a given file to a given destination.

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

Parameters:
source_name the name of the source file
destination_name the name of the destination file
Returns:
true if copying was successfull

bool File::moveTo const String destination_name  )  throw (Exception::FileNotFound)
 

Move the file to a given destination.

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

Parameters:
destination_name the name of the destination file
Returns:
true if copying was successfull

bool File::open const String name,
File::OpenMode  open_mode = std::ios::in
throw (Exception::FileNotFound)
 

Open a given file.

The standard constructor uses this method.

Parameters:
name the name of the file
open_mode the open mode, default is IN
Returns:
bool true if the file could be opened

Reimplemented in DCDFile, and DSN6File.

bool File::operator!= const File file  )  const throw ()
 

Inequality comparison operator.

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

const File& File::operator= const File file  )  throw ()
 

Assignment operator.

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

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

Equality comparison operator.

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

bool File::remove  )  throw ()
 

Remove the file.

Returns:
bool true if the file could be removed

bool File::remove String  name  )  throw () [static]
 

Remove the given file.

Parameters:
name the name of the file to be removed
Returns:
bool true if the file could be removed

bool File::rename String  old_path,
String  new_path
throw (Exception::FileNotFound) [static]
 

Rename a file.

Parameters:
old_path the path and name of the file to be renamed
new_path the new path and name of the file
Returns:
bool true if the file could be renamed

bool File::renameTo const String new_path  )  throw (Exception::FileNotFound)
 

Rename the file to a given name.

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

Parameters:
new_path the new path and name of the file
Returns:
bool true if the file could be renamed

bool File::reopen File::OpenMode  open_mode  )  throw (Exception::FileNotFound)
 

Reopen the file with a different mode.

The file is closed and reopend.

Parameters:
open_mode the new mode
Returns:
bool true if the file could be reopend

bool File::reopen  )  throw (Exception::FileNotFound)
 

Reopen the file.

The file is closed and reopend.

Returns:
bool true if the file could be reopend

void File::setName const String name  )  throw ()
 

Close the file and point to an other file.

Parameters:
name the new file

bool File::truncate Size  size = 0  )  throw (Exception::FileNotFound)
 

Truncate the file.

Parameters:
size the new size of the file
Returns:
bool true if the file could be truncated

bool File::truncate String  path,
Size  size = 0
throw (Exception::FileNotFound) [static]
 

Truncate a given file.

Parameters:
path the path to the file
size the new size of the file
Returns:
bool true if the file could be truncated