Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

InputFile Class Reference

read textfiles line per line and provide error raising. More...

#include <InputFile.h>

Collaboration diagram for InputFile:

Collaboration graph
[legend]
List of all members.

Public Methods

 InputFile (const std::string &filename_, int bufsize_=RS_INPUTFILE_BUFSIZE)
 open a file for reading. More...

 InputFile (int bufsize_=RS_INPUTFILE_BUFSIZE)
 open STDIN for reading. More...

virtual ~InputFile ()
 close the InputFile. More...

void autoLinebreak (int max_line_length, const std::string &toBreak, int toBreakAtPos)
 defines a substring where lines may be broken automatically. More...

bool getLine (std::string &result)
 read next line from file. More...

unsigned long getLineNumber () const
 get number of last line read by getLine. More...

void ignoreEmptyLines (bool ignore)
 what to do with empty lines. More...

void throw_Error (const std::string &message) const
 raise an Error referencing the current linenumber. More...


Private Methods

void fillBuffer ()

Private Attributes

std::string filename
unsigned long current_line
FILE * in
size_t bufsize
size_t offset
size_t filled
char * buffer
bool end_of_file_seen
bool ignore_empty
int do_auto_break
std::string breakAt
int breakAtPos

Detailed Description

read textfiles line per line and provide error raising.

Definition at line 43 of file InputFile.h.


Constructor & Destructor Documentation

InputFile const std::string &    filename_,
int    bufsize_ = RS_INPUTFILE_BUFSIZE
 

open a file for reading.

Parameters:
filename_  name of file to read
bufsize_  size of line buffer has to be longer than longest line [Default: 2048#]
Exceptions:
IOError 

Definition at line 32 of file InputFile.cpp.

InputFile int    bufsize_ = RS_INPUTFILE_BUFSIZE
 

open STDIN for reading.

Parameters:
bufsize_  size of line buffer has to be longer than longest line [Default: 2048#]

Definition at line 55 of file InputFile.cpp.

virtual ~InputFile   [inline, virtual]
 

close the InputFile.

Definition at line 79 of file InputFile.h.


Member Function Documentation

void fillBuffer   [inline, private]
 

Definition at line 58 of file InputFile.h.

Referenced by InputFile::getLine(), and InputFile::InputFile().

void autoLinebreak int    max_line_length,
const std::string &    toBreak,
int    toBreakAtPos
 

defines a substring where lines may be broken automatically.

Parameters:
max_line_length  wanted length of lines (may be ignored by getLine)
toBreak  a string where line may be broken (i.e. "><" for HTML-Files)
toBreakAtPos  the offset inside 'toBreak' where linebreak will happen (i.e. 1 for example above)
                InputFile html("index.html");
                html.autoLinebreak(80, "><", 1);

                InputFile text("example.txt");
                text.autoLinebreak(80, " ", 1);

Todo:
use two parameters for toBreakAtPos to allow to eliminate the space which is leftover at the end of broken line (in the last example)

Definition at line 75 of file InputFile.cpp.

bool getLine std::string &    result
 

read next line from file.

Parameters:
result  after success this contains the content of the line
Returns:
true# if successful

Definition at line 85 of file InputFile.cpp.

Referenced by FileFilter::getLine().

unsigned long getLineNumber   const [inline]
 

get number of last line read by getLine.

Returns:
number of line [1..n]

Definition at line 111 of file InputFile.h.

void ignoreEmptyLines bool    ignore [inline]
 

what to do with empty lines.

Parameters:
ignore  if true empty lines are overread

Definition at line 116 of file InputFile.h.

void throw_Error const std::string &    message const [inline]
 

raise an Error referencing the current linenumber.

The raised Error contains sth like 'Error in filename (#linenumber): message'

Parameters:
message  error message to raise
Exceptions:
err::Error  (always thrown)

Definition at line 126 of file InputFile.h.


Member Data Documentation

std::string filename [private]
 

Definition at line 45 of file InputFile.h.

unsigned long current_line [private]
 

Definition at line 46 of file InputFile.h.

Referenced by InputFile::getLine().

FILE* in [private]
 

Definition at line 47 of file InputFile.h.

Referenced by InputFile::InputFile().

size_t bufsize [private]
 

Definition at line 48 of file InputFile.h.

Referenced by InputFile::InputFile().

size_t offset [private]
 

Definition at line 49 of file InputFile.h.

Referenced by InputFile::getLine().

size_t filled [private]
 

Definition at line 50 of file InputFile.h.

Referenced by InputFile::getLine().

char* buffer [private]
 

Definition at line 51 of file InputFile.h.

Referenced by InputFile::getLine(), and InputFile::InputFile().

bool end_of_file_seen [private]
 

Definition at line 52 of file InputFile.h.

bool ignore_empty [private]
 

Definition at line 53 of file InputFile.h.

Referenced by InputFile::getLine().

int do_auto_break [private]
 

Definition at line 54 of file InputFile.h.

Referenced by InputFile::autoLinebreak(), and InputFile::getLine().

std::string breakAt [private]
 

Definition at line 55 of file InputFile.h.

Referenced by InputFile::autoLinebreak(), and InputFile::getLine().

int breakAtPos [private]
 

Definition at line 56 of file InputFile.h.

Referenced by InputFile::autoLinebreak(), and InputFile::getLine().


The documentation for this class was generated from the following files:
Contact me in case of errors or questions.
This documentation is powered by Doxygen.
(C) 2000-2002 Doxygen