AXCEL C++ Framework
Elegance through abstraction
Public Member Functions
axcel::io::input Class Reference

Input stream. More...

#include <axcel.h>

Inheritance diagram for axcel::io::input:
axcel::io::iob axcel::object axcel::io::ios axcel::console axcel::data axcel::fs::file axcel::net::socket::tcp axcel::proc::pstream axcel::string

List of all members.

Public Member Functions

virtual string type ()
 Get type of object.
virtual int getc ()=0
 Read byte.
virtual char * gets (char *s, int size=0)
 Read line to buffer.
virtual string gets (int size=0)
 Read line.
virtual int scanf (const char *format,...)
 Formatted input.
virtual size_t read (char *ptr, size_t size, size_t nmemb)
 Read raw data.
virtual data read (size_t size, size_t nmemb)
 Read raw data.
virtual data dump ()
 Read until EOF.
virtual string drink (const char *eol=0)
 Read string until terminating sequence.
virtual data suck (const char *eol, size_t len=0)
 Read raw data until terminating sequence.
inputoperator>> (bool &val)
inputoperator>> (short &val)
inputoperator>> (unsigned short &val)
inputoperator>> (int &val)
inputoperator>> (unsigned int &val)
inputoperator>> (long &val)
inputoperator>> (unsigned long &val)
inputoperator>> (long long &val)
inputoperator>> (unsigned long long &val)
inputoperator>> (float &val)
inputoperator>> (double &val)
inputoperator>> (long double &val)
inputoperator>> (void *&val)
inputoperator>> (char &c)
inputoperator>> (char *s)
inputoperator>> (string &s)

Detailed Description

Input stream.

Definition at line 329 of file axcel.h.


Member Function Documentation

string axcel::io::input::drink ( const char *  eol = 0) [virtual]

Read string until terminating sequence.

Definition at line 6641 of file axcel.cpp.

data axcel::io::input::dump ( ) [virtual]

Read until EOF.

Returns:
data object containing every byte read from this stream until an error or end-of-file was detected. This method may or may not block depending on the deriving object implementing this class.

Reimplemented in axcel::net::socket::tcp, and axcel::console.

Definition at line 6674 of file axcel.cpp.

virtual int axcel::io::input::getc ( ) [pure virtual]

Read byte.

Returns:
Character read as an unsigned char cast to an int or EOF on end of file or error

Reads the next character from stream and returns it as an unsigned char cast to an int, or EOF on end of file or error. Before returning from the method, one of the following methods of the stream must be called:

  • If end of file is reached, the method must call drain()
  • If a small error occurs but the stream is still usable, the method must call hurt()
  • If a fatal error occurs and the stream is unusable, the method must call kill()
  • If successful, the method must call heal()

Implemented in axcel::data, axcel::string, axcel::fs::file, axcel::net::socket::tcp, axcel::console, and axcel::proc::pstream.

string axcel::io::input::gets ( int  size = 0) [virtual]

Read line.

Parameters:
sizeMax number of characters to read
Returns:
Line read as string

Unless size is 0, this method reads in at most size characters from stream and returns it as a string. Reading stops after an EOF or a '\n' character. If a '\n' character is read, it is stored into the string.

Definition at line 3681 of file axcel.cpp.

char * axcel::io::input::gets ( char *  s,
int  size = 0 
) [virtual]

Read line to buffer.

Parameters:
sBuffer to store string
sizeMaximum size of buffer
Returns:
s on success, and NULL on error or when end of fs::file occurs.

Unless size is 0, this method reads in at most one less than size characters from stream and stores them info the buffer pointed to by s. Reading stops after an EOF or a newline. If a newline is read, it is stored into the buffer. A '\0' is stored after the last character in the buffer.

Definition at line 572 of file axcel.cpp.

io::input & axcel::io::input::operator>> ( char *  s)

Reimplemented in axcel::io::ios.

Definition at line 1079 of file axcel.cpp.

io::input & axcel::io::input::operator>> ( double &  val)

Reimplemented in axcel::io::ios.

Definition at line 1043 of file axcel.cpp.

