CoinFileIO.hpp
Go to the documentation of this file.
1 /* $Id: CoinFileIO.hpp 1215 2009-11-05 11:03:04Z forrest $ */
2 // Copyright (C) 2005, COIN-OR. All Rights Reserved.
3 #ifndef CoinFileIO_H
4 #define CoinFileIO_H
5 
6 #include <string>
7 
10 {
11 public:
14  CoinFileIOBase (const std::string &fileName);
15 
17  ~CoinFileIOBase ();
18 
20  const char *getFileName () const;
21 
23  inline std::string getReadType () const
24  { return readType_.c_str();}
25 protected:
26  std::string readType_;
27 private:
28  CoinFileIOBase ();
30 
31  std::string fileName_;
32 };
33 
36 {
37 public:
45  static CoinFileInput *create (const std::string &fileName);
46 
49  CoinFileInput (const std::string &fileName);
50 
52  virtual ~CoinFileInput ();
53 
58  virtual int read (void *buffer, int size) = 0;
59 
69  virtual char *gets (char *buffer, int size) = 0;
70 };
71 
74 {
75 public:
76 
78  enum Compression {
82  };
83 
86  static bool compressionSupported (Compression compression);
87 
98  static CoinFileOutput *create (const std::string &fileName,
99  Compression compression);
100 
103  CoinFileOutput (const std::string &fileName);
104 
106  virtual ~CoinFileOutput ();
107 
112  virtual int write (const void * buffer, int size) = 0;
113 
121  virtual bool puts (const char *s);
122 
124  inline bool puts (const std::string &s)
125  {
126  return puts (s.c_str ());
127  }
128 };
129 
137 bool fileAbsPath (const std::string &path) ;
138 
157 bool fileCoinReadable(std::string &name,
158  const std::string &dfltPrefix = std::string(""));
159 #endif
virtual bool puts(const char *s)
Write a string to the file (like fputs).
std::string getReadType() const
Return the method of reading being used.
Definition: CoinFileIO.hpp:23
bool fileAbsPath(const std::string &path)
Test if the given string looks like an absolute file path.
CoinFileInput(const std::string &fileName)
Constructor (don't use this, use the create method instead).
static CoinFileInput * create(const std::string &fileName)
Factory method, that creates a CoinFileInput (more precisely a subclass of it) for the file specified...
~CoinFileIOBase()
Destructor.
bool puts(const std::string &s)
Convenience method: just a 'puts(s.c_str())'.
Definition: CoinFileIO.hpp:124
virtual ~CoinFileInput()
Destructor.
virtual int write(const void *buffer, int size)=0
Write a block of data to the file, similar to fwrite.
Compression
The compression method.
Definition: CoinFileIO.hpp:78
virtual int read(void *buffer, int size)=0
Read a block of data from the file, similar to fread.
const char * getFileName() const
Return the name of the file used by this object.
Abstract base class for file input classes.
Definition: CoinFileIO.hpp:35
std::string fileName_
Definition: CoinFileIO.hpp:31
bool fileCoinReadable(std::string &name, const std::string &dfltPrefix=std::string(""))
Test if the file is readable, using likely versions of the file name, and return the name that worked...
static CoinFileOutput * create(const std::string &fileName, Compression compression)
Factory method, that creates a CoinFileOutput (more precisely a subclass of it) for the file specifie...
Abstract base class for file output classes.
Definition: CoinFileIO.hpp:73
Base class for FileIO classes.
Definition: CoinFileIO.hpp:9
std::string readType_
Definition: CoinFileIO.hpp:26
virtual char * gets(char *buffer, int size)=0
Reads up to (size-1) characters an stores them into the buffer, similar to fgets. ...
virtual ~CoinFileOutput()
Destructor.
static bool compressionSupported(Compression compression)
Returns whether the specified compression method is supported (i.e.
CoinFileOutput(const std::string &fileName)
Constructor (don't use this, use the create method instead).