Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-06 09:38:31

0001 // -*- C++ -*-
0002 #ifndef THEPEG_CFile_H
0003 #define THEPEG_CFile_H
0004 //
0005 // This is the declaration of the CFile class.
0006 //
0007 
0008 #include "Exception.h"
0009 
0010 namespace ThePEG {
0011 
0012 /**
0013  * Here is the documentation of the CFile class.
0014  */
0015 class CFile {
0016 
0017 public:
0018 
0019   /**
0020    *  Type of the file
0021    */
0022   enum FileType {
0023     undefined, plain, pipe, gzip, bzip2
0024   };
0025 
0026 public:
0027 
0028   /** @name Standard constructors and destructors. */
0029   //@{
0030   /**
0031    * The default constructor.
0032    */
0033   CFile(): file(0), fileType(undefined) {}
0034 
0035   /**
0036    * Create a CFile given a file name and a mode.
0037    */
0038   CFile(string filename, string mode)
0039   : file(0), fileType(undefined) {
0040     open(filename, mode);
0041   }
0042     
0043   /**
0044    * The destructor.
0045    */
0046   ~CFile() {}
0047   //@}
0048 
0049   /**
0050    * Open the file
0051    */
0052   void open(string filename, string mode);
0053 
0054   /**
0055    *  Close the file
0056    */
0057   void close();
0058 
0059   /**
0060    *  Pointer to the file
0061    */
0062   operator void * () const {
0063     return fileType != undefined? file: 0;
0064   }
0065 
0066   /**
0067    *  Exist for file existance
0068    */
0069   bool operator!() const {
0070     return !(operator void * ());
0071   }
0072 
0073   /**
0074    *  Get characters
0075    */
0076   char * gets(char * s, int size);
0077 
0078   /**
0079    *  Set characters
0080    */
0081   int puts(const char * s);
0082 
0083   /**
0084    *  Get the current character
0085    */
0086   int getc();
0087 
0088   /**
0089    *  Set the current character
0090    */
0091   int putc(int c);
0092 
0093   /** Pushes the byte specified by \a c (converted to an unsigned char)
0094    *  back onto the stream
0095    */
0096   int ungetc(int c);
0097 
0098   /**
0099    *  Read
0100    */
0101   size_t read(void *ptr, size_t size, size_t nmemb = 1);
0102 
0103   /**
0104    *   Write
0105    */
0106   size_t write(const void *ptr, size_t size, size_t nmemb = 1);
0107 
0108 private:
0109 
0110   /**
0111    * Pointer to the file
0112    */
0113   void * file;
0114 
0115   /**
0116    *  Type of the file
0117    */
0118   FileType fileType;
0119 
0120 public:
0121 
0122   /** @cond EXCEPTIONCLASSES */
0123   /** Exception class used by CFile if reading a file fails. */
0124   class FileError: public Exception {};
0125   /** @endcond */
0126 
0127 };
0128 
0129 }
0130 
0131 
0132 #endif /* THEPEG_CFile_H */