io::input & axcel::io::input::operator>> ( long &  val)

Reimplemented in axcel::io::ios.

Definition at line 998 of file axcel.cpp.

io::input & axcel::io::input::operator>> ( unsigned long long &  val)

Reimplemented in axcel::io::ios.

Definition at line 1025 of file axcel.cpp.

io::input & axcel::io::input::operator>> ( unsigned long &  val)

Reimplemented in axcel::io::ios.

Definition at line 1007 of file axcel.cpp.

io::input & axcel::io::input::operator>> ( string s)

Reimplemented in axcel::io::ios.

Definition at line 3311 of file axcel.cpp.

io::input & axcel::io::input::operator>> ( long long &  val)

Reimplemented in axcel::io::ios.

Definition at line 1016 of file axcel.cpp.

io::input & axcel::io::input::operator>> ( unsigned int &  val)

Reimplemented in axcel::io::ios.

Definition at line 989 of file axcel.cpp.

io::input & axcel::io::input::operator>> ( bool &  val)

Reimplemented in axcel::io::ios.

Definition at line 944 of file axcel.cpp.

io::input & axcel::io::input::operator>> ( unsigned short &  val)

Reimplemented in axcel::io::ios.

Definition at line 971 of file axcel.cpp.

io::input & axcel::io::input::operator>> ( char &  c)

Reimplemented in axcel::io::ios.

Definition at line 1070 of file axcel.cpp.

io::input & axcel::io::input::operator>> ( float &  val)

Reimplemented in axcel::io::ios.

Definition at line 1034 of file axcel.cpp.

io::input & axcel::io::input::operator>> ( long double &  val)

Reimplemented in axcel::io::ios.

Definition at line 1052 of file axcel.cpp.

io::input & axcel::io::input::operator>> ( void *&  val)

Reimplemented in axcel::io::ios.

Definition at line 1061 of file axcel.cpp.

io::input & axcel::io::input::operator>> ( short &  val)

Reimplemented in axcel::io::ios.

Definition at line 962 of file axcel.cpp.

io::input & axcel::io::input::operator>> ( int &  val)

Reimplemented in axcel::io::ios.

Definition at line 980 of file axcel.cpp.

size_t axcel::io::input::read ( char *  ptr,
size_t  size,
size_t  nmemb 
) [virtual]

Read raw data.

Parameters:
ptrBuffer
sizeElement size
nmembNumber of elements to read
Returns:
Number of elements successfully read

Reads nmemb elements of data, each of size bytes long, from the stream, storing them at the location given by ptr.

Definition at line 615 of file axcel.cpp.

data axcel::io::input::read ( size_t  size,
size_t  nmemb 
) [virtual]

Read raw data.

Definition at line 6782 of file axcel.cpp.

int axcel::io::input::scanf ( const char *  format,
  ... 
) [virtual]

Formatted input.

Parameters:
formatFormat string
...Token value arguments
Returns:
Number of matched tokens or EOF on end of fs::file or error.

Scans input according to format as described below. This format may contain conversion specifications; the results from such conversions, if any, are stored in the locations pointed to by the pointer arguments that follow format. Each pointer argument must be of a type that is appropriate for the value returned by the corresponding conversion specification.

If the number of conversion specifications in format exceeds the number of pointer arguments, the results are undefined. If the number of pointer arguments exeeds the number of conversion specifications, then the excess pointer arguments are evaluated, but are otherwise ignored.

The format string consists of a sequence of directives which describe how to process the sequence of input characters. If processing of a directive fails, no further input is read, and scanf() returns. A "failure" can be either the following: input failure, meaning that input characters were unavailable, or matching failure, meaning that the input was inappropriate (see below).

A directive is one of the following:

  • A sequence of whitespace characters. This directive matches any amount of whitespace, including none, in the input.
  • An ordinary character (other than whitespace or '%'). This character must exactly match the next character of input.
  • A conversion specification, which commences with a '%' (percent) character. A sequence of characters from the input is converted according to this specification, and the result is placed in the corresponding pointer argument. If the next item of io::input does not match the conversion specification, the conversion failes - this is a matching failure.

