00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef STREAMWRAPPER_H
00016 #define STREAMWRAPPER_H
00017
00018 #include "dtoolbase.h"
00019 #include "mutexImpl.h"
00020
00021
00022
00023
00024
00025
00026
00027 class EXPCL_DTOOLCONFIG StreamWrapperBase {
00028 protected:
00029 INLINE StreamWrapperBase();
00030
00031 PUBLISHED:
00032 INLINE void acquire();
00033 INLINE void release();
00034
00035 private:
00036 MutexImpl _lock;
00037 #ifdef SIMPLE_THREADS
00038
00039
00040
00041
00042 bool _lock_flag;
00043 #endif
00044 };
00045
00046
00047
00048
00049
00050
00051
00052
00053 class EXPCL_DTOOLCONFIG IStreamWrapper : virtual public StreamWrapperBase {
00054 public:
00055 INLINE IStreamWrapper(istream *stream, bool owns_pointer);
00056 PUBLISHED:
00057 INLINE IStreamWrapper(istream &stream);
00058 ~IStreamWrapper();
00059
00060 INLINE istream *get_istream() const;
00061
00062 public:
00063 void read(char *buffer, streamsize num_bytes);
00064 void read(char *buffer, streamsize num_bytes, streamsize &read_bytes);
00065 void read(char *buffer, streamsize num_bytes, streamsize &read_bytes, bool &eof);
00066 void seek_read(streamsize pos, char *buffer, streamsize num_bytes, streamsize &read_bytes, bool &eof);
00067 INLINE int get();
00068 streamsize seek_gpos_eof();
00069
00070 private:
00071 istream *_istream;
00072 bool _owns_pointer;
00073 };
00074
00075
00076
00077
00078
00079
00080
00081 class EXPCL_DTOOLCONFIG OStreamWrapper : virtual public StreamWrapperBase {
00082 public:
00083 INLINE OStreamWrapper(ostream *stream, bool owns_pointer, bool stringstream_hack = false);
00084 PUBLISHED:
00085 INLINE OStreamWrapper(ostream &stream);
00086 ~OStreamWrapper();
00087
00088 INLINE ostream *get_ostream() const;
00089
00090 public:
00091 void write(const char *buffer, streamsize num_bytes);
00092 void write(const char *buffer, streamsize num_bytes, bool &fail);
00093 void seek_write(streamsize pos, const char *buffer, streamsize num_bytes, bool &fail);
00094 void seek_eof_write(const char *buffer, streamsize num_bytes, bool &fail);
00095 INLINE bool put(char c);
00096 streamsize seek_ppos_eof();
00097
00098 private:
00099 ostream *_ostream;
00100 bool _owns_pointer;
00101
00102
00103
00104
00105
00106
00107
00108 bool _stringstream_hack;
00109 };
00110
00111
00112
00113
00114
00115
00116 class EXPCL_DTOOLCONFIG StreamWrapper : public IStreamWrapper, public OStreamWrapper {
00117 public:
00118 INLINE StreamWrapper(iostream *stream, bool owns_pointer, bool stringstream_hack = false);
00119 PUBLISHED:
00120 INLINE StreamWrapper(iostream &stream);
00121 ~StreamWrapper();
00122
00123 INLINE iostream *get_iostream() const;
00124
00125 private:
00126 iostream *_iostream;
00127 bool _owns_pointer;
00128 };
00129
00130 #include "streamWrapper.I"
00131
00132 #endif