BALL  1.5.0
List of all members
BALL::LineBasedFile Class Reference

#include <BALL/FORMAT/lineBasedFile.h>

Inheritance diagram for BALL::LineBasedFile:
BALL::File BALL::GenericMolFile BALL::HMOFile BALL::JCAMPFile BALL::SCWRLRotamerFile BALL::AntechamberFile BALL::DockResultFile BALL::GAMESSDatFile BALL::GAMESSLogFile BALL::HINFile BALL::KCFFile BALL::MOL2File BALL::MOLFile BALL::MOPACInputFile BALL::MOPACOutputFile BALL::PDBFile BALL::XYZFile

Public Member Functions

Constructors and Destructors
 LineBasedFile ()
 Default constructor. More...
 
 LineBasedFile (const String &filename, File::OpenMode open_mode=std::ios::in, bool trim_whitespaces=false)
 
void clear ()
 
Equality operators
bool operator== (const LineBasedFile &f)
 
bool operator!= (const LineBasedFile &f)
 
Assignment
const LineBasedFileoperator= (const LineBasedFile &file)
 
Accessors
Position getLineNumber () const
 Get the last line number in the file. More...
 
const StringgetLine () const
 Return the current line. More...
 
StringgetLine ()
 Return the current line. More...
 
- Public Member Functions inherited from BALL::File
 File ()
 
 File (const String &name, OpenMode open_mode=std::ios::in)
 
virtual ~File ()
 
bool isValid () const
 
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 ()
 
TransformationManagergetTransformationManager ()
 
const TransformationManagergetTransformationManager () const
 
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
 

Help-Methods for File Acces

String line_
 buffer for the line in use More...
 
Position line_number_
 line number in the file More...
 
bool trim_whitespaces_
 
vector< char > col_buffer_
 buffer for column parsing More...
 
bool readLine ()
 
bool skipLines (Size number=1)
 
bool search (const String &text, bool return_to_start=false)
 
bool search (const String &text, const String &stop, bool return_to_start=false)
 
bool gotoLine (Position line_number)
 
void rewind ()
 
void test (const char *file, int line, bool condition, const String &msg) const
 
String getField (Index pos=0, const String &quotes="", const String &delimiters=String::CHARACTER_CLASS__WHITESPACE) const
 
bool startsWith (const String &text) const
 Test if the current line starts with text. More...
 
bool has (const String &text) const
 Return true if the current line contains text. More...
 
Index switchString (const std::vector< String > &data) const
 
bool parseColumnFormat (const char *format, Position index, Size length, void *arg)
 
void enableTrimWhitespaces (bool state)
 Set wheter leading and trailing whitespaces in lines shall be removed. More...
 
bool trimWhiteSpacesEnabled () const
 

Additional Inherited Members

- Public Types inherited from BALL::File
typedef std::ios::openmode OpenMode
 
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 Public Member Functions inherited from BALL::File
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")
 
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)
 
static bool isAccessible (String name)
 
static bool isReadable (String name)
 
static bool isWritable (String name)
 
static bool isExecutable (String name)
 
- Static Public Attributes inherited from BALL::File
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...
 
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...
 
- Protected Attributes inherited from BALL::File
String name_
 
String original_name_
 
OpenMode open_mode_
 
bool is_open_
 
bool is_temporary_
 
- Static Protected Attributes inherited from BALL::File
static HashSet< Stringcreated_temp_filenames_
 
static TransformationManager transformation_manager_
 
static Size transformation_methods_
 

Detailed Description

A class for the convenient parsing of line-based file formats.

Definition at line 20 of file lineBasedFile.h.

Constructor & Destructor Documentation

◆ LineBasedFile() [1/2]

BALL::LineBasedFile::LineBasedFile ( )

Default constructor.

◆ LineBasedFile() [2/2]

BALL::LineBasedFile::LineBasedFile ( const String filename,
File::OpenMode  open_mode = std::ios::in,
bool  trim_whitespaces = false 
)

Detailed constuctor. Open the given file.

Parameters
trim_whitespaces- sets wheter leading and trailing whitespaces shall be removed while reading the file
Exceptions
Exception::FileNotFoundif the file could not be opened

Member Function Documentation

◆ clear()

void BALL::LineBasedFile::clear ( )
virtual

Clear method.

Reimplemented from BALL::File.

Reimplemented in BALL::PDBFile, and BALL::MOPACOutputFile.

◆ enableTrimWhitespaces()

void BALL::LineBasedFile::enableTrimWhitespaces ( bool  state)

