00001 /* $Id: CoinFileIO.hpp 1215 2009-11-05 11:03:04Z forrest $ */ 00002 // Copyright (C) 2005, COIN-OR. All Rights Reserved. 00003 #ifndef CoinFileIO_H 00004 #define CoinFileIO_H 00005 00006 #include <string> 00007 00009 class CoinFileIOBase 00010 { 00011 public: 00014 CoinFileIOBase (const std::string &fileName); 00015 00017 ~CoinFileIOBase (); 00018 00020 const char *getFileName () const; 00021 00023 inline std::string getReadType () const 00024 { return readType_.c_str();} 00025 protected: 00026 std::string readType_; 00027 private: 00028 CoinFileIOBase (); 00029 CoinFileIOBase (const CoinFileIOBase &); 00030 00031 std::string fileName_; 00032 }; 00033 00035 class CoinFileInput: public CoinFileIOBase 00036 { 00037 public: 00045 static CoinFileInput *create (const std::string &fileName); 00046 00049 CoinFileInput (const std::string &fileName); 00050 00052 virtual ~CoinFileInput (); 00053 00058 virtual int read (void *buffer, int size) = 0; 00059 00069 virtual char *gets (char *buffer, int size) = 0; 00070 }; 00071 00073 class CoinFileOutput: public CoinFileIOBase 00074 { 00075 public: 00076 00078 enum Compression { 00079 COMPRESS_NONE = 0, 00080 COMPRESS_GZIP = 1, 00081 COMPRESS_BZIP2 = 2 00082 }; 00083 00086 static bool compressionSupported (Compression compression); 00087 00098 static CoinFileOutput *create (const std::string &fileName, 00099 Compression compression); 00100 00103 CoinFileOutput (const std::string &fileName); 00104 00106 virtual ~CoinFileOutput (); 00107 00112 virtual int write (const void * buffer, int size) = 0; 00113 00121 virtual bool puts (const char *s); 00122 00124 inline bool puts (const std::string &s) 00125 { 00126 return puts (s.c_str ()); 00127 } 00128 }; 00129 00137 bool fileAbsPath (const std::string &path) ; 00138 00157 bool fileCoinReadable(std::string &name, 00158 const std::string &dfltPrefix = std::string("")); 00159 #endif