[SLP-Homepage]    [Source Modules]    [Manual]    [Run]    [Examples]
 

Abstract Input Stream

The super logic program is read by calling the read method defined here. The class in_c is an abstract input stream, with subclasses for The class in_c defines only the common interface. There can be no direct instances of this class, only instances of the subclasses. Of course, there can be more than one input stream open at the same time (e.g. for include files).

Note that both, constructors and destructors of the subclasses may print error messages (via out_c) - in case the open or close does not work correctly. Also the read method may print an error message. One should check is_open before calling read.


Function for Getting Input:

read:
int read(char *buf, int size);
This function reads characters from the input file into the given buffer with starting address buf and size size. It returns the number of characters actually read. As long as this is greater than zero, everything is ok. If it is zero, the end of file was reached. If it is negative, some error occurred. The function will print an error message itself (by calling the appropriate function from out_c). So if a negative result is returned, the caller may simply treat it like an end of file. Note that the input in the buffer is not null-terminated.


Other Functions (Common to All Input Sources):

is_open:
bool_t is_open(void);
Usually, the constructors of the subclasses immediately open an input stream. However, it might be possible that something wents wrong (e.g. the file doesn't exist). This method returns BOOL_TRUE if this object is currently associated with an open input stream, and BOOL_FALSE otherwise (i.e. the open failed or close was called). Note the the constructors print an error message themselves (by calling the appropriate function from out_c). However, one should check is_open before trying to read from the input stream.
close:
bool_t close(void);
This method closes the current input stream. The method returns BOOL_TRUE if the close was successful. Otherwise, BOOL_FALSE is returned and an error message is printed. The destructor of this class implicitly calls close (if this was not done before). However, by using the implicit method, one has no chance of checking the error status. (Probably, for input files this is not very important, but I don't like such limitations.) Of course, for standard input the close is simply ignored.
filename:
str_t filename(void);
This method returns the name of the file associated with this input stream (e.g. for syntax error messages). It might be possible that the method returns STR_NIL if the input stream comes from the keyboard or the common gateway interface (CGI).


Implementation:


Stefan Brass (sbrass@sis.pitt.edu), March 18, 2001.    [HTML 3.2 Checked]