00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00029 #ifndef flc_fstream_H
00030 #define flc_fstream_H
00031
00032 #include <falcon/stream.h>
00033
00034 namespace Falcon {
00035
00047 class FALCON_DYN_CLASS FileSysData: public BaseAlloc
00048 {
00049 protected:
00050 FileSysData() {}
00051 public:
00052 virtual ~FileSysData() {}
00053 virtual FileSysData *dup() = 0;
00054 };
00055
00062 class FALCON_DYN_CLASS BaseFileStream: public Stream
00063 {
00064 public:
00066 typedef enum {
00067 e_omReadWrite,
00068 e_omReadOnly,
00069 e_omWriteOnly
00070 } t_openMode;
00071
00073 typedef enum {
00074 e_smExclusive,
00075 e_smShareRead,
00076 e_smShareFull
00077 } t_shareMode;
00078
00080 typedef enum {
00081 e_aOtherRead = 04,
00082 e_aOtherWrite = 02,
00083 e_aOtherExecute = 01,
00084 e_aGroupRead = 040,
00085 e_aGroupWrite = 020,
00086 e_aGroupExecute = 010,
00087 e_aUserRead = 0400,
00088 e_aUserWrite = 0200,
00089 e_aUserExecute = 0100,
00090
00091 e_aAll = 0777,
00092 e_aReadOnly = 0444,
00093 e_aHidden = 0600
00094 } t_attributes;
00095
00096 protected:
00097
00098 FileSysData *m_fsData;
00099
00100 virtual int64 seek( int64 pos, Stream::e_whence whence );
00101
00102 public:
00103 BaseFileStream( t_streamType streamType, FileSysData *fsdata ):
00104 Stream( streamType ),
00105 m_fsData( fsdata )
00106 {}
00107
00108 BaseFileStream( const BaseFileStream &other );
00109
00110 virtual ~BaseFileStream();
00111
00112 virtual bool close();
00113 virtual int32 read( void *buffer, int32 size );
00114 virtual int32 write( const void *buffer, int32 size );
00115 virtual int64 tell();
00116 virtual bool truncate( int64 pos = - 1);
00117 virtual bool errorDescription( ::Falcon::String &description ) const;
00118 const FileSysData *getFileSysData() const { return m_fsData; }
00119 virtual int64 lastError() const;
00120 virtual bool put( uint32 chr );
00121 virtual bool get( uint32 &chr );
00125 virtual int32 readAvailable( int32 msecs_timeout, const Sys::SystemData *sysData = 0 );
00126
00127 virtual int32 writeAvailable( int32 msecs_timeout, const Sys::SystemData *sysData = 0 );
00128
00129 virtual bool writeString( const String &source, uint32 begin = 0, uint32 end = csh::npos );
00130 virtual bool readString( String &content, uint32 size );
00131
00136 void setError( int64 errorCode );
00137
00138 virtual FalconData *clone() const;
00139 };
00140
00141 class FALCON_DYN_CLASS FileStream: public BaseFileStream
00142 {
00143 public:
00148 FileStream( FileSysData *fsdata ):
00149 BaseFileStream( t_file, fsdata )
00150 {
00151 status( t_open );
00152 }
00153
00164 FileStream();
00165
00166 virtual void setSystemData( const FileSysData &data );
00167
00172 virtual bool open( const String &filename, t_openMode mode=e_omReadOnly, t_shareMode share=e_smExclusive );
00173
00180 virtual bool create( const String &filename, t_attributes mode, t_shareMode share=e_smExclusive);
00181
00182 };
00183
00184 class FALCON_DYN_CLASS StdStream: public BaseFileStream
00185 {
00186 virtual int64 seek( int64 pos, Stream::e_whence whence ) {
00187 m_status = t_unsupported;
00188 return -1;
00189 }
00190
00191 public:
00192 StdStream( FileSysData *fsdata ):
00193 BaseFileStream( t_stream, fsdata )
00194 {
00195 status( t_open );
00196 }
00197
00202 virtual ~StdStream()
00203 {}
00204
00205
00206
00207
00208
00209
00210 virtual bool truncate( int64 pos=-1 ) {
00211 m_status = t_unsupported;
00212 return false;
00213 }
00214 };
00215
00216 class FALCON_DYN_CLASS InputStream: public StdStream
00217 {
00218 public:
00219
00220 InputStream( FileSysData *fsdata ):
00221 StdStream( fsdata )
00222 {}
00223
00224 virtual int32 write( const void *buffer, int32 size ) {
00225 m_status = t_unsupported;
00226 return -1;
00227 }
00228
00229 };
00230
00231 class FALCON_DYN_CLASS OutputStream: public StdStream
00232 {
00233 public:
00234
00235 OutputStream( FileSysData *fsdata ):
00236 StdStream( fsdata )
00237 {}
00238
00239 virtual int32 read( void *buffer, int32 size ) {
00240 m_status = t_unsupported;
00241 return -1;
00242 }
00243 };
00244
00254 class FALCON_DYN_CLASS StdInStream: public InputStream
00255 {
00256 public:
00257 StdInStream();
00258 };
00259
00269 class FALCON_DYN_CLASS StdOutStream: public OutputStream
00270 {
00271 public:
00272 StdOutStream();
00273 };
00274
00284 class FALCON_DYN_CLASS StdErrStream: public OutputStream
00285 {
00286 public:
00287 StdErrStream();
00288 };
00289
00303 class FALCON_DYN_CLASS RawStdInStream: public InputStream
00304 {
00305 public:
00306 RawStdInStream();
00307 };
00308
00322 class FALCON_DYN_CLASS RawStdOutStream: public OutputStream
00323 {
00324 public:
00325 RawStdOutStream();
00326 };
00327
00341 class FALCON_DYN_CLASS RawStdErrStream: public OutputStream
00342 {
00343 public:
00344 RawStdErrStream();
00345 };
00346
00347 inline BaseFileStream::t_attributes operator|( BaseFileStream::t_attributes one, BaseFileStream::t_attributes two)
00348 {
00349 return (BaseFileStream::t_attributes) ( ((uint32)one) | ((uint32)two) );
00350 }
00351
00352 inline BaseFileStream::t_attributes operator&( BaseFileStream::t_attributes one, BaseFileStream::t_attributes two)
00353 {
00354 return (BaseFileStream::t_attributes) ( ((uint32)one) & ((uint32)two) );
00355 }
00356
00357 inline BaseFileStream::t_attributes operator^( BaseFileStream::t_attributes one, BaseFileStream::t_attributes two)
00358 {
00359 return (BaseFileStream::t_attributes) ( ((uint32)one) & ((uint32)two) );
00360 }
00361
00362 }
00363
00364 #endif
00365
00366