Paula Script
stream.h
Go to the documentation of this file.
1 #pragma once
2 #include "defs.h"
3 #ifndef PAULA_MINI
4 #include <fstream>
5 #endif
6 
7 namespace paula
8 {
9  namespace core { class TreeIterator; }
10  class Var;
11 
12  // OUTPUT
13 
18  {
19  public:
20  virtual void flush() const = 0;
21  virtual void close() const = 0;
22  virtual bool closed() const = 0;
23  };
27  class POut : public IOutputStream
28  {
29  public:
30 
31  virtual void flush() const = 0;
32 
33  // paula printing interface
34 
35  virtual const POut& print(char) const = 0; // eg. std::cout<<c; return *this;
36  virtual const POut& print(const char*) const = 0;
37  virtual const POut& print(long) const = 0;
38  virtual const POut& print(double) const = 0;
39 
40  const POut& print(int x) const;
41  const POut& print(float x) const;
42  const POut& print(bool x) const;
43  const POut& printHex(INT i) const;
44  const POut& printCharSymbol(CHAR c) const;
45  const POut& print(const Error* a) const;
46  const POut& println(const char*) const;
47  const POut& endl() const;
48 
49  const POut& print(const core::TreeIterator& x) const;
50 
51  const POut& print(const Var& x) const;
52 
53  // TODO
54  // printIntsToText(x*)
55  };
56 
60  class NullPrint
61  {
62  // dummy printer that does nothing.
63  // use to get debug prints optimized away on release.
64  public:
65  void flush() const;
66  const NullPrint& print(const char*) const;
67  const NullPrint& print(double) const; // take care of all numbers and bool
68  const NullPrint& printHex(INT i) const;
69  const NullPrint& printCharSymbol(CHAR c) const;
70  const NullPrint& print(const Error* a) const;
71  const NullPrint& println(const char*) const;
72  const NullPrint& print(const core::TreeIterator& x) const;
73  const NullPrint& endl() const;
74  };
78  class STDOut : public POut
79  {
80  public:
81  // Inherited via POut
82  void flush() const override;
83  void close() const override;
84  bool closed() const override;
85  const POut& print(char) const override;
86  const POut& print(const char*) const override;
87  const POut& print(long) const override;
88  const POut& print(double) const override;
89  };
93  class STDErr : public POut
94  {
95  public:
96  // Inherited via POut
97  void flush() const override;
98  void close() const override;
99  bool closed() const override;
100  const POut& print(char) const override;
101  const POut& print(const char*) const override;
102  const POut& print(long) const override;
103  const POut& print(double) const override;
104  };
105 
106  // INPUT
107 
112  {
113  public:
114  virtual bool read(BYTE&) = 0; // we don't know we're at end before reaching it
115  virtual void close() = 0;
116  };
120  class CharInput : public IInputStream
121  {
122  public:
123  CharInput(const char *);
124  bool read(BYTE&) override;
125  void close() override;
126  private:
127  const char * str;
128  INT i;
129  };
134  {
135  public:
137  // Inherited via IInputStream
138  bool read(BYTE&) override;
139  void close() override;
140  };
141 
142 #ifndef PAULA_MINI
143 
146  class FileInput : public IInputStream
147  {
148  private:
149  std::ifstream file; // The internal ifstream object
150  FileInput() = delete;
151  public:
152  static bool exists(const std::string& name);
153 
154  explicit FileInput(const char *);
155  ~FileInput();
156  // Inherited via IInputStream
157  bool read(BYTE&) override;
158  void close() override;
159  const bool found;
160  };
161 #endif
162  //template <class CHAR> class Array;
163 
164  //class BufferInputStream : public IInputStream
165  //{
166  //public:
167  // BufferInputStream(Array<CHAR>&, INT start, INT last);
168  // CHAR read() override;
169  // bool end() override;
170  // void close() override;
171  //private:
172  // Array<CHAR> str;
173  // INT i, last;
174  //};
175 }
paula::IInputStream
Base class for input streams.
Definition: stream.h:111
paula::STDErr::flush
void flush() const override
paula::Var
Access Paula script variable data.
Definition: args.h:17
paula::STDErr::print
const POut & print(char) const override
paula::CharInput::CharInput
CharInput(const char *)
paula::NullPrint::flush
void flush() const
paula::StandardInput
Input stream for C++ std input.
Definition: stream.h:133
paula::STDOut::closed
bool closed() const override
paula::StandardInput::StandardInput
StandardInput()
Definition: stream.h:136
paula::FileInput::close
void close() override
paula::STDErr::close
void close() const override
paula::FileInput::read
bool read(BYTE &) override
paula::FileInput::~FileInput
~FileInput()
paula::NullPrint
Dummy printer. Use to optimize out debug prints.
Definition: stream.h:60
paula::POut::print
virtual const POut & print(char) const =0
paula::STDErr::closed
bool closed() const override
paula::NullPrint::println
const NullPrint & println(const char *) const
paula::POut::printCharSymbol
const POut & printCharSymbol(CHAR c) const
paula::POut::printHex
const POut & printHex(INT i) const
paula::FileInput::found
const bool found
Definition: stream.h:159
paula::STDOut::print
const POut & print(char) const override
paula::POut::println
const POut & println(const char *) const
paula::StandardInput::read
bool read(BYTE &) override
paula::CharInput::read
bool read(BYTE &) override
paula::POut::endl
const POut & endl() const
paula::STDOut::close
void close() const override
paula::StandardInput::close
void close() override
paula::STDOut::flush
void flush() const override
paula::POut::flush
virtual void flush() const =0
paula::CharInput::close
void close() override
paula::STDOut
Print output using C++ std cout.
Definition: stream.h:78
paula::FileInput::exists
static bool exists(const std::string &name)
paula::IOutputStream
Base class for output.
Definition: stream.h:17
paula::STDErr
Print output using C++ std err.
Definition: stream.h:93
paula::IInputStream::read
virtual bool read(BYTE &)=0
paula::CharInput
Input stream for constant strings.
Definition: stream.h:120
paula::NullPrint::endl
const NullPrint & endl() const
paula::NullPrint::print
const NullPrint & print(const char *) const
paula::NullPrint::printHex
const NullPrint & printHex(INT i) const
paula
Definition: paula.h:6
paula::IOutputStream::closed
virtual bool closed() const =0
paula::POut
Base class for print output.
Definition: stream.h:27
paula::IOutputStream::flush
virtual void flush() const =0
paula::IOutputStream::close
virtual void close() const =0
paula::NullPrint::printCharSymbol
const NullPrint & printCharSymbol(CHAR c) const
paula::FileInput
Input stream for C++ std ifstream.
Definition: stream.h:146
paula::IInputStream::close
virtual void close()=0