Classes | Public Member Functions | Static Public Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
PLMD::IFile Class Reference


Class for input files More...

#include <IFile.h>

Inheritance diagram for PLMD::IFile:
Inheritance graph
[legend]

Classes

class  Field
 

Public Member Functions

 IFile ()
 Constructor. More...
 
 ~IFile ()
 Destructor. More...
 
IFileopen (const std::string &name)
 Opens the file. More...
 
IFilescanFieldList (std::vector< std::string > &)
 Gets the list of all fields. More...
 
IFilescanField (const std::string &, double &)
 Read a double field. More...
 
IFilescanField (const std::string &, int &)
 Read a int field. More...
 
IFilescanField (const std::string &, std::string &)
 Read a string field. More...
 
IFilescanField ()
 
Ends a field-formatted line. More...
 
IFilegetline (std::string &)
 Get a full line as a string. More...
 
void reset (bool)
 Reset end of file. More...
 
bool FieldExist (const std::string &s)
 Check if a field exist. More...
 
IFilescanField (Value *val)
 Read in a value. More...
 
void allowIgnoredFields ()
 Allow some of the fields in the input to be ignored. More...
 
void allowNoEOL ()
 Allow files without EOL at the end. More...
 
FileBaselink (FILE *)
 Link to an already open filed. More...
 
FileBaselink (PlumedMain &)
 Link to a PlumedMain object Automatically links also the corresponding Communicator. More...
 
FileBaselink (Communicator &)
 Link to a Communicator object. More...
 
FileBaselink (Action &)
 Link to an Action object. More...
 
FileBaseenforceSuffix (const std::string &suffix)
 Enforce suffix. More...
 
virtual FileBaseflush ()
 Flushes the file to disk. More...
 
void close ()
 Closes the file Should be used only for explicitely opened files. More...
 
 operator bool () const
 Check for error/eof. More...
 
void setHeavyFlush ()
 Set heavyFlush flag. More...
 
bool FileExist (const std::string &path)
 Check if the file exists. More...
 
bool isOpen ()
 Check if a file is open. More...
 
std::string getPath () const
 Retrieve the path. More...
 
std::string getMode () const
 Retrieve the mode. More...
 
std::string getSuffix () const
 Get the file suffix. More...
 

Static Public Member Functions

static std::string appendSuffix (const std::string &path, const std::string &suffix)
 Append suffix. More...
 
static void test ()
 Runs a small testcase. More...
 

Protected Attributes

FILE * fp
 file pointer More...
 
void * gzfp
 zip file pointer. More...
 
Communicatorcomm
 communicator. NULL if not set More...
 
PlumedMainplumed
 pointer to main plumed object. NULL if not linked More...
 
Actionaction
 pointer to corresponding action. NULL if not linked More...
 
bool cloned
 Control closing on destructor. More...
 
bool eof
 Set to true when end of file is encountered. More...
 
bool err
 Set to true when error is encountered. More...
 
std::string path
 path of the opened file More...
 
std::string mode
 mode of the opened file More...
 
bool heavyFlush
 Set to true if you want flush to be heavy (close/reopen) More...
 

Private Member Functions

size_t llread (char *, size_t)
 Low-level read. More...
 
IFileadvanceField ()
 Advance to next field (= read one line) More...
 
unsigned findField (const std::string &name) const
 Find field index by name. More...
 

Private Attributes

std::vector< Fieldfields
 All the defined fields. More...
 
bool inMiddleOfField
 Flag set in the middle of a field reading. More...
 
bool ignoreFields
 Set to true if you want to allow fields to be ignored in the read in file. More...
 
bool noEOL
 Set to true to allow files without end-of-line at the end. More...
 

Detailed Description


Class for input files

This class provides features similar to those in the standard C "FILE*" type, but only for sequential input. See OFile for sequential output.

Constructor & Destructor Documentation

◆ IFile()

PLMD::IFile::IFile ( )

Constructor.

◆ ~IFile()

PLMD::IFile::~IFile ( )

Destructor.

Member Function Documentation

◆ advanceField()

IFile & PLMD::IFile::advanceField ( )
private

Advance to next field (= read one line)

◆ allowIgnoredFields()

void PLMD::IFile::allowIgnoredFields ( )

Allow some of the fields in the input to be ignored.

◆ allowNoEOL()

void PLMD::IFile::allowNoEOL ( )

Allow files without EOL at the end.

This in practice should be only used when opening plumed input files

◆ appendSuffix()

std::string PLMD::FileBase::appendSuffix ( const std::string &  path,
const std::string &  suffix 
)
staticinherited

Append suffix.

It appends the desired suffix to the string. Notice that it conserves some suffix (e.g. gz/xtc/trr).

◆ close()

void PLMD::FileBase::close ( )
inherited

Closes the file Should be used only for explicitely opened files.

◆ enforceSuffix()

FileBase & PLMD::FileBase::enforceSuffix ( const std::string &  suffix)
inherited

Enforce suffix.

Overrides the one set in PlumedMain&

