nis-util  1.0.D108
Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Private Member Functions | Private Attributes
input Class Reference

#include <input.h>

Inheritance diagram for input:
input_file input_null input_remove_escaped_newlines input_remove_hash_comments input_stdin input_string

Public Types

typedef boost::shared_ptr< inputpointer

Public Member Functions

virtual ~input ()
int get (void)
void unget (int c)
source_location get_source_location (void)
bool read_one_line (source_location &line_locn, rcstring &line)

Static Public Attributes

static const int eof = -1

Protected Member Functions

 input ()

Static Protected Member Functions

static int count_newlines (const void *data, size_t data_size)

Private Member Functions

int underflow (void)
virtual size_t read_inner (source_location &data_locn, void *data, size_t data_size)=0
void refill (void)
 input (const input &rhs)
inputoperator= (const input &rhs)

Private Attributes

unsigned char * buf
size_t buf_allocated
size_t pos
size_t avail
long relative_line_number
source_location buf_locn

Detailed Description

The input abstratc base class is used to represent any kind of input. It could be a file, or a string, or anything else.

Definition at line 30 of file input.h.


Member Typedef Documentation

typedef boost::shared_ptr<input> input::pointer

Definition at line 33 of file input.h.


Constructor & Destructor Documentation

input::~input ( ) [virtual]

The destructor.

Definition at line 28 of file input.cc.

input::input ( ) [protected]

The default constructor. For use by derived classes only.

Definition at line 39 of file input.cc.

input::input ( const input rhs) [private]

The copy constructor. Do not use.

Parameters:
rhsThe right hand side of the initialization.

Member Function Documentation

int input::count_newlines ( const void *  data,
size_t  data_size 
) [static, protected]

The count_newlines class method is used to count the number of newline ('
') characters in the given data.

Definition at line 122 of file input.cc.

int input::get ( void  ) [inline]

The get method is used to obtain a single byte from the input source.

Returns:
a bytes value (always positive, 0..UCHAR_MAX), or input::eof for end of file.

Definition at line 55 of file input.h.

The get_source_location method may be used to obtain the source file location of the current read point.

Note:
The is the current readposition, think of it as the location of the next byte to be obtained from the get method.

Definition at line 113 of file input.cc.

input& input::operator= ( const input rhs) [private]

The assignment operator. Do not use.

Parameters:
rhsThe right hand side of the assignment.
virtual size_t input::read_inner ( source_location data_locn,
void *  data,
size_t  data_size 
) [private, pure virtual]

The read_inner method is called byu the underflow method to fill the buffer buf with more data.

Parameters:
data_locnThe location of the beginning of the returned data. It is the first argument because it's position is immediately before the returned data.
datapointer to the base of an array to receive the data
data_sizethe maximum number of bytes of data than can be received into the data array.
Returns:
The nunber of bytes read into data, or 0 at end of file. always <= data_size

Implemented in input_remove_hash_comments, input_string, input_file, input_stdin, input_null, and input_remove_escaped_newlines.

bool input::read_one_line ( source_location line_locn,
rcstring line 
)

The read_one_line method is used to read a single line from the input.

Parameters:
line_locnThe location of the start of the line.
lineThe returned text of the line, not including the newline.
Returns:
true if a line was read, false at end of file

Definition at line 140 of file input.cc.

void input::refill ( void  ) [private]

Definition at line 99 of file input.cc.

int input::underflow ( void  ) [private]

The underflow method is used by the get method to fill the buffer when it runs out. It uses the read_inner method for this.

Definition at line 51 of file input.cc.

void input::unget ( int  c)

The unget method is sued to return a byte to the input, taking precedence over the data in the buf array. May be called more than once.

Parameters:
cThe byte to be returned. The input::eof value will be ignored (meaning, returning end-of-file.)

Definition at line 67 of file input.cc.


Field Documentation

size_t input::avail [private]

The avail instance variable is used to remember how many bytes were read into the buf array by the most recent call to the underflow method.

aeert(!buf == !avail); assert(avail <= buf_allocated);

Definition at line 156 of file input.h.

unsigned char* input::buf [private]

The buf instance variable is used to remember the base of the dynamically allocated array of bytes used as a buffer to accellerate access (block buffered, rather than unbuffers byte at a time).

assert(!buf == !buf_allocated);

Definition at line 127 of file input.h.

size_t input::buf_allocated [private]

The buf_allocated instance variable is used to remember the number of bytes allocated for the buf array. Once allocated, this usually remains fixed for the life of the program.

assert(!buf == !buf_allocated);

Definition at line 136 of file input.h.

The buf_locn instance variable is used to remember the source file location of the beginning of the most recently read data from the read_inner method. The relative_line_number is added to it to form the value returned by the get_source_location method.

Definition at line 192 of file input.h.

const int input::eof = -1 [static]

The input::eof constant is used to represent the eof of input, or end of file, when reading byte-at-a-time through the get method.

Definition at line 44 of file input.h.

size_t input::pos [private]

The pos instance variable is used to remember how far along we are in reading the data in the buf array.

assert(!buf == !pos); assert(pos <= buf_allocated); assert(pos <= avail);

Definition at line 146 of file input.h.

The relative_line_number instance variable is used to remember the line number of the next byte to be returned by the get method, relative to the buf_locn instance variable, populated by the most recent call to the read_inner method.

Definition at line 164 of file input.h.


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