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
21#include "CepGen/Utils/String.h"
22
23using namespace std::string_literals;
24
25namespace cepgen {
26 namespace utils {
31 public:
33 : DocumentationGenerator(params), dump_params_(steer<bool>("dumpParameters")) {}
34
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)
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
#define REGISTER_DOCUMENTATION_GENERATOR(name, obj)
Add a documentation generator to the list of handled modules.
A description object for parameters collection.
T steer(const std::string &key) const
Retrieve a parameters as previously steered.
Definition Steerable.h:39
static ParametersDescription description()
std::vector< std::pair< std::string, category_t > > categories_
std::string s(const std::string &word, float num, bool show_number)
Add a trailing "s" when needed.
Definition String.cpp:228
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
std::string toCamelCase(const std::string &in, bool lower)
Convert any case into a camelCase string.
Definition String.cpp:186
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
Common namespace for this Monte Carlo generator.