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 162 of file TCLAPOutput.h.

163 {
164 if (auto val = dynamic_cast<TCLAP::ValueArg<T>*>(arg))
165 {
166 os << " (" << type_name<T>();
167 if (!required)
168 {
169 if constexpr (std::is_same_v<T, std::string>)
170 {
171 // print non-empty default value only
172 if (val->getValue() != "")
173 {
174 os << ", default: " << val->getValue();
175 }
176 }
177 else
178 {
179 os << ", default: " << val->getValue();
180 }
181 }
182 os << ")";
183 }
184 }
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 (std::list<TCLAP::ArgGroup*>::iterator sit = argSets.begin();
75 sit != argSets.end();
76 ++sit)
77 {
78 TCLAP::ArgGroup& argGroup = **sit;
79
80 int const visible = CountVisibleArgs(argGroup);
81 bool const exclusive = visible > 1 && argGroup.isExclusive();
82 bool const forceRequired = visible == 1 && argGroup.isRequired();
83 if (exclusive)
84 {
85 spacePrint(std::cout,
86 argGroup.isRequired() ? "One of:" : "Either of:", 75,
87 3, 0);
88 }
89
90 for (TCLAP::ArgGroup::iterator it = argGroup.begin();
91 it != argGroup.end();
92 ++it)
93 {
94 TCLAP::Arg& arg = **it;
95
96 if (!arg.visibleInHelp())
97 {
98 continue;
99 }
100
101 if (!arg.hasLabel())
102 {
103 unlabelled.push_back(&arg);
104 continue;
105 }
106
107 // Added by LB:
108 std::string const shortID = arg.shortID();
109 std::smatch match;
110 bool const required = arg.isRequired() || forceRequired;
111 std::stringstream ss;
112 if (std::regex_search(shortID, match, std::regex("<([^>]+)>")))
113 {
114 std::string const identifier = match[1];
115
116 ss << identifier;
117 tryPrintValue<std::string>(*it, ss, required);
118 tryPrintValue<int>(*it, ss, required);
119 tryPrintValue<double>(*it, ss, required);
120 tryPrintValue<float>(*it, ss, required);
121 tryPrintValue<size_t>(*it, ss, required);
122 tryPrintValue<unsigned>(*it, ss, required);
123 tryPrintValue<unsigned int>(*it, ss, required);
124 ss << ": ";
125 }
126 ss << arg.getDescription(required);
127
128 if (exclusive)
129 {
130 spacePrint(std::cout, arg.longID(), 75, 6, 3);
131 spacePrint(std::cout, ss.str(), 75, 8, 0);
132 }
133 else
134 {
135 spacePrint(std::cout, arg.longID(), 75, 3, 3);
136 spacePrint(std::cout, ss.str(), 75, 5, 0);
137 }
138 std::cout << '\n';
139 }
140 }
141
142 for (TCLAP::ArgListIterator it = unlabelled.begin();
143 it != unlabelled.end();
144 ++it)
145 {
146 const TCLAP::Arg& arg = **it;
147 spacePrint(std::cout, arg.longID(), 75, 3, 3);
148 spacePrint(std::cout, arg.getDescription(), 75, 5, 0);
149 std::cout << '\n';
150 }
151
152 if (!message.empty())
153 {
154 spacePrint(std::cout, message, 75, 3, 0);
155 }
156
157 std::cout.flush();
158 }
void tryPrintValue(TCLAP::Arg *arg, std::ostream &os, bool required)

References tryPrintValue().


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