#include <BALL/SYSTEM/file.h>
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) throw (Exception::FileNotFound) | |
File (const File &file) throw (Exception::FileNotFound) | |
virtual | ~File () |
virtual void | clear () |
Assignment | |
const File & | operator= (const File &file) |
Debugging and Diagnostics | |
bool | isValid () const |
Static Public Attributes | |
Constants | |
static const OpenMode | MODE_IN |
Open for input (default). | |
static const OpenMode | MODE_OUT |
Open for output. | |
static const OpenMode | MODE_APP |
Append. Seek to end before each write operation. | |
static const OpenMode | MODE_BINARY |
Binary mode. | |
static const OpenMode | MODE_ATE |
Seek to end directly after opening. | |
static 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 | |
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:". | |
static const String | TRANSFORMATION_FILE_PREFIX |
Prefix for files (to mimick URL-like behavior) "file:". | |
static const String | TRANSFORMATION_FTP_PREFIX |
Prefix for FTP-transfers "ftp://". | |
static 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) |
bool | reopen () throw (Exception::FileNotFound) |
bool | reopen (File::OpenMode open_mode) throw (Exception::FileNotFound) |
void | close () |
const String & | getName () const |
void | setName (const String &name) |
const String & | getOriginalName () const |
Size | getSize () throw (Exception::FileNotFound) |
File::OpenMode | getOpenMode () const |
Type | getType (bool trace_link) const throw (Exception::FileNotFound) |
bool | copyTo (const String &destination_name, Size buffer_size=4096) throw (Exception::FileNotFound) |
bool | moveTo (const String &destination_name) throw (Exception::FileNotFound) |
bool | remove () |
bool | renameTo (const String &new_path) throw (Exception::FileNotFound) |
bool | truncate (Size size=0) throw (Exception::FileNotFound) |
std::fstream & | getFileStream () |
static Size | getSize (String name) throw (Exception::FileNotFound) |
static Type | getType (String name, bool trace_link) throw (Exception::FileNotFound) |
static bool | copy (String source_name, String destination_name, Size buffer_size=4096) throw (Exception::FileNotFound) |
static bool | move (const String &source_name, const String &destination_name) throw (Exception::FileNotFound) |
static bool | remove (String name) |
static bool | rename (String old_path, String new_path) throw (Exception::FileNotFound) |
static bool | truncate (String path, Size size=0) throw (Exception::FileNotFound) |
static bool | createTemporaryFilename (String &temporary) |
On-the-fly file transformation | |
| |
TransformationManager & | getTransformationManager () |
const TransformationManager & | getTransformationManager () 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 throw (Exception::FileNotFound) |
bool | isCanonized () const throw (Exception::FileNotFound) |
bool | isReadable () const throw (Exception::FileNotFound) |
bool | isWritable () const throw (Exception::FileNotFound) |
bool | isExecutable () const throw (Exception::FileNotFound) |
static bool | isAccessible (String name) |
static bool | isReadable (String name) throw (Exception::FileNotFound) |
static bool | isWritable (String name) throw (Exception::FileNotFound) |
static bool | isExecutable (String name) throw (Exception::FileNotFound) |
File Class.
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.
enum BALL::File::Type |
BALL::File::File | ( | ) |
Default constructor.
BALL::File::File | ( | const String & | name, | |
OpenMode | open_mode = std::ios::in | |||
) | throw (Exception::FileNotFound) |
BALL::File::File | ( | const File & | file | ) | throw (Exception::FileNotFound) |
virtual BALL::File::~File | ( | ) | [virtual] |
Destructor. The file is closed.
virtual void BALL::File::clear | ( | ) | [virtual] |
Clear the File object.
Reimplemented in BALL::DCDFile, BALL::DSN6File, BALL::LineBasedFile, BALL::NMRStarFile, BALL::PDBFile, BALL::ResourceFile, BALL::TrajectoryFile, and BALL::TRRFile.
void BALL::File::close | ( | ) |
Close the file.
Reimplemented in BALL::ResourceFile.
Referenced by BALL::TRegularData3D< ValueType >::binaryRead(), BALL::TRegularData2D< ValueType >::binaryRead(), BALL::TRegularData1D< ValueType >::binaryRead(), BALL::TRegularData3D< ValueType >::binaryWrite(), and BALL::TRegularData1D< ValueType >::binaryWrite().
static bool BALL::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.
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 |
bool BALL::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.
destination_name | the name of the destination file | |
buffer_size | the buffer size to use while copying |
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.
temporary | reference to the temporary filename |
Referenced by main().
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.
const String& BALL::File::getName | ( | ) | const |
Return the name of the file.
File::OpenMode BALL::File::getOpenMode | ( | ) | const |
Return the open mode. Default is IN.
const String& BALL::File::getOriginalName | ( | ) | const |
static Size BALL::File::getSize | ( | String | name | ) | throw (Exception::FileNotFound) [static] |
Return the size of a given file.
Size BALL::File::getSize | ( | ) | throw (Exception::FileNotFound) |
Return the size of the file. If the file does not exist, 0 is returned.
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.).
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.).
Type BALL::File::getType | ( | bool | trace_link | ) | const throw (Exception::FileNotFound) |
Return the filetype.
trace_link | true to follow links |
static Type BALL::File::getType | ( | String | name, | |
bool | trace_link | |||
) | throw (Exception::FileNotFound) [static] |
Return the filetype of a given file.
name | the name of the file. | |
trace_link | true to follow links |
bool BALL::File::isAccessible | ( | ) | const throw (Exception::FileNotFound) |
Test if the file can be accessed.
Test if a given file can be accessed.
name | the name of the file to be tested |
bool BALL::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).
bool BALL::File::isClosed | ( | ) | const |
Test if the file is closed. The standard constructor opens the file.
bool BALL::File::isExecutable | ( | ) | const throw (Exception::FileNotFound) |
Test if the file is executable.
static bool BALL::File::isExecutable | ( | String | name | ) | throw (Exception::FileNotFound) [static] |
Test if a given file is executable.
name | the name of the file |
bool BALL::File::isOpen | ( | ) | const |
Test if the file is opend. The standard constructor opens the file.
bool BALL::File::isReadable | ( | ) | const throw (Exception::FileNotFound) |
Test if the file is readable.
static bool BALL::File::isReadable | ( | String | name | ) | throw (Exception::FileNotFound) [static] |
Test if a given file is readable.
name | the name of the file |
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().
Reimplemented in BALL::ResourceFile.
Referenced by BALL::TRegularData3D< ValueType >::binaryRead(), BALL::TRegularData2D< ValueType >::binaryRead(), BALL::TRegularData1D< ValueType >::binaryRead(), BALL::TRegularData3D< ValueType >::binaryWrite(), and BALL::TRegularData1D< ValueType >::binaryWrite().
bool BALL::File::isWritable | ( | ) | const throw (Exception::FileNotFound) |
Test if the file is writeable.
static bool BALL::File::isWritable | ( | String | name | ) | throw (Exception::FileNotFound) [static] |
Test if a given file is writeable.
name | the name of the file |
static bool BALL::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.
source_name | the name of the source file | |
destination_name | the name of the destination file |
bool BALL::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.
destination_name | the name of the destination file |
bool BALL::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.
name | the name of the file | |
open_mode | the open mode, default is IN |
Reimplemented in BALL::DCDFile, and BALL::DSN6File.
Inequality comparison operator. Two File objects are inequal if they point not to the same canonized filename.
Assignment operator. Assign the filename from file . The file is not opend.
Referenced by BALL::XYZFile::operator=().
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] |
bool BALL::File::remove | ( | ) |
Remove the file.
Remove the given file.
name | the name of the file to be removed |
Referenced by main().
static bool BALL::File::rename | ( | String | old_path, | |
String | new_path | |||
) | throw (Exception::FileNotFound) [static] |
Rename a file.
old_path | the path and name of the file to be renamed | |
new_path | the new path and name of the file |
bool BALL::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.
new_path | the new path and name of the file |
bool BALL::File::reopen | ( | File::OpenMode | open_mode | ) | throw (Exception::FileNotFound) |
Reopen the file with a different mode. The file is closed and reopend.
open_mode | the new mode |
bool BALL::File::reopen | ( | ) | throw (Exception::FileNotFound) |
Reopen the file. The file is closed and reopend.
void BALL::File::setName | ( | const String & | name | ) |
Close the file and point to an other file.
name | the new file |
bool BALL::File::truncate | ( | Size | size = 0 |
) | throw (Exception::FileNotFound) |
Truncate the file.
size | the new size of the file |
static bool BALL::File::truncate | ( | String | path, | |
Size | size = 0 | |||
) | throw (Exception::FileNotFound) [static] |
Truncate a given file.
path | the path to the file | |
size | the new size of the file |
static void BALL::File::unregisterTransformation | ( | const String & | pattern | ) | [static] |
bool BALL::File::is_open_ [protected] |
bool BALL::File::is_temporary_ [protected] |
const OpenMode BALL::File::MODE_APP [static] |
Append. Seek to end before each write operation.
const OpenMode BALL::File::MODE_ATE [static] |
Seek to end directly after opening.
const OpenMode BALL::File::MODE_BINARY [static] |
Binary mode.
const OpenMode BALL::File::MODE_IN [static] |
Open for input (default).
const OpenMode BALL::File::MODE_OUT [static] |
Open for output.
const OpenMode BALL::File::MODE_TRUNC [static] |
Truncate an existing file.
String BALL::File::name_ [protected] |
Reimplemented in BALL::PDBFile.
OpenMode BALL::File::open_mode_ [protected] |
String BALL::File::original_name_ [protected] |
const String BALL::File::TRANSFORMATION_EXEC_PREFIX [static] |
Prefix for filenames that are created through the execution of commands "exec:".
const String BALL::File::TRANSFORMATION_FILE_PREFIX [static] |
Prefix for files (to mimick URL-like behavior) "file:".
const String BALL::File::TRANSFORMATION_FTP_PREFIX [static] |
Prefix for FTP-transfers "ftp://".
const String BALL::File::TRANSFORMATION_HTTP_PREFIX [static] |
Prefix for HTTP-transfer "http://".
TransformationManager BALL::File::transformation_manager_ [static, protected] |
Size BALL::File::transformation_methods_ [static, protected] |