CoinUtils trunk
|
00001 /* $Id$ */ 00002 // Copyright (C) 2005, COIN-OR. All Rights Reserved. 00003 // This code is licensed under the terms of the Eclipse Public License (EPL). 00004 00005 #ifndef CoinFileIO_H 00006 #define CoinFileIO_H 00007 00008 #include <string> 00009 00011 class CoinFileIOBase 00012 { 00013 public: 00016 CoinFileIOBase (const std::string &fileName); 00017 00019 ~CoinFileIOBase (); 00020 00022 const char *getFileName () const; 00023 00025 inline std::string getReadType () const 00026 { return readType_.c_str();} 00027 protected: 00028 std::string readType_; 00029 private: 00030 CoinFileIOBase (); 00031 CoinFileIOBase (const CoinFileIOBase &); 00032 00033 std::string fileName_; 00034 }; 00035 00037 class CoinFileInput: public CoinFileIOBase 00038 { 00039 public: 00047 static CoinFileInput *create (const std::string &fileName); 00048 00051 CoinFileInput (const std::string &fileName); 00052 00054 virtual ~CoinFileInput (); 00055 00060 virtual int read (void *buffer, int size) = 0; 00061 00071 virtual char *gets (char *buffer, int size) = 0; 00072 }; 00073 00075 class CoinFileOutput: public CoinFileIOBase 00076 { 00077 public: 00078 00080 enum Compression { 00081 COMPRESS_NONE = 0, 00082 COMPRESS_GZIP = 1, 00083 COMPRESS_BZIP2 = 2 00084 }; 00085 00088 static bool compressionSupported (Compression compression); 00089 00100 static CoinFileOutput *create (const std::string &fileName, 00101 Compression compression); 00102 00105 CoinFileOutput (const std::string &fileName); 00106 00108 virtual ~CoinFileOutput (); 00109 00114 virtual int write (const void * buffer, int size) = 0; 00115 00123 virtual bool puts (const char *s); 00124 00126 inline bool puts (const std::string &s) 00127 { 00128 return puts (s.c_str ()); 00129 } 00130 }; 00131 00139 bool fileAbsPath (const std::string &path) ; 00140 00159 bool fileCoinReadable(std::string &name, 00160 const std::string &dfltPrefix = std::string("")); 00161 #endif