thepeg is hosted by Hepforge, IPPP Durham
ThePEG  2.2.1
CFileLineReader.h
1 // -*- C++ -*-
2 //
3 // CFileLineReader.h is a part of ThePEG - Toolkit for HEP Event Generation
4 // Copyright (C) 1999-2019 Leif Lonnblad
5 //
6 // ThePEG is licenced under version 3 of the GPL, see COPYING for details.
7 // Please respect the MCnet academic guidelines, see GUIDELINES for details.
8 //
9 #ifndef THEPEG_CFileLineReader_H
10 #define THEPEG_CFileLineReader_H
11 //
12 // This is the declaration of the CFileLineReader class.
13 //
14 
15 #include "ThePEG/Config/ThePEG.h"
16 #include "CFileLineReader.fh"
17 #include "CFile.h"
18 #include <cstdio>
19 #include <string>
20 
21 namespace ThePEG {
22 
43 
44 public:
45 
52 
61  CFileLineReader(string filename, int len = defsize);
62 
68 
78  void open(string filename);
79 
83  void close();
85 
89  bool readline();
90 
96  void resetline();
97 
101  string getline() const;
102 
106  CFile cFile() const;
107 
111  operator void *();
112 
116  bool operator!();
117 
123  bool skip(char c);
124 
128  bool find(string str) const;
129 
135  char getc();
136 
140  CFileLineReader & operator>>(long & l);
141 
145  CFileLineReader & operator>>(int & i);
146 
150  CFileLineReader & operator>>(unsigned long & l);
151 
155  CFileLineReader & operator>>(unsigned int & i);
156 
160  CFileLineReader & operator>>(double & d);
161 
165  CFileLineReader & operator>>(float & f);
166 
170  CFileLineReader & operator>>(std::string & s);
172 
173 private:
174 
179 
183  int bufflen;
184 
188  char * buff;
189 
193  char * pos;
194 
198  bool bad;
199 
203  static const int defsize = 1024;
204 
205 private:
206 
211 
216  CFileLineReader & operator=(const CFileLineReader &) = delete;
217 
218 };
219 
220 }
221 
222 #endif /* THEPEG_CFileLineReader_H */
int bufflen
The length of the line buffer.
string getline() const
Return a string containing what is left of the line buffer.
char * buff
The line buffer.
bool find(string str) const
Check if a given string is present in the current line buffer.
CFileLineReader()
The default constructor.
~CFileLineReader()
The destructor.
char getc()
Return the next character of the line-buffer.
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28
CFile cFile() const
Return the underlying c-file.
This is the main config header file for ThePEG.
CFileLineReader & operator=(const CFileLineReader &)=delete
The assignment operator is private and must never be called.
CFile file
The c-file to be read from.
Here is the documentation of the CFile class.
Definition: CFile.h:15
bool operator!()
Return true if a previous read failed.
void resetline()
Undo reading from the current line, ie.
bool bad
The current state is bad if a read has failed.
bool skip(char c)
Scan forward up and until the first occurrence of the given character.
void open(string filename)
Initialize with a filename.
CFileLineReader is a wrapper around a standard C FILE stream.
bool readline()
Read a line from the underlying c-file into the line buffer.
static const int defsize
The default size of the buffer.
void close()
If the file was opened from within this object, close it.
CFileLineReader & operator>>(long &l)
Read a long from the line buffer.
char * pos
The current position in the line buffer.