1
// ---------------------------------------------------------------------------
3
// - standard object library - input stream base class definition -
4
// ---------------------------------------------------------------------------
5
// - This program is free software; you can redistribute it and/or modify -
6
// - it provided that this copyright notice is kept intact. -
8
// - This program is distributed in the hope that it will be useful, but -
9
// - without any warranty; without even the implied warranty of -
10
// - merchantability or fitness for a particular purpose. In no event shall -
11
// - the copyright holder be liable for any direct, indirect, incidental or -
12
// - special damages arising in any way out of the use of this software. -
13
// ---------------------------------------------------------------------------
14
// - copyright (c) 1999-2007 amaury darsch -
15
// ---------------------------------------------------------------------------
17
#ifndef AFNIX_INPUT_HPP
18
#define AFNIX_INPUT_HPP
20
#ifndef AFNIX_STREAM_HPP
24
#ifndef AFNIX_BUFFER_HPP
30
/// The input stream class is a base class which provides a read method for
31
/// character in a generic way. Various classes are derived from it, like
32
/// the InputTerm or InputFile. The class implements a buffer which provides
33
/// a generic pushback method. When the read method is invoked, the character
34
/// is placed in the buffer.
35
/// @author amaury darsch
37
class Input : public Stream {
40
mutable Buffer d_buffer;
43
/// @return the stream descriptor
44
virtual int getsid (void) const;
46
/// @return the next available character
47
virtual char read (void) =0;
49
/// @return the next character in byte mode
50
virtual t_quad rbyte (void);
52
/// @return the next character in utf8 mode
53
virtual t_quad rutf8 (void);
55
/// @return the next available unicode character
56
virtual t_quad rduc (void);
58
/// @return a buffer of character
59
/// @param size the number of character to read
60
virtual Buffer* read (const long size);
62
/// @return the next available line
63
virtual String readln (void);
65
/// @return true if we are at the eof
66
virtual bool iseof (void) const =0;
68
/// check if we can read a character
69
/// @param tout the timeout value
70
virtual bool valid (const long tout) const =0;
72
/// push back a character in the input stream.
73
/// @param value the character to push back
74
virtual void pushback (const char value);
76
/// pushback a c-string
77
/// @param s the string to pushback
78
virtual void pushback (const char* s);
80
/// pushback a c-string by size
81
/// @param s the string to pushback
82
/// @param size the string size
83
virtual void pushback (const char* s, const long size);
85
/// pushback a string on this input stream
86
virtual void pushback (const String& value);
88
/// @return the size of the input buffer
89
virtual long buflen (void) const;
91
/// flush the input stream until a certain character is found
92
/// @param value the blocking character
93
virtual void flush (const char value);
95
/// flush the input stream until a certain character is found
96
/// @param value the blocking character
97
virtual void flush (const t_quad value);
100
/// @return true if the given quark is defined
101
bool isquark (const long quark, const bool hflg) const;
103
/// apply this object with a set of arguments and a quark
104
/// @param robj the current runnable
105
/// @param nset the current nameset
106
/// @param quark the quark to apply these arguments
107
/// @param argv the arguments to apply
108
Object* apply (Runnable* robj, Nameset* nset, const long quark,