◆ FieldExist()

bool PLMD::IFile::FieldExist ( const std::string &  s)

Check if a field exist.

◆ FileExist()

bool PLMD::FileBase::FileExist ( const std::string &  path)
inherited

Check if the file exists.

◆ findField()

unsigned PLMD::IFile::findField ( const std::string &  name) const
private

Find field index by name.

◆ flush()

FileBase & PLMD::FileBase::flush ( )
virtualinherited

Flushes the file to disk.

Reimplemented in PLMD::OFile.

◆ getline()

IFile & PLMD::IFile::getline ( std::string &  str)

Get a full line as a string.

◆ getMode()

std::string PLMD::FileBase::getMode ( ) const
inlineinherited

Retrieve the mode.

◆ getPath()

std::string PLMD::FileBase::getPath ( ) const
inlineinherited

Retrieve the path.

◆ getSuffix()

std::string PLMD::FileBase::getSuffix ( ) const
inherited

Get the file suffix.

◆ isOpen()

bool PLMD::FileBase::isOpen ( )
inherited

Check if a file is open.

◆ link() [1/4]

FileBase & PLMD::FileBase::link ( FILE *  fp)
inherited

Link to an already open filed.

◆ link() [2/4]

FileBase & PLMD::FileBase::link ( PlumedMain plumed)
inherited

Link to a PlumedMain object Automatically links also the corresponding Communicator.

◆ link() [3/4]

FileBase & PLMD::FileBase::link ( Communicator comm)
inherited

Link to a Communicator object.

◆ link() [4/4]

FileBase & PLMD::FileBase::link ( Action action)
inherited

Link to an Action object.

Automatically links also the corresponding PlumedMain and Communicator.

◆ llread()

size_t PLMD::IFile::llread ( char *  ptr,
size_t  s 
)
private

Low-level read.

Note: in parallel, all processes read

◆ open()

IFile & PLMD::IFile::open ( const std::string &  name)
virtual

Opens the file.

Implements PLMD::FileBase.

◆ operator bool()

PLMD::FileBase::operator bool ( ) const
inherited

Check for error/eof.

◆ reset()

void PLMD::IFile::reset ( bool  reset)

Reset end of file.

◆ scanField() [1/5]

IFile & PLMD::IFile::scanField ( const std::string &  name,
double &  x 
)

Read a double field.

◆ scanField() [2/5]

IFile & PLMD::IFile::scanField ( const std::string &  name,
int &  x 
)

Read a int field.

◆ scanField() [3/5]

IFile & PLMD::IFile::scanField ( const std::string &  name,
std::string &  str 
)

Read a string field.

◆ scanField() [4/5]

IFile & PLMD::IFile::scanField ( )


Ends a field-formatted line.

Typically used as

  if.scanField("a",a).scanField("b",b).scanField();

◆ scanField() [5/5]

IFile & PLMD::IFile::scanField ( Value val)

Read in a value.

◆ scanFieldList()

IFile & PLMD::IFile::scanFieldList ( std::vector< std::string > &  s)

Gets the list of all fields.

◆ setHeavyFlush()

void PLMD::FileBase::setHeavyFlush ( )
inlineinherited

Set heavyFlush flag.

◆ test()

void PLMD::FileBase::test ( )
staticinherited

Runs a small testcase.

Member Data Documentation

◆ action

Action* PLMD::FileBase::action
protectedinherited

pointer to corresponding action. NULL if not linked

◆ cloned

bool PLMD::FileBase::cloned
protectedinherited

Control closing on destructor.

If true, file will not be closed in destructor

◆ comm

Communicator* PLMD::FileBase::comm
protectedinherited

communicator. NULL if not set

◆ eof

bool PLMD::FileBase::eof
protectedinherited

Set to true when end of file is encountered.

◆ err

bool PLMD::FileBase::err
protectedinherited

Set to true when error is encountered.

◆ fields

std::vector<Field> PLMD::IFile::fields
private

All the defined fields.

◆ fp

FILE* PLMD::FileBase::fp
protectedinherited

file pointer

◆ gzfp

void* PLMD::FileBase::gzfp
protectedinherited

zip file pointer.

◆ heavyFlush

bool PLMD::FileBase::heavyFlush
protectedinherited

Set to true if you want flush to be heavy (close/reopen)

◆ ignoreFields

bool PLMD::IFile::ignoreFields
private

Set to true if you want to allow fields to be ignored in the read in file.

◆ inMiddleOfField

bool PLMD::IFile::inMiddleOfField
private

Flag set in the middle of a field reading.

◆ mode

std::string PLMD::FileBase::mode
protectedinherited

mode of the opened file

◆ noEOL

bool PLMD::IFile::noEOL
private

Set to true to allow files without end-of-line at the end.

◆ path

std::string PLMD::FileBase::path
protectedinherited

path of the opened file

◆ plumed

PlumedMain* PLMD::FileBase::plumed
protectedinherited

pointer to main plumed object. NULL if not linked


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