Set wheter leading and trailing whitespaces in lines shall be removed.

◆ getField()

String BALL::LineBasedFile::getField ( Index  pos = 0,
const String quotes = "",
const String delimiters = String::CHARACTER_CLASS__WHITESPACE 
) const

Function to get a field surrounded by delimiter

See also
String::getField
String::getFieldQuoted

◆ getLine() [1/2]

String& BALL::LineBasedFile::getLine ( )

Return the current line.

◆ getLine() [2/2]

const String& BALL::LineBasedFile::getLine ( ) const

Return the current line.

◆ getLineNumber()

Position BALL::LineBasedFile::getLineNumber ( ) const

Get the last line number in the file.

◆ gotoLine()

bool BALL::LineBasedFile::gotoLine ( Position  line_number)

Go to a given line.

Returns
false if EOF occurs
Exceptions
Exception::ParseErrorif a syntax error was encountered

◆ has()

bool BALL::LineBasedFile::has ( const String text) const

Return true if the current line contains text.

◆ operator!=()

bool BALL::LineBasedFile::operator!= ( const LineBasedFile f)

Inequality operator

◆ operator=()

const LineBasedFile& BALL::LineBasedFile::operator= ( const LineBasedFile file)

Assignment operator. The file is opened and the same position in it is seeked.

Exceptions
Exception::FileNotFoundif the file could not be opened

◆ operator==()

bool BALL::LineBasedFile::operator== ( const LineBasedFile f)

Equality operator

◆ parseColumnFormat()

bool BALL::LineBasedFile::parseColumnFormat ( const char *  format,
Position  index,
Size  length,
void *  arg 
)

Parse column based formats. Copy the subsection of the current line defined by index and length into a buffer try to parse it using sscanf. The result is stored in arg (use with caution: no type checking!).

◆ readLine()

bool BALL::LineBasedFile::readLine ( )

Reads a line and counts the line number.

Returns
true if a line could be read, false if End Of File.
Exceptions
Exception::ParseErrorif a syntax error was encountered

◆ rewind()

void BALL::LineBasedFile::rewind ( )

Rewind file to start

Exceptions
Exception::ParseErrorif a syntax error was encountered

◆ search() [1/2]

bool BALL::LineBasedFile::search ( const String text,
bool  return_to_start = false 
)

Search for a line starting with a given string. Search starts at the current line and ends at the end of the file (no wrap around).

Parameters
return_to_startif set to true, the current line is reset to its value prior to the invocation
Returns
true if line could be found
Exceptions
Exception::ParseErrorif a syntax error was encountered

◆ search() [2/2]

bool BALL::LineBasedFile::search ( const String text,
const String stop,
bool  return_to_start = false 
)

◆ skipLines()

bool BALL::LineBasedFile::skipLines ( Size  number = 1)

Skip a given number of lines.

Returns
false, if EOF occurs.
Exceptions
Exception::ParseErrorif a syntax error was encountered

◆ startsWith()

bool BALL::LineBasedFile::startsWith ( const String text) const

Test if the current line starts with text.

◆ switchString()

Index BALL::LineBasedFile::switchString ( const std::vector< String > &  data) const

Switch method of the current line. Return the position of the current line in data or -1 if it does not exist.

◆ test()

void BALL::LineBasedFile::test ( const char *  file,
int  line,
bool  condition,
const String msg 
) const

Test for a condition. Throw an exception if a given condition is not met. \begin{verbatim} abort(FILE, LINE, shift_reference->elements.size() > 0, "no data for shift references found"); \end{verbatim}

Parameters
fileshould be used for FILE
lineshould be used for LINE
conditionto be tested
msgthis string is used as message in the exception
Exceptions
Exception::ParseErrorif condition is not fulfilled

◆ trimWhiteSpacesEnabled()

bool BALL::LineBasedFile::trimWhiteSpacesEnabled ( ) const

Member Data Documentation

◆ col_buffer_

vector<char> BALL::LineBasedFile::col_buffer_
protected

buffer for column parsing

Definition at line 181 of file lineBasedFile.h.

◆ line_

String BALL::LineBasedFile::line_
protected

buffer for the line in use

Definition at line 173 of file lineBasedFile.h.

◆ line_number_

Position BALL::LineBasedFile::line_number_
protected

line number in the file

Definition at line 176 of file lineBasedFile.h.

◆ trim_whitespaces_

bool BALL::LineBasedFile::trim_whitespaces_
protected

Definition at line 178 of file lineBasedFile.h.