cepgen
is hosted by
Hepforge
,
IPPP Durham
CepGen
1.2.5
Central exclusive processes event generator
Loading...
Searching...
No Matches
Filesystem.cpp
Go to the documentation of this file.
1
/*
2
* CepGen: a central exclusive processes event generator
3
* Copyright (C) 2013-2024 Laurent Forthomme
4
* 2023 Dmitri Konstantinov
5
*
6
* This program is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18
*/
19
20
#include <fstream>
21
22
#include "
CepGen/Core/Exception.h
"
23
#include "
CepGen/Utils/Filesystem.h
"
24
25
namespace
cepgen
{
26
namespace
utils {
27
bool
fileExists
(
const
std::string& path) {
return
fs::exists(path); }
28
29
std::string
fileExtension
(
const
std::string& file) {
return
fs::path(file).extension(); }
30
31
std::string
readFile
(
const
std::string& filename) {
32
if
(
auto
ifile = std::ifstream(filename); ifile.good())
33
return
std::string(std::istreambuf_iterator<char>(ifile), std::istreambuf_iterator<char>());
34
throw
CG_FATAL
(
"readFile"
) <<
"Failed to open the file '"
<< filename <<
"' for reading."
;
35
}
36
}
//namespace utils
37
}
// namespace cepgen
Exception.h
CG_FATAL
#define CG_FATAL(mod)
Definition
Exception.h:61
Filesystem.h
cepgen::utils::readFile
std::string readFile(const std::string &filename)
Read the content of a file into a string buffer.
Definition
Filesystem.cpp:31
cepgen::utils::fileExists
bool fileExists(const std::string &path)
Check if the file exists.
Definition
Filesystem.cpp:27
cepgen::utils::fileExtension
std::string fileExtension(const std::string &file)
Small utility to retrieve the extension of a filename.
Definition
Filesystem.cpp:29
cepgen
Common namespace for this Monte Carlo generator.
Definition
CommandLineHandler.cpp:36
CepGen
Utils
Filesystem.cpp
Generated on Mon Jul 29 2024 for CepGen by
1.9.7