thepeg is hosted by Hepforge, IPPP Durham
ThePEG  2.2.1
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 */
char * gets(char *s, int size)
Get characters.
FileType
Type of the file.
Definition: CFile.h:22
CFile()
The default constructor.
Definition: CFile.h:33
size_t read(void *ptr, size_t size, size_t nmemb=1)
Read.
FileType fileType
Type of the file.
Definition: CFile.h:118
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28
~CFile()
The destructor.
Definition: CFile.h:46
int putc(int c)
Set the current character.
void open(string filename, string mode)
Open the file.
int getc()
Get the current character.
size_t write(const void *ptr, size_t size, size_t nmemb=1)
Write.
Here is the documentation of the CFile class.
Definition: CFile.h:15
void close()
Close the file.
int ungetc(int c)
Pushes the byte specified by c (converted to an unsigned char) back onto the stream.
bool operator!() const
Exist for file existance.
Definition: CFile.h:69
CFile(string filename, string mode)
Create a CFile given a file name and a mode.
Definition: CFile.h:38
Exception is the base class for all exceptions to be used in ThePEG.
Definition: Exception.h:44
int puts(const char *s)
Set characters.
void * file
Pointer to the file.
Definition: CFile.h:113