Each conversion specification in format begins with the character '%' followed by:

  • An optional '*' assignment-suppression character: scanf() reads input as directed by the conversion specification, but discards the input. No corresponding pointer argument is required, and this specification is not included in the count of successfull assignments returned by scanf().
  • An optional '^' character: scanf() does not discard leading whitespace for this conversion.
  • An optional '$' character: scanf() reads until a '\n' character is detected before performing conversion.
  • An optional decimal integer which specifies the maximum field width. Reading of characters stops either when this maximum is reached or when a nonmatching character is found, whichever happens first. All conversions discard initial white space characters (unless overridden), and these discarded characters don't count towards the maximum field width. string io::input conversions store a null terminator ('\0') to mark the end of the io::input; the maximum field width does not include this terminator.
  • An optional type modifier character. For example, the w type modifier is used with integer conversions such as d to specify that the corresponding pointer argument refers to a long int rather than a pointer to an int.
  • A conversion specifier that specifies the type of input conversion to be performed.

The following type modifier characters can appear in a conversion specification:

  • b - indicates that the conversion will be one of D, O, X, I, d, o, x, or i and the next pointer is a pointer to a signed char or unsigned char.
  • h - As for b, but the next pointer is a pointer to a short int or unsigned short int
  • w - indicates that the conversion will be one of f, D, O, X, I, d, o, x, or i and the next pointer is a pointer to a long int, unsigned long int, or double (when used with f only).
  • l - As for w, but the next pointer is a pointer to a long long int, unsigned long long int, or long double (when used with f only).

The following conversion specifiers are available:

  • % - Matches a literal %. That is, %% in the format string matches a single input % character. No conversion is done (but initial white space characters are discarded), and assignment does not occur.
  • d - Matches a signed decimal integer; the next pointer must be a pointer to a signed int.
  • D - Matches an unsigned decimal integer; the next pointer must be a pointer to an unsigned int.
  • o - Matches a signed octal integer; the next pointer must be a pointer to a signed int.
  • O - Matches an unsigned octal integer; the next pointer must be a pointer to an unsigned int.
  • x - Matches a signed hexadecimal integer; the next pointer must be a pointer to a signed int.
  • X - Matches an unsigned hexadecimal integer; the next pointer must be a pointer to an unsigned int.
  • i - Matches a signed integer; the next pointer must be a pointer to a signed int. The integer is read in base 16 if it begins with 0x, in base 8 if it begins with 0, and in base 10 otherwise. Only characters that correspond to the base are used.
  • I - As for i, except using unsigned integers.
  • f - Matches a signed floating-point number; the next pointer must be a pointer to a float.
  • c - Matches a sequence of characters whose length is specified by the maximum field width (default 1); the next pointer must be a pointer to a char, and there must be enough room for all characters (no terminating null bye is added).
  • s - Matches a sequence of non-white-space characters; the next pointer must be a pointer to a character array that is long enough to hold the input sequence and ther terminating null character ('\0'), which is added automatically. The io::input string stops at whitespace or at maximum field width. To read an entire line, use the '$' format flag (see above).

This method returns the number of input items successfully matched and assigned, which can be fewer than provided for, or even zero in the event of an early matching failure.

The value EOF is returned if the end of input is reached before either the first successful conversion or a matrching failure occurs (see eof()). EOF is also returned if a read error occurs, in which case the error indicator for the stream is set (see dead()).

Definition at line 696 of file axcel.cpp.

data axcel::io::input::suck ( const char *  eol,
size_t  len = 0 
) [virtual]

Read raw data until terminating sequence.

Definition at line 6656 of file axcel.cpp.

string axcel::io::input::type ( ) [virtual]

Get type of object.

Returns:
string containing name of object's class.

Reimplemented from axcel::io::iob.

Reimplemented in axcel::io::ios, axcel::data, axcel::string, axcel::fs::file, axcel::net::socket::tcp, axcel::console, and axcel::proc::pstream.

Definition at line 255 of file axcel.cpp.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Defines