File indexing completed on 2025-12-16 10:19:19
0001
0002
0003
0004
0005
0006 #pragma once
0007 #ifndef LHAPDF_FileIO_H
0008 #define LHAPDF_FileIO_H
0009
0010
0011 #include <fstream>
0012 #include <sstream>
0013 #include <string>
0014
0015
0016 namespace LHAPDF {
0017
0018
0019
0020 template <class FILETYPE>
0021 class File {
0022 public:
0023
0024
0025 File(const std::string& name)
0026 : _name(name), _fileptr(nullptr), _streamptr(nullptr) {
0027 open();
0028 }
0029
0030
0031 ~File() { close(); }
0032
0033
0034
0035 bool open();
0036
0037
0038 bool close();
0039
0040
0041 FILETYPE* operator->() const { return _fileptr; }
0042
0043
0044 FILETYPE& operator*() const { return *_fileptr; }
0045
0046
0047 std::string getContent() const { return _streamptr != nullptr ? _streamptr->str() : ""; }
0048
0049
0050 protected:
0051
0052 std::string _name;
0053
0054 FILETYPE* _fileptr;
0055
0056 std::stringstream* _streamptr;
0057
0058 };
0059
0060
0061
0062
0063
0064 #define IFile File<std::ifstream>
0065 #define OFile File<std::ofstream>
0066
0067
0068
0069 void flushFileCache();
0070
0071
0072 }
0073 #endif