Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

sstream.hpp

Go to the documentation of this file.
00001 // +-------------------------------------------------------------------------+
00002 // |               I__n__t__e__L__i__b           0.6.10 development          |
00003 // | Copyright (c) Andrey Vikt. Stolyarov <crocodil_AT_croco.net> 2000-2007. |
00004 // |                                                                         |
00005 // | This is free software. The library part is available under              |
00006 // |                               GNU LESSER GENERAL PUBLIC LICENSE v.2.1.  |
00007 // | GNU LGPL v2.1 is found in docs/gnu_gpl2.txt,  or at  http://www.gnu.org |
00008 // |     Please see also docs/readme.txt and visit http://www.intelib.org    |
00009 // |                                                                         |
00010 // | !!! THERE IS NO WARRANTY OF ANY KIND, NEITHER EXPRESSED NOR IMPLIED !!! |
00011 // +-------------------------------------------------------------------------+
00012 
00013 
00014 
00015 
00026 #ifndef INTELIB_LSTREAM_HPP_SENTRY
00027 #define INTELIB_LSTREAM_HPP_SENTRY
00028 
00029 #include <stdio.h>
00030 #include "../sexpress/refcount.hpp"
00031 #include "../sexpress/iexcept.hpp"
00032 #include "../sexpress/sstring.hpp"
00033 #include "../sexpress/gensref.hpp"
00034 
00036 
00039 class SExpressionStream : public SExpression {
00040 public:
00042     static IntelibTypeId TypeId;
00043 
00045     SExpressionStream() : SExpression(TypeId) {}
00046 protected:
00047     SExpressionStream(const IntelibTypeId &id) : SExpression(id) {}
00048     ~SExpressionStream() {}
00049 
00050 public:
00051 #if INTELIB_TEXT_REPRESENTATIONS == 1
00052     virtual SString TextRepresentation() const;
00053 #endif
00054 
00056     virtual int Getc() = 0;
00058     virtual int Ungetc(int c) = 0;
00060     virtual int Putc(int c) = 0;
00062     virtual int Puts(const char *s) = 0;
00064     virtual char* Gets(char *buf, int bufsize) = 0;
00066     virtual int Seek(long pos) = 0;
00068     virtual long Tell() const = 0;
00070     virtual int Close() = 0;
00072     virtual int Flush() = 0;
00074     virtual int Fileno() const = 0;
00075 };
00076 
00078 class IntelibX_not_a_stream : public IntelibX {
00079 public:
00080     IntelibX_not_a_stream(SReference a_param);
00081 };
00082 
00084 typedef GenericSReference<SExpressionStream,IntelibX_not_a_stream>
00085 SStreamRef;
00086 
00087 
00089 class SExpressionStreamFile : public SExpressionStream {
00090     FILE *f;
00091 public:
00092     static IntelibTypeId TypeId;
00093 
00094     SExpressionStreamFile(FILE *); 
00095 
00096 protected:
00097     SExpressionStreamFile(const IntelibTypeId &id, FILE *); 
00098     virtual ~SExpressionStreamFile(); 
00099 public:
00100 
00101     virtual int Getc();
00102     virtual int Ungetc(int c);
00103     virtual int Putc(int c);
00104     virtual int Puts(const char *s);
00105     virtual char* Gets(char *buf, int bufsize);
00106     virtual int Seek(long pos);
00107     virtual long Tell() const;
00108     virtual int Close();
00109     virtual int Flush();
00110     virtual int Fileno() const; 
00111     
00112     FILE* GetFile() const { return f; }
00113 };
00114 
00116 class SStreamFile : public SStreamRef {
00117 public:
00118     SStreamFile(FILE *f) : SStreamRef(new SExpressionStreamFile(f)) {}
00119 };
00120 
00122 class SStreamStdin : public SStreamFile {
00123 public:
00124     SStreamStdin() : SStreamFile(stdin) {}
00125 };
00126 
00128 class SStreamStdout : public SStreamFile {
00129 public:
00130     SStreamStdout() : SStreamFile(stdout) {}
00131 };
00132 
00134 class SStreamStderr : public SStreamFile {
00135 public:
00136     SStreamStderr() : SStreamFile(stderr) {}
00137 };
00138 
00140 class SExpressionStreamCharbuf : public SExpressionStream {
00141     SString buf;
00142     unsigned long pos;
00143     bool multipass;
00144 public:
00145     SExpressionStreamCharbuf(const char *initbuf = NULL, bool mpass = false);
00146 protected:
00147     ~SExpressionStreamCharbuf();
00148 public:
00149     void AddChar(char);
00150     void AddString(const char*);
00151     void Cleanup(); /* removes the processed part of the buffer */
00152     virtual int Getc();
00153     virtual int Ungetc(int c);
00154     virtual int Putc(int c);
00155     virtual int Puts(const char *s);
00156     virtual char* Gets(char *buf, int bufsize);
00157     virtual int Seek(long pos);
00158     virtual long Tell() const;
00159     virtual int Close();
00160     virtual int Flush();
00161     virtual int Fileno() const;
00162 };
00163 
00165 class SStreamCharbuf : public SStreamRef {
00166 public:
00167     SStreamCharbuf(const char *str, int mpass = 1)
00168         : SStreamRef(new SExpressionStreamCharbuf(str, mpass)) {}
00169     SExpressionStreamCharbuf* operator->() const
00170         { return static_cast<SExpressionStreamCharbuf*>(GetPtr()); }
00171 };
00172 
00173 
00175 class SExpressionStreamTextInput : public SExpressionStreamFile {
00176     int line;
00177 public:
00178     static IntelibTypeId TypeId;
00179 
00180     SExpressionStreamTextInput(FILE *f) 
00181         : SExpressionStreamFile(TypeId, f), line(1) {}
00182     virtual int Getc();
00183     virtual int Ungetc(int c);
00184     virtual char* Gets(char *buf, int bufsize);
00185 
00187     int TellLine() const { return line; } 
00188 protected:
00189     ~SExpressionStreamTextInput() {}
00190 };
00191 
00193 class SStreamTextInput : public SStreamFile {
00194 public:
00195     SStreamTextInput(FILE *f) : SStreamFile(f) {}
00196     SExpressionStreamTextInput* operator->() const
00197         { return static_cast<SExpressionStreamTextInput*>(GetPtr()); }
00198 };
00199 
00200 
00201 #endif

Generated on Tue Dec 18 00:39:46 2007 for InteLib by  doxygen 1.4.1