00001 // -*- C++ -*- 00002 // 00003 // CFileLineReader.h is a part of ThePEG - Toolkit for HEP Event Generation 00004 // Copyright (C) 1999-2007 Leif Lonnblad 00005 // 00006 // ThePEG is licenced under version 2 of the GPL, see COPYING for details. 00007 // Please respect the MCnet academic guidelines, see GUIDELINES for details. 00008 // 00009 #ifndef THEPEG_CFileLineReader_H 00010 #define THEPEG_CFileLineReader_H 00011 // 00012 // This is the declaration of the CFileLineReader class. 00013 // 00014 00015 #include "ThePEG/Config/ThePEG.h" 00016 #include "CFileLineReader.fh" 00017 #include <cstdio> 00018 #include <string> 00019 00020 namespace ThePEG { 00021 00041 class CFileLineReader { 00042 00043 public: 00044 00050 CFileLineReader(); 00051 00057 CFileLineReader(FILE * f, int len = defsize); 00058 00067 CFileLineReader(string filename, int len = defsize); 00068 00072 ~CFileLineReader(); 00074 00080 void open(FILE * f); 00081 00089 void open(string filename); 00090 00094 void close(); 00096 00100 bool readline(); 00101 00107 void resetline(); 00108 00112 string getline() const; 00113 00117 FILE * cfile() const; 00118 00122 operator void *(); 00123 00127 bool operator!(); 00128 00134 bool skip(char c); 00135 00139 bool find(string str) const; 00140 00146 char getc(); 00147 00151 CFileLineReader & operator>>(long & l); 00152 00156 CFileLineReader & operator>>(int & i); 00157 00161 CFileLineReader & operator>>(unsigned long & l); 00162 00166 CFileLineReader & operator>>(unsigned int & i); 00167 00171 CFileLineReader & operator>>(double & d); 00172 00176 CFileLineReader & operator>>(float & f); 00177 00181 CFileLineReader & operator>>(std::string & s); 00183 00184 private: 00185 00189 enum StreamType { unknown, 00190 plainfile, 00191 pipe 00192 }; 00193 00197 FILE * file; 00198 00202 int bufflen; 00203 00207 char * buff; 00208 00212 char * pos; 00213 00217 bool bad; 00218 00222 StreamType type; 00223 00227 static const int defsize = 1024; 00228 00229 private: 00230 00234 CFileLineReader(const CFileLineReader &); 00235 00240 CFileLineReader & operator=(const CFileLineReader &); 00241 00242 }; 00243 00244 } 00245 00246 #endif /* THEPEG_CFileLineReader_H */