ForthIo Class Reference
[Forth - Forth virtual machine]

Abstract interfrace class for forth character i/o. More...

#include <forth.h>

Inheritance diagram for ForthIo:
Inheritance graph
[legend]

List of all members.

Public Member Functions

virtual void ConsoleOut (const CHAR *text, UCELL textLength)=0
virtual CELL ConsoleIn ()=0

Public Attributes

CHAR NewLine [4]

Detailed Description

Abstract interfrace class for forth character i/o.

The forth VM uses this object to request character input and output. Here is an example implementation of this class using the C standard library...

    #include <stdio.h>
    #include <unistd.h>
    #include <termios.h>

    class StdForthIo : public ForthIo
        {
    public:
        StdForthIo()
            {
            // set new line sequence as CR/LF...
            NewLine[0]=2;
            NewLine[1]=13;
            NewLine[2]=10;

            // if stdin is a terminal then set non-canonical input mode without echo...
            if((IsTerminal = tcgetattr(fileno(stdin),&InitialSettings)==0))
                {
                struct termios settings = InitialSettings;
                settings.c_lflag &= ~(ICANON|ECHO);
                settings.c_cc[VMIN] = 1;
                settings.c_cc[VTIME] = 0;
                tcsetattr(fileno(stdin),TCSANOW,&settings);
                }
            }

        ~StdForthIo()
            {
            // restore terminal settings...
            if(IsTerminal)
                tcsetattr(fileno(stdin),TCSANOW,&InitialSettings);
            }


        virtual void ConsoleOut(const CHAR* text,UCELL textLength)
            {
            while(textLength--)
                putchar(*text++);
            }

        virtual CELL ConsoleIn()
            {
            return getchar();
            }

    private:
        bool IsTerminal;
        struct termios InitialSettings;
        };

Definition at line 143 of file forth.h.


Member Function Documentation

virtual void ForthIo::ConsoleOut ( const CHAR text,
UCELL  textLength 
) [pure virtual]

Display a text string on the console. This is called by the forth words TYPE and EMIT.

Parameters:
text Pointer to string.
textLength Number of characters in string.

Implemented in StdForthIo, and TestForthIo.

virtual CELL ForthIo::ConsoleIn (  )  [pure virtual]

Get a single character from the console input. This is called by the forth word KEY.

Returns:
The character.

Implemented in StdForthIo, and TestForthIo.


Member Data Documentation

A counted string representing the system's line terminating sequence. This is used by the forth word CR and the first character in this string is also used as the input termination character by ACECPT.

NewLine[0] is the character count, NewLine[1] and subsequent are the characters of the line terminating sequence; unused characters may be left uninitialised. E.g. the following sequence initialises the string with a carriage-return line-feed sequence:

    NewLine[0]=2; NewLine[1]=13; NewLine[2]=10;

Definition at line 174 of file forth.h.


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

Generated by  doxygen 1.6.1