/* */ #ifndef D_IO_FILE_H #define D_IO_FILE_H #include "OutputFile.h" #include #include namespace aria2 { // This is a wrapper base class intended to provide // fopen/fclose/fread/fwrite/fgets functionality. class IOFile:public OutputFile { private: typedef void (IOFile::*unspecified_bool_type)() const; void goodState() const {} public: IOFile() {} virtual ~IOFile() {} // Returns true if file is opened and ferror returns 0. Otherwise // returns false. operator unspecified_bool_type() const; // wrapper for fread. Using 1 for 2nd argument of fread. size_t read(void* ptr, size_t count); // wrapper for fwrite. Using 1 for 2nd argument of fwrite. size_t write(const void* ptr, size_t count); virtual size_t write(const char* str); // wrapper for fgets char* gets(char* s, int size); // wrapper for fgets, but trailing '\n' is replaced with '\0'. char* getsn(char* s, int size); // Reads one line and returns it. The last '\n' is removed. std::string getLine(); // wrapper for fclose int close(); // wrapper for fflush int flush(); // Return true if file is opened && feof(fp_) != 0. Otherwise // returns false. bool eof(); // Returns true if file supports ANSI color escape codes. bool supportsColor(); // Convenient method. Read data to end of file and write them into // given stream. Returns written size. size_t transfer(std::ostream& out); int vprintf(const char* format, va_list va); // Mode for reading static const char READ[]; // Mode for writing static const char WRITE[]; // Mode for append static const char APPEND[]; protected: virtual size_t onRead(void* ptr, size_t count) = 0; virtual size_t onWrite(const void* ptr, size_t count) = 0; virtual char* onGets(char* s, int size) = 0; virtual int onVprintf(const char* format, va_list va) = 0; virtual int onFlush() = 0; virtual int onClose() = 0; virtual bool onSupportsColor() = 0; virtual bool isError() const = 0; virtual bool isEOF() const = 0; virtual bool isOpen() const = 0; }; } // namespace aria2 #endif // D_IO_FILE_H