lhapdf
is hosted by
Hepforge
,
IPPP Durham
LHAPDF
6.5.4
Loading...
Searching...
No Matches
include
LHAPDF
FileIO.h
1
// -*- C++ -*-
2
//
3
// This file is part of LHAPDF
4
// Copyright (C) 2012-2023 The LHAPDF collaboration (see AUTHORS for details)
5
//
6
#pragma once
7
#ifndef LHAPDF_FileIO_H
8
#define LHAPDF_FileIO_H
9
10
// STL includes
11
#include <fstream>
12
#include <sstream>
13
#include <string>
14
16
namespace
LHAPDF
{
17
18
20
template
<
class
FILETYPE>
21
class
File
{
22
public
:
23
24
// Constructor
25
File
(
const
std::string& name)
26
: _name(name), _fileptr(
nullptr
), _streamptr(
nullptr
) {
27
open
();
28
}
29
31
~File
() {
close
(); }
32
33
35
bool
open
();
36
38
bool
close
();
39
41
FILETYPE*
operator->
()
const
{
return
_fileptr; }
42
44
FILETYPE&
operator*
()
const
{
return
*_fileptr; }
45
47
std::string
getContent
()
const
{
return
_streamptr !=
nullptr
? _streamptr->str() :
""
; }
48
49
50
protected
:
51
52
std::string _name;
53
54
FILETYPE* _fileptr;
55
56
std::stringstream* _streamptr;
57
58
};
59
60
61
// Convenience aliases (NB. have to use #defines due to how .cc template building works)
62
// typedef File<std::ifstream> IFile;
63
// typedef File<std::ofstream> OFile;
64
#define IFile File<std::ifstream>
65
#define OFile File<std::ofstream>
66
67
69
void
flushFileCache
();
70
71
72
}
73
#endif
LHAPDF::File
MPI-safe file I/O interface.
Definition
FileIO.h:21
LHAPDF::File::operator->
FILETYPE * operator->() const
Forward methods via pointer emulation.
Definition
FileIO.h:41
LHAPDF::File::getContent
std::string getContent() const
Get the file content.
Definition
FileIO.h:47
LHAPDF::File::operator*
FILETYPE & operator*() const
Forward methods via pointer-dereference emulation.
Definition
FileIO.h:44
LHAPDF::File::open
bool open()
Open file.
LHAPDF::File::close
bool close()
Close file.
LHAPDF::File::~File
~File()
Destructor.
Definition
FileIO.h:31
LHAPDF
Namespace for all LHAPDF functions and classes.
Definition
AlphaS.h:14
LHAPDF::flushFileCache
void flushFileCache()
Global function to flush the MPI-safe file cache.
Generated on Thu Sep 26 2024 15:19:26 for LHAPDF by
1.12.0