Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4680 right-hear 1
/** \file lispio.h
2
 * definitions of pure input output classes.
3
 */
4
 
5
 
6
#ifndef __lispio_h__
7
#define __lispio_h__
8
 
9
#include "yacasbase.h"
10
 
11
// Hope this forward declaration doesn't screw us over...
12
class InputDirectories;
13
class InputStatus : public YacasBase
14
{
15
public:
16
  InputStatus() : iFileName("none") , iLineNumber(-1)  {};
17
  ~InputStatus();
18
  void SetTo(LispChar * aFileName);
19
  void RestoreFrom(InputStatus& aPreviousStatus);
20
  inline LispInt LineNumber();
21
  inline LispChar * FileName();
22
  inline void NextLine();
23
 
24
  inline InputStatus(const InputStatus& aOther) : iFileName(aOther.iFileName) , iLineNumber(aOther.iLineNumber)
25
  {
26
  }
27
 
28
  inline InputStatus& operator=(const InputStatus& aOther)
29
  {
30
    iFileName   = aOther.iFileName;
31
    iLineNumber = aOther.iLineNumber;
32
    return *this;
33
  }
34
 
35
private:
36
  LispChar * iFileName;
37
  LispInt  iLineNumber;
38
};
39
 
40
inline LispInt InputStatus::LineNumber()
41
{
42
  return iLineNumber;
43
}
44
inline LispChar * InputStatus::FileName()
45
{
46
  return iFileName;
47
}
48
inline void InputStatus::NextLine()
49
{
50
  iLineNumber++;
51
}
52
 
53
/** \class LispInput : pure abstract class declaring the interface
54
 *  that needs to be implemented by a file (something that expressions
55
 *  can be read from).
56
 */
57
class LispInput : public YacasBase
58
{
59
public:
60
  /** Constructor with InputStatus. InputStatus retains the information
61
   * needed when an error occurred, and the file has already been
62
   * closed.
63
   */
64
  LispInput(InputStatus& aStatus) : iStatus(aStatus) {};
65
  virtual ~LispInput();
66
 
67
  /// Return the next character in the file
68
  virtual LispChar Next() = 0;
69
 
70
  /** Peek at the next character in the file, without advancing the file
71
   *  pointer.
72
   */
73
  virtual LispChar Peek() = 0;
74
 
75
  virtual InputStatus& Status() const {return iStatus;};
76
 
77
  /// Check if the file position is past the end of the file.
78
  virtual LispBoolean EndOfStream() = 0;
79
  /** StartPtr returns the start of a buffer, if there is one.
80
   * Implementations of this class can keep the file in memory
81
   * as a whole, and return the start pointer and current position.
82
   * Especially the parsing code requires this, because it can then
83
   * efficiently look up a symbol in the hash table without having to
84
   * first create a buffer to hold the symbol in. If StartPtr is supported,
85
   * the whole file should be in memory for the whole period the file
86
   * is being read.
87
   */
88
  virtual LispChar * StartPtr() = 0;
89
  virtual LispInt Position() = 0;
90
  virtual void SetPosition(LispInt aPosition) = 0;
91
protected:
92
  InputStatus& iStatus;
93
};
94
 
95
/** \class LispOutput : interface an output object should adhere to.
96
 */
97
class LispOutput : public YacasBase
98
{
99
public:
100
    virtual ~LispOutput();
101
    /// Write out one character.
102
    virtual void PutChar(LispChar aChar) = 0;
103
 
104
public:
105
    void Write(const LispChar * aString);
106
};
107
 
108
#endif
109