|
Pol
Rev 533
|
00001 /* 00002 History 00003 ======= 00004 00005 Notes 00006 ======= 00007 00008 */ 00009 00010 #ifndef __OFILE_H 00011 #define __OFILE_H 00012 00013 #ifndef __BOBJECT_H 00014 #include "bobject.h" 00015 #endif 00016 00017 #include <iosfwd> 00018 00019 class OFile; 00020 class FILECont 00021 { 00022 std::string filename_; 00023 00024 FILE *fp; 00025 int nCopies; 00026 public: 00027 FILECont(FILE *iFP) : fp(iFP), nCopies(1) { } 00028 virtual ~FILECont() { if (fp) fclose(fp); fp = NULL; } 00029 friend class OFile; 00030 00031 int close(void); 00032 int read(char *buf, int maxlen); 00033 int write(const char *buf); 00034 int seek(int posn); 00035 int tell(int& posn); 00036 }; 00037 class OFile : public BObjectImp 00038 { 00039 FILECont *fc; 00040 00041 public: 00042 OFile(FILE *iFP) : BObjectImp(OTUnknown), fc(new FILECont(iFP)) { } 00043 OFile(FILECont *iFC) : BObjectImp(OTUnknown), fc(iFC) { fc->nCopies++; } 00044 00045 virtual ~OFile(); 00046 00047 BObjectImp *copy(void) const; 00048 00049 int close(void); 00050 int read(char *buf, int maxlen); 00051 int write(const char *buf); 00052 int seek(int posn); 00053 int tell(int& posn); 00054 00055 const char *isA(void) const { return "File"; } 00056 virtual bool isA(const char *s) const 00057 { 00058 return (stricmp("File", s) == 0); 00059 } 00060 virtual bool isTrue(void) const { return (fc && fc->fp); } 00061 std::string getStringRep() const; 00062 void printOn(std::ostream&) const; 00063 }; 00064 #endif