ThePEG  1.8.0
CFile.h
1 // -*- C++ -*-
2 #ifndef THEPEG_CFile_H
3 #define THEPEG_CFile_H
4 //
5 // This is the declaration of the CFile class.
6 //
7 
8 #include "Exception.h"
9 
10 namespace ThePEG {
11 
15 class CFile {
16 
17 public:
18 
22  enum FileType {
23  undefined, plain, pipe, gzip, bzip2
24  };
25 
26 public:
27 
33  CFile(): file(0), fileType(undefined) {}
34 
38  CFile(string filename, string mode)
39  : file(0), fileType(undefined) {
40  open(filename, mode);
41  }
42 
46  ~CFile() {}
48 
52  void open(string filename, string mode);
53 
57  void close();
58 
62  operator void * () const {
63  return fileType != undefined? file: 0;
64  }
65 
69  bool operator!() const {
70  return !(operator void * ());
71  }
72 
76  char * gets(char * s, int size);
77 
81  int puts(const char * s);
82 
86  int getc();
87 
91  int putc(int c);
92 
96  int ungetc(int c);
97 
101  size_t read(void *ptr, size_t size, size_t nmemb = 1);
102 
106  size_t write(const void *ptr, size_t size, size_t nmemb = 1);
107 
108 private:
109 
113  void * file;
114 
119 
120 public:
121 
124  class FileError: public Exception {};
127 };
128 
129 }
130 
131 
132 #endif /* THEPEG_CFile_H */