00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef FILE_CAST_H
00030 #define FILE_CAST_H
00031
00032 #ifndef __cplusplus
00033 #error This is a C++ include file
00034 #endif
00035
00036
00037
00038
00039 #include "Ref.h"
00040 #include "Sink.h"
00041 #include "CastSink.h"
00042 #include "FileSink.h"
00043 #include "FileCast.h"
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00060 class FileCast : public CastSink
00061 {
00062 private:
00063
00067 Ref<FileSink> targetFile;
00068
00075 inline void
00076 init ( FileSink * targetFile )
00077 throw ( Exception )
00078 {
00079 this->targetFile = targetFile;
00080 }
00081
00087 inline void
00088 strip ( void ) throw ( Exception )
00089 {
00090 if ( isOpen() ) {
00091 close();
00092 }
00093 }
00094
00095
00096 protected:
00097
00103 inline
00104 FileCast ( void ) throw ( Exception )
00105 {
00106 throw Exception( __FILE__, __LINE__);
00107 }
00108
00116 inline virtual bool
00117 sendLogin ( void ) throw ( Exception )
00118 {
00119 return true;
00120 }
00121
00122
00123 public:
00124
00131 inline
00132 FileCast ( FileSink * targetFile )
00133 throw ( Exception )
00134 : CastSink( 0, 0, 0)
00135 {
00136 init( targetFile );
00137 }
00138
00144 inline
00145 FileCast( const FileCast & cs ) throw ( Exception )
00146 {
00147 init( targetFile.get() );
00148 }
00149
00155 inline virtual
00156 ~FileCast( void ) throw ( Exception )
00157 {
00158 strip();
00159 }
00160
00168 inline virtual FileCast &
00169 operator= ( const FileCast & cs ) throw ( Exception )
00170 {
00171 if ( this != &cs ) {
00172 strip();
00173 init( targetFile.get() );
00174 }
00175 return *this;
00176 }
00177
00184 virtual bool
00185 open ( void ) throw ( Exception );
00186
00192 inline virtual bool
00193 isOpen ( void ) const throw ()
00194 {
00195 return targetFile->isOpen();
00196 }
00197
00208 inline virtual bool
00209 canWrite ( unsigned int sec,
00210 unsigned int usec ) throw ( Exception )
00211 {
00212 return targetFile->canWrite( sec, usec);
00213 }
00214
00223 inline virtual unsigned int
00224 write ( const void * buf,
00225 unsigned int len ) throw ( Exception )
00226 {
00227 return targetFile->write( buf, len);
00228 }
00229
00235 inline virtual void
00236 flush ( void ) throw ( Exception )
00237 {
00238 return targetFile->flush();
00239 }
00240
00246 inline virtual void
00247 close ( void ) throw ( Exception )
00248 {
00249 return targetFile->close();
00250 }
00251
00252 };
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262 #endif
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277