CCAFFEINE
0.8.8
|
00001 #ifndef __BUFFEREDREADER_H__ 00002 #define __BUFFEREDREADER_H__ 00003 00004 // Depends on: 00005 /* #include <sys/time.h> */ 00006 /* #include <error.h> */ 00007 /* #include <sys/types.h> */ 00008 /* #include <unistd.h> */ 00009 /* #include "jc++/jc++.h" */ 00010 /* #include "jc++/util/jc++util.h" */ 00011 /* #include "util/IO.h" */ 00012 /* #include "Reader.h" */ 00013 00014 namespace jcpp { 00015 00017 class BufferedReader : public virtual Reader { 00018 private: 00019 CDELETE Reader* in; 00020 00021 char* cb; 00022 long nChars; // last readable char + 1 00023 int nextChar; // index to the next readable char 00024 int maxChars; // size of the buffer cb 00025 long defaultCharBufferSize; 00026 long defaultExpectedLineLength; 00027 CDELETE StringBuffer* sb; 00028 public: 00029 BufferedReader(Reader* in); 00031 virtual void close() { 00032 in->close(); 00033 } 00035 virtual void mark() { 00036 en((char *)"not allowed to use mark() in Reader"); 00037 } 00039 virtual boolean markSupported() { 00040 return FALSE; 00041 } 00043 virtual int read(); 00045 virtual int read(char* cbuf, int length) { 00046 return read(cbuf, 0 , length); 00047 } 00048 private: 00052 int preRead(char* cbuf, int off, int length); 00053 public: 00054 00057 virtual int read(char* cbuf, int off, int length); 00059 virtual boolean ready() { 00060 return (nextChar < nChars) || in->ready(); 00061 } 00064 virtual void reset() { 00065 en((char *)":-( Reader::reset() not supported"); 00066 } 00068 virtual long skip(long length); 00070 virtual CFREE char* readLine(); 00071 private: 00074 int findLineInBuffer(); 00076 void fill(); 00077 protected: 00079 void en(char* str) { 00080 ::fprintf(stderr, "%s\n", str); 00081 } 00082 00083 }; 00084 00085 } ENDSEMI //jcpp 00086 00087 00088 #endif // __BUFFEREDREADER_H__