DUtils::LineFile Class Reference

Reads and writes a file by string lines. More...

#include <LineFile.h>

List of all members.

Public Member Functions

 LineFile (void)
 ~LineFile (void)
 LineFile (const char *filename, const FILE_MODES mode)
 LineFile (const string &filename, const FILE_MODES mode)
void OpenForReading (const char *filename)
void OpenForReading (const string &filename)
void OpenForWriting (const char *filename)
void OpenForWriting (const string &filename)
void OpenForAppending (const char *filename)
void OpenForAppending (const string &filename)
bool Eof ()
void Close ()
LineFileoperator<< (const char *s)
LineFileoperator<< (const string &s)
LineFileoperator>> (string &s)
LineFileoperator>> (vector< string > &v)
void Dump (const vector< string > &v)
LineFileoperator<< (const vector< string > &v)
void DiscardLine ()
FILE_MODES GetOpenMode () const

Protected Member Functions

void Init (const char *filename, const FILE_MODES mode)

Protected Attributes

FILE_MODES m_mode
 Opening mode.
fstream m_f
 File stream.
string m_next_line
 Next line to read.

Detailed Description

Reads and writes a file by string lines.


Constructor & Destructor Documentation

LineFile::LineFile ( void   ) 

Creates a linefile with no file

LineFile::~LineFile ( void   ) 

Closes any opened file

LineFile::LineFile ( const char *  filename,
const FILE_MODES  mode 
)

Creates a linefile by opening a file

Parameters:
filename 
mode,: READ or WRITE
Exceptions:
DException if cannot open the file
LineFile::LineFile ( const string &  filename,
const FILE_MODES  mode 
)

Creates a linefile by opening a file

Parameters:
filename 
mode,: READ or WRITE
Exceptions:
DException if cannot open the file

Member Function Documentation

void LineFile::Close (  ) 

Closes any opened file. It is not necessary to call this function explicitly

void LineFile::DiscardLine (  ) 

In reading mode, reads and throws away the next line

void LineFile::Dump ( const vector< string > &  v  ) 

Writes several lines at a time

Parameters:
v,: vector of line strings
Exceptions:
DException if wrong access mode
bool LineFile::Eof (  ) 

Says whether the end of the file has been reached. It is not necessary to read a last empty line to reach eof

Returns:
true iff there is nothing else to read
Exceptions:
DException if wrong access mode
FILE_MODES DUtils::LineFile::GetOpenMode (  )  const [inline]

Returns the opening mode

void LineFile::Init ( const char *  filename,
const FILE_MODES  mode 
) [protected]

Initializes the object by opening a file

Parameters:
filename file to open
mode opening mode
Exceptions:
DException if cannot open the file
void DUtils::LineFile::OpenForAppending ( const string &  filename  )  [inline]

Opens a file for writing at the end. It closes any other opened file

Parameters:
filename 
Exceptions:
DException if cannot open the file
void LineFile::OpenForAppending ( const char *  filename  ) 

Opens a file for writing at the end. It closes any other opened file

Parameters:
filename 
Exceptions:
DException if cannot open the file
void DUtils::LineFile::OpenForReading ( const string &  filename  )  [inline]

Opens a file for reading. It closes any other opened file

Parameters:
filename 
Exceptions:
DException if cannot create the file
void LineFile::OpenForReading ( const char *  filename  ) 

Opens a file for reading. It closes any other opened file

Parameters:
filename 
Exceptions:
DException if cannot create the file
void DUtils::LineFile::OpenForWriting ( const string &  filename  )  [inline]

Opens a file for writing. It closes any other opened file

Parameters:
filename 
Exceptions:
DException if cannot create the file
void LineFile::OpenForWriting ( const char *  filename  ) 

Opens a file for writing. It closes any other opened file

Parameters:
filename 
Exceptions:
DException if cannot create the file
LineFile& DUtils::LineFile::operator<< ( const vector< string > &  v  )  [inline]

Writes several lines at a time

Parameters:
v,: vector of line strings
Exceptions:
DException if wrong access mode
LineFile& DUtils::LineFile::operator<< ( const string &  s  )  [inline]

Writes a line

Exceptions:
DException if wrong access mode
LineFile & LineFile::operator<< ( const char *  s  ) 

Writes a line

Exceptions:
DException if wrong access mode
LineFile & LineFile::operator>> ( vector< string > &  v  ) 

Reads all the remaining lines in the file

Parameters:
v vector to store the lines in
Exceptions:
DException if wrong access mode
LineFile & LineFile::operator>> ( string &  s  ) 

Reads a line

Parameters:
s,: string to write on
Exceptions:
DException if wrong access mode

The documentation for this class was generated from the following files:
 All Classes Namespaces Functions Variables Enumerations Friends
Generated on Thu Feb 7 19:16:00 2013 by  doxygen 1.6.3