OGS
BaseLib::TCLAPOutput Class Reference

Detailed Description

Definition at line 57 of file TCLAPOutput.h.

#include <TCLAPOutput.h>

Inheritance diagram for BaseLib::TCLAPOutput:
[legend]
Collaboration diagram for BaseLib::TCLAPOutput:
[legend]

Public Member Functions

virtual void usage (TCLAP::CmdLineInterface &_cmd)

Private Member Functions

template<typename T>
void tryPrintValue (TCLAP::Arg *arg, std::ostream &os, bool required)

Member Function Documentation

◆ tryPrintValue()

template<typename T>
void BaseLib::TCLAPOutput::tryPrintValue ( TCLAP::Arg * arg,
std::ostream & os,
bool required )
inlineprivate

Definition at line 158 of file TCLAPOutput.h.

159 {
160 if (auto val = dynamic_cast<TCLAP::ValueArg<T>*>(arg))
161 {
162 os << " (" << type_name<T>();
163 if (!required)
164 {
165 if constexpr (std::is_same_v<T, std::string>)
166 {
167 // print non-empty default value only
168 if (val->getValue() != "")
169 {
170 os << ", default: " << val->getValue();
171 }
172 }
173 else
174 {
175 os << ", default: " << val->getValue();
176 }
177 }
178 os << ")";
179 }
180 }
const char * type_name()

References BaseLib::type_name().

Referenced by usage().

◆ usage()

virtual void BaseLib::TCLAPOutput::usage ( TCLAP::CmdLineInterface & _cmd)
inlinevirtual

Definition at line 60 of file TCLAPOutput.h.

61 {
62 // Follows implementation from tclap
63 std::cout << std::endl << "USAGE: " << std::endl << std::endl;
64 _shortUsage(_cmd, std::cout);
65 std::cout << std::endl
66 << std::endl
67 << "Where: " << std::endl
68 << std::endl;
69
70 std::string const message = _cmd.getMessage();
71 std::list<TCLAP::ArgGroup*> argSets = _cmd.getArgGroups();
72
73 std::list<TCLAP::Arg*> unlabelled;
74 for (auto& argSet : argSets)
75 {
76 TCLAP::ArgGroup& argGroup = *argSet;
77
78 int const visible = CountVisibleArgs(argGroup);
79 bool const exclusive = visible > 1 && argGroup.isExclusive();
80 bool const forceRequired = visible == 1 && argGroup.isRequired();
81 if (exclusive)
82 {
83 spacePrint(std::cout,
84 argGroup.isRequired() ? "One of:" : "Either of:", 75,
85 3, 0);
86 }
87
88 for (auto& it : argGroup)
89 {
90 TCLAP::Arg& arg = *it;
91
92 if (!arg.visibleInHelp())
93 {
94 continue;
95 }
96
97 if (!arg.hasLabel())
98 {
99 unlabelled.push_back(&arg);
100 continue;
101 }
102
103 // Added by LB:
104 std::string const shortID = arg.shortID();
105 std::smatch match;
106 bool const required = arg.isRequired() || forceRequired;
107 std::stringstream ss;
108 if (std::regex_search(shortID, match, std::regex("<([^>]+)>")))
109 {
110 std::string const identifier = match[1];
111
112 ss << identifier;
113 tryPrintValue<std::string>(it, ss, required);
114 tryPrintValue<int>(it, ss, required);
115 tryPrintValue<double>(it, ss, required);
116 tryPrintValue<float>(it, ss, required);
117 tryPrintValue<size_t>(it, ss, required);
118 tryPrintValue<unsigned>(it, ss, required);
119 tryPrintValue<unsigned int>(it, ss, required);
120 ss << ": ";
121 }
122 ss << arg.getDescription(required);
123
124 if (exclusive)
125 {
126 spacePrint(std::cout, arg.longID(), 75, 6, 3);
127 spacePrint(std::cout, ss.str(), 75, 8, 0);
128 }
129 else
130 {
131 spacePrint(std::cout, arg.longID(), 75, 3, 3);
132 spacePrint(std::cout, ss.str(), 75, 5, 0);
133 }
134 std::cout << '\n';
135 }
136 }
137
138 for (TCLAP::ArgListIterator it = unlabelled.begin();
139 it != unlabelled.end();
140 ++it)
141 {
142 const TCLAP::Arg& arg = **it;
143 spacePrint(std::cout, arg.longID(), 75, 3, 3);
144 spacePrint(std::cout, arg.getDescription(), 75, 5, 0);
145 std::cout << '\n';
146 }
147
148 if (!message.empty())
149 {
150 spacePrint(std::cout, message, 75, 3, 0);
151 }
152
153 std::cout.flush();
154 }
void tryPrintValue(TCLAP::Arg *arg, std::ostream &os, bool required)

References tryPrintValue().


The documentation for this class was generated from the following file: