cepgen
is hosted by
Hepforge
,
IPPP Durham
CepGen
1.2.5
Central exclusive processes event generator
Loading...
Searching...
No Matches
TextDocumentationGenerator.cpp
Go to the documentation of this file.
1
/*
2
* CepGen: a central exclusive processes event generator
3
* Copyright (C) 2021-2024 Laurent Forthomme
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* any later version.
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
*/
18
19
#include "
CepGen/Modules/DocumentationGeneratorFactory.h
"
20
#include "
CepGen/Utils/DocumentationGenerator.h
"
21
#include "
CepGen/Utils/String.h
"
22
23
using namespace
std::string_literals;
24
25
namespace
cepgen
{
26
namespace
utils {
30
class
TextDocumentationGenerator
final :
public
DocumentationGenerator
{
31
public
:
32
explicit
TextDocumentationGenerator
(
const
ParametersList
& params)
33
:
DocumentationGenerator
(params), dump_params_(
steer
<bool>(
"dumpParameters"
)) {}
34
35
static
ParametersDescription
description
() {
36
auto
desc =
DocumentationGenerator::description
();
37
desc.setDescription(
"Bare text documentation generator"
);
38
desc.add<
bool
>(
"modulesOnly"
,
false
).setDescription(
"only list the module names (for a category)?"
);
39
desc.add<
bool
>(
"camelCaseModulesNames"
,
false
).setDescription(
"write modules in camel case?"
);
40
desc.add<
bool
>(
"light"
,
false
).setDescription(
"lightweight module description (without parameters)"
);
41
desc.add<
bool
>(
"dumpParameters"
,
false
)
42
.setDescription(
"dump the parameters list along with their parameters description?"
);
43
return
desc;
44
}
45
46
std::string
describe
()
override
{
47
std::ostringstream os;
48
const
auto
separator = std::string(80,
'-'
);
49
const
auto
light = steer<bool>(
"light"
), camel_case = steer<bool>(
"camelCaseModulesNames"
);
50
std::vector<std::string> modules_names;
51
for
(
const
auto
& cat :
categories_
) {
52
if
(cat.second.modules.empty())
53
continue
;
54
os <<
colourise
(
"\n"
+ separator +
"\n"
+ cat.second.title,
Colour::green
,
Modifier::bold
);
55
if
(!light)
56
os <<
"\n"
;
57
for
(
const
auto
& mod : cat.second.modules) {
58
modules_names.emplace_back(camel_case ?
utils::toCamelCase
(mod.first) : mod.first);
59
if
(light) {
60
os <<
"\n"
61
<< (cat.second.modules_indices.count(mod.first) > 0
62
?
"#"
s
+ std::to_string(cat.second.modules_indices.at(mod.first)) +
": "
63
:
""
s
)
64
<<
colourise
(mod.first,
Colour::cyan
,
Modifier::underline
|
Modifier::bold
) <<
": "
65
<< mod.second.description() << (mod.second.empty() ?
" (*)"
:
""
);
66
}
else
{
67
os <<
"\n"
;
68
if
(cat.second.modules_indices.count(mod.first) > 0)
69
os <<
"#"
<< cat.second.modules_indices.at(mod.first) <<
": "
;
70
os << mod.second.describe();
71
if
(dump_params_)
72
os <<
"\n\tParametersList object:\n\t\t"
<< mod.second.parameters();
73
os <<
"\n"
;
74
}
75
}
76
}
77
if
(steer<bool>(
"modulesOnly"
))
78
return
repr
(modules_names,
";"
);
79
return
os.str();
80
}
81
82
private
:
83
const
bool
dump_params_;
84
};
85
}
// namespace utils
86
}
// namespace cepgen
87
using
cepgen::utils::TextDocumentationGenerator
;
88
REGISTER_DOCUMENTATION_GENERATOR
(
"text"
,
TextDocumentationGenerator
);
DocumentationGeneratorFactory.h
REGISTER_DOCUMENTATION_GENERATOR
#define REGISTER_DOCUMENTATION_GENERATOR(name, obj)
Add a documentation generator to the list of handled modules.
Definition
DocumentationGeneratorFactory.h:25
DocumentationGenerator.h
String.h
cepgen::ParametersDescription
A description object for parameters collection.
Definition
ParametersDescription.h:26
cepgen::ParametersList
Definition
ParametersList.h:52
cepgen::Steerable::steer
T steer(const std::string &key) const
Retrieve a parameters as previously steered.
Definition
Steerable.h:39
cepgen::utils::DocumentationGenerator
Documentation generator object.
Definition
DocumentationGenerator.h:29
cepgen::utils::DocumentationGenerator::description
static ParametersDescription description()
Definition
DocumentationGenerator.cpp:90
cepgen::utils::DocumentationGenerator::categories_
std::vector< std::pair< std::string, category_t > > categories_
Definition
DocumentationGenerator.h:44
cepgen::utils::TextDocumentationGenerator
Text documentation generator object.
Definition
TextDocumentationGenerator.cpp:30
cepgen::utils::TextDocumentationGenerator::describe
std::string describe() override
Definition
TextDocumentationGenerator.cpp:46
cepgen::utils::TextDocumentationGenerator::description
static ParametersDescription description()
Definition
TextDocumentationGenerator.cpp:35
cepgen::utils::TextDocumentationGenerator::TextDocumentationGenerator
TextDocumentationGenerator(const ParametersList ¶ms)
Definition
TextDocumentationGenerator.cpp:32
cepgen::utils::s
std::string s(const std::string &word, float num, bool show_number)
Add a trailing "s" when needed.
Definition
String.cpp:228
cepgen::utils::Modifier::bold
@ bold
cepgen::utils::Modifier::underline
@ underline
cepgen::utils::repr
std::string repr(const std::vector< T > &vec, const std::function< std::string(const T &)> &printer, const std::string &sep=",")
Helper to print a vector.
Definition
String.h:156
cepgen::utils::Colour::cyan
@ cyan
cepgen::utils::Colour::green
@ green
cepgen::utils::toCamelCase
std::string toCamelCase(const std::string &in, bool lower)
Convert any case into a camelCase string.
Definition
String.cpp:186
cepgen::utils::colourise
std::string colourise(const std::string &str, const Colour &col, const Modifier &mod)
Colourise a string for TTY-type output streams.
Definition
String.cpp:70
cepgen
Common namespace for this Monte Carlo generator.
Definition
CommandLineHandler.cpp:36
CepGen
OutputModules
TextDocumentationGenerator.cpp
Generated on Mon Jul 29 2024 for CepGen by
1.9.7