Ocean
Loading...
Searching...
No Matches
CommandArguments.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_BASE_COMMAND_ARGUMENTS_H
9#define META_OCEAN_BASE_COMMAND_ARGUMENTS_H
10
11#include "ocean/base/Base.h"
12#include "ocean/base/Lock.h"
15#include "ocean/base/String.h"
16#include "ocean/base/Triple.h"
17#include "ocean/base/Value.h"
18
19#include <unordered_map>
20
21namespace Ocean
22{
23
24/**
25 * This class implements a manager for command arguments.
26 * Arguments can be configured, parsed, and acquired.
27 * @ingroup base
28 */
29class OCEAN_BASE_EXPORT CommandArguments
30{
31 public:
32
33 /**
34 * Definition of a string with either `char` or `wchar_t`.
35 */
36 template <typename T>
37 using ArgumentT = std::basic_string<T>;
38
39 /**
40 * Definition of a vector holding strings with either `char` or `wchar_t`.
41 */
42 template <typename T>
43 using ArgumentsT = std::vector<ArgumentT<T>>;
44
45 /**
46 * This class implements a simple singleton holding the raw application's command arguments.
47 */
48 class OCEAN_BASE_EXPORT Manager : public Singleton<Manager>
49 {
50 friend class Singleton<Manager>;
51
52 public:
53
54 /**
55 * Sets/registers the command arguments of the application.
56 * @param arguments The arguments to set, ensure that the pointer is valid as long as the application exists, must be valid
57 * @param size The number of provided command arguments, with range [1, infinity)
58 */
59 bool setRawArguments(const char* const* arguments, const size_t size);
60
61 /**
62 * Sets/registers the command arguments of the application.
63 * @param arguments The arguments to set, ensure that the pointer is valid as long as the application exists, must be valid
64 * @param size The number of provided command arguments, with range [1, infinity)
65 */
66 bool setRawArguments(const wchar_t* const* arguments, const size_t size);
67
68 /**
69 * Returns the command arguments of the application.
70 * @return The application's command arguments, nullptr if the arguments have not been set via setArguments().
71 * @tparam TChar The character type, `char` or `wchar_t`
72 * @see setArguments().
73 */
74 template <typename TChar = char>
75 const TChar* const* rawArguments() const;
76
77 /**
78 * Returns the number of command arguments of the application.
79 * @return The application's number of command arguments, 0 if arguments have not been set via setArguments().
80 * @see setArguments().
81 */
82 size_t size() const;
83
84 protected:
85
86 /**
87 * Protected default constructor.
88 */
90
91 protected:
92
93 /// The command arguments, nullptr if no arguments are defined.
94 const char* const* argumentsChar_ = nullptr;
95
96 /// The command arguments, nullptr if no arguments are defined.
97 const wchar_t* const* argumentsWchar_ = nullptr;
98
99 /// The number of command arguments, with range [0, infinity).
100 size_t size_ = 0;
101
102 /// The manager's lock.
103 mutable Lock lock_;
104 };
105
106 protected:
107
108 /**
109 * This class defines a named value with long and short name, with default parameter and description.
110 */
112 {
113 public:
114
115 /**
116 * Creates a new parameter object.
117 * @param longName The long name of the parameter, must be valid
118 * @param shortName The short name of the parameter, can be empty
119 * @param description The optional description of the parameter, can be empty
120 * @param defaultValue The optional default value, invalid otherwise
121 */
122 Parameter(const std::string& longName, const std::string& shortName, const std::string& description, const Value& defaultValue);
123
124 /**
125 * Returns the long name of this parameter
126 * @return The parameter's long name
127 */
128 inline const std::string& longName() const;
129
130 /**
131 * Returns the short name of this parameter
132 * @return The parameter's short name, can be empty
133 */
134 inline const std::string& shortName() const;
135
136 /**
137 * Returns the description of this parameter.
138 * @return The parameter's description
139 */
140 inline const std::string& description() const;
141
142 /**
143 * Returns the default value of this parameter.
144 * @return The parameter's default name, can be invalid
145 */
146 inline const Value& defaultValue() const;
147
148 protected:
149
150 /// The long name of the parameter.
151 std::string longName_;
152
153 /// The short name of the parameter, can be empty.
154 std::string shortName_;
155
156 /// The description of this parameter, can be empty.
157 std::string description_;
158
159 /// The default value of this parameter, can be invalid.
161 };
162
163 /**
164 * Definition of a map mapping long parameter names to parameter objects.
165 */
166 typedef std::map<std::string, Parameter> ParameterMap;
167
168 /**
169 * Definition of a map mapping short parameter names to long parameter names.
170 */
171 typedef std::unordered_map<std::string, std::string> ShortToLongMap;
172
173 /**
174 * Definition of a map mapping long parameter names to values.
175 */
176 typedef std::unordered_map<std::string, Value> ValueMap;
177
178 public:
179
180 /**
181 * Creates a new object.
182 */
184
185 /**
186 * Creates a new object with a description of the application
187 * @param applicationDescription A description text for the application using these command arguments.
188 */
189 CommandArguments(const std::string& applicationDescription);
190
191 /**
192 * Registers a new named parameter which can be parsed as command argument.
193 * @param longName The long name of the parameter, must be valid, must start with a alphabetic character
194 * @param shortName Optional short name of the parameter, can be empty, must start with a alphabetic character if defined
195 * @param description Optional description of the parameter, can be empty
196 * @param defaultValue Optional default value of the parameter, can be invalid
197 * @return True, if the named parameter did not exist before
198 */
199 bool registerParameter(const std::string& longName, const std::string& shortName = std::string(), const std::string& description = std::string(), const Value& defaultValue = Value());
200
201 /**
202 * Registers nameless parameters for the summary.
203 * @param description The description for nameless parameters, must not be empty
204 * @return True, if succeeded
205 */
206 bool registerNamelessParameters(std::string&& description);
207
208 /**
209 * Parses A given command line.
210 * The entire command line may contain several commands separated by space characters.<br>
211 * Command elements which contain space characters must be surrounded by quotation marks.<br>
212 * However, all surrounding quotation marks will be removed during the parsing process.<br>
213 * The first argument should not be the filename (and path) of the executable.
214 * @param commandLine The command line to be parsed, must be valid
215 * @return True, if succeeded
216 * @tparam TChar The character type, `char` or `wchar_t`
217 */
218 template <typename TChar>
219 inline bool parse(const TChar* commandLine);
220
221 /**
222 * Parses the several command arguments.
223 * @param arguments The arguments to be parsed, an be nullptr if `size == 0`
224 * @param size The number of arguments, with size [0, infinity)
225 * @param skipFirstArgument True, to skip the first argument (as this is commonly the path of the executable); False, to parse the first parameter as well
226 * @return True, if succeeded
227 * @tparam TChar The character type, `char` or `wchar_t`
228 */
229 template <typename TChar>
230 bool parse(const TChar* const* arguments, const size_t size, const bool skipFirstArgument = true);
231
232 /**
233 * Parses the command arguments already separated into individual arguments.
234 * @param separatedArguments The individual arguments to be parsed
235 * @return True, if succeeded
236 */
237 bool parse(const ArgumentsT<char>& separatedArguments);
238
239 /**
240 * Parses the command arguments already separated into individual arguments.
241 * @param separatedArguments The individual arguments to be parsed
242 * @return True, if succeeded
243 */
244 bool parse(const ArgumentsT<wchar_t>& separatedArguments);
245
246 /**
247 * Returns the value of a specific parameter which has been parsed.
248 * Below an example of how to use this function:
249 * @code
250 * CommandArguments commandArguments;
251 * commandArguments.registerParameter("input", "i", "The input file");
252 *
253 * const Value inputFile = commandArguments.value<std::string>("input");
254 * if (inputFile.isString())
255 * {
256 * const std::string inputFileString = inputFile.stringValue();
257 * // ...
258 * }
259 * @endcode
260 * @param longName The long name of the parameter for which the value will be returned, must be valid
261 * @param allowDefaultValue True, to return the default value in case no actual value has been parsed; False, to return an invalid value if no actual value has been parsed
262 * @param namelessValueIndex Optional explicit index of a nameless value which is used in case the named value does not exist, -1 to avoid using a nameless value
263 * @return The value of the parameter, an invalid value if the value has not been parsed
264 */
265 Value value(const std::string& longName, const bool allowDefaultValue = true, const size_t namelessValueIndex = size_t(-1)) const;
266
267 /**
268 * Returns the value of a specific parameter which has been parsed.
269 * Below an example of how to use this function:
270 * @code
271 * CommandArguments commandArguments;
272 * commandArguments.registerParameter("input", "i", "The input file");
273 * commandArguments.registerParameter("factor", "f", "The factor parameter");
274 *
275 * const std::string inputFile = commandArguments.value<std::string>("input", std::string(), false);
276 * const double factor = commandArguments.value<double>("factor", -1.0, false);
277 * @endcode
278 * @param longName The long name of the parameter for which the value will be returned, must be valid
279 * @param invalidValue The resulting value in case the parameter was not parsed
280 * @param allowDefaultValue True, to return the default value in case no actual value has been parsed; False, to return an invalid value if no actual value has been parsed
281 * @param namelessValueIndex Optional explicit index of a nameless value which is used in case the named value does not exist, -1 to avoid using a nameless value
282 * @return The value of the parameter, the invalid value if the value has not been parsed
283 */
284 template <typename T>
285 T value(const std::string& longName, const T& invalidValue, const bool allowDefaultValue, const size_t namelessValueIndex = size_t(-1)) const;
286
287 /**
288 * Checks whether a specific parameter value has been parsed, or whether a default value is defined.
289 * @param longName The long name of the parameter value to check, must be valid
290 * @param value Optional resulting value of the parameter
291 * @param allowDefaultValue True, to allow a default value to count as parsed value; False, to check for actually parsed values only
292 * @param namelessValueIndex Optional explicit index of a nameless value which is used in case the named value does not exist, -1 to avoid using a nameless value
293 * @return True, if succeeded
294 */
295 bool hasValue(const std::string& longName, Value* value = nullptr, const bool allowDefaultValue = true, const size_t namelessValueIndex = size_t(-1)) const;
296
297 /**
298 * Checks whether a specific parameter value has been parsed with specific data type, or whether a default value is defined.
299 * @param longName The long name of the parameter value to check, must be valid
300 * @param value The resulting value of the parameter
301 * @param allowDefaultValue True, to allow a default value to count as parsed value; False, to check for actually parsed values only
302 * @param namelessValueIndex Optional explicit index of a nameless value which is used in case the named value does not exist, -1 to avoid using a nameless value
303 * @return True, if succeeded
304 * @tparam T The data type of the value, 'Value' by default, can also be one of these specific values 'bool', 'int32_t', 'double' (while integers are accepted as well), 'std::string'
305 */
306 template <typename T>
307 bool hasValue(const std::string& longName, T& value, const bool allowDefaultValue = true, const size_t namelessValueIndex = size_t(-1)) const;
308
309 /**
310 * Returns all nameless values which have been parsed.
311 * @return The nameless values, in order as they have been parsed, if any
312 */
313 inline const std::vector<std::string>& namelessValues() const;
314
315 /**
316 * Creates a summary of all possible command arguments.
317 * @return The string containing the summary
318 */
319 std::string makeSummary();
320
321 /**
322 * Parses the command line and returns the individual command elements.
323 * The entire command line may contain several commands separated by space characters.<br>
324 * Command elements which contain space characters must be surrounded by quotation marks.<br>
325 * However, all surrounding quotation marks will be removed during the parsing process.<br>
326 * The first argument should not be the filename (and path) of the executable.
327 * @param commandLine Command line to be parsed
328 * @return The separated command arguments
329 * @tparam TChar The character type, `char` or `wchar_t`
330 */
331 template <typename TChar>
332 static ArgumentsT<TChar> separateArguments(const TChar* commandLine);
333
334 protected:
335
336 /**
337 * Returns whether a given string is the start of a long parameter name (whether it starts with "--").
338 * The string must be zero terminated.
339 * @param parameter The string to be checked, must be valid
340 * @return True, if so
341 * @tparam TChar The character type, `char` or `wchar_t`
342 */
343 template <typename TChar>
344 bool isLongParameter(const TChar* parameter);
345
346 /**
347 * Returns whether a given string is the start of a short parameter name (whether it starts with "--").
348 * The string must be zero terminated.
349 * @param parameter The string to be checked, must be valid
350 * @return True, if so
351 * @tparam TChar The character type, `char` or `wchar_t`
352 */
353 template <typename TChar>
354 bool isShortParameter(const TChar* parameter);
355
356 /**
357 * Returns a dash character.
358 * @return Dash character
359 * @tparam TChar The character type, `char` or `wchar_t`
360 */
361 template <typename TChar>
362 static inline TChar dashCharacter();
363
364 /**
365 * Returns a quote character.
366 * @return Quote character
367 * @tparam TChar The character type, `char` or `wchar_t`
368 */
369 template <typename TChar>
370 static inline TChar quoteCharacter();
371
372 /**
373 * Returns a space character.
374 * @return Space character
375 * @tparam TChar The character type, `char` or `wchar_t`
376 */
377 template <typename TChar>
378 static inline TChar spaceCharacter();
379
380 /**
381 * Returns a backslash character.
382 * @return Backslash character
383 * @tparam TChar The character type, `char` or `wchar_t`
384 */
385 template <typename TChar>
386 static inline TChar backslashCharacter();
387
388 protected:
389
390 /// The description text for the application using these command arguments.
392
393 /// The map mapping short parameter names to long parameter names.
395
396 /// The map mapping long parameter names to parameter objects.
398
399 /// The map mapping long parameter names to values.
401
402 /// The vector of values without name.
403 std::vector<std::string> namelessValues_;
404
405 /// Optional description for nameless parameters.
407};
408
409inline const std::string& CommandArguments::Parameter::longName() const
410{
411 return longName_;
412}
413
414inline const std::string& CommandArguments::Parameter::shortName() const
415{
416 return shortName_;
417}
418
419inline const std::string& CommandArguments::Parameter::description() const
420{
421 return description_;
422}
423
425{
426 return defaultValue_;
427}
428
429template <typename TChar>
430inline bool CommandArguments::parse(const TChar* commandLine)
431{
432 if (commandLine == nullptr)
433 {
434 return false;
435 }
436
437 return parse(separateArguments(commandLine));
438}
439
440template <>
441inline bool CommandArguments::parse<wchar_t>(const wchar_t* commandLine)
442{
443 if (commandLine == nullptr)
444 {
445 return false;
446 }
447
448 const ArgumentsT<wchar_t> wSeparatedArugments = separateArguments(commandLine);
449
450 ArgumentsT<char> separatedArugments;
451 separatedArugments.reserve(wSeparatedArugments.size());
452
453 for (const ArgumentT<wchar_t>& argument : wSeparatedArugments)
454 {
455 separatedArugments.emplace_back(String::toAString(argument));
456 }
457
458 return parse(separatedArugments);
459}
460
461template <typename TChar>
462bool CommandArguments::parse(const TChar* const* arguments, const size_t size, const bool skipFirstArgument)
463{
464 if (size == 0)
465 {
466 return true;
467 }
468
469 if (arguments == nullptr)
470 {
471 ocean_assert(false && "Invalid arguments!");
472 return false;
473 }
474
475 ArgumentsT<char> separatedArguments;
476 separatedArguments.reserve(size);
477
478 const size_t nStart = skipFirstArgument ? 1 : 0;
479
480 for (size_t n = nStart; n < size; ++n)
481 {
482 separatedArguments.emplace_back(String::toAString(arguments[n]));
483 }
484
485 return parse(separatedArguments);
486}
487
488template <typename T>
489T CommandArguments::value(const std::string& longName, const T& invalidValue, const bool allowDefaultValue, const size_t namelessValueIndex) const
490{
491 T validValue;
492 if (hasValue<T>(longName, validValue, allowDefaultValue, namelessValueIndex))
493 {
494 return validValue;
495 }
496
497 return invalidValue;
498}
499
500template <>
501inline bool CommandArguments::hasValue(const std::string& longName, bool& boolValue, const bool allowDefaultValue, const size_t namelessValueIndex) const
502{
503 Value value;
504 if (!hasValue(longName, &value, allowDefaultValue, namelessValueIndex))
505 {
506 return false;
507 }
508
509 if (!value.isBool())
510 {
511 return false;
512 }
513
514 boolValue = value.boolValue();
515
516 return true;
517}
518
519template <>
520inline bool CommandArguments::hasValue(const std::string& longName, int32_t& intValue, const bool allowDefaultValue, const size_t namelessValueIndex) const
521{
522 Value value;
523 if (!hasValue(longName, &value, allowDefaultValue, namelessValueIndex))
524 {
525 return false;
526 }
527
528 if (!value.isInt())
529 {
530 return false;
531 }
532
533 intValue = value.intValue();
534
535 return true;
536}
537
538template <>
539inline bool CommandArguments::hasValue(const std::string& longName, double& doubleValue, const bool allowDefaultValue, const size_t namelessValueIndex) const
540{
541 Value value;
542 if (!hasValue(longName, &value, allowDefaultValue, namelessValueIndex))
543 {
544 return false;
545 }
546
547 if (!value.isFloat64(true /*allowIntAndFloat*/))
548 {
549 return false;
550 }
551
552 doubleValue = value.float64Value(true /*allowIntAndFloat*/);
553
554 return true;
555}
556
557template <>
558inline bool CommandArguments::hasValue(const std::string& longName, std::string& stringValue, const bool allowDefaultValue, const size_t namelessValueIndex) const
559{
560 Value value;
561 if (!hasValue(longName, &value, allowDefaultValue, namelessValueIndex))
562 {
563 return false;
564 }
565
566 if (!value.isString())
567 {
568 return false;
569 }
570
571 stringValue = value.stringValue();
572
573 return true;
574}
575
576inline const std::vector<std::string>& CommandArguments::namelessValues() const
577{
578 return namelessValues_;
579}
580
581template <typename TChar>
583{
584 ArgumentsT<TChar> applicationArguments;
585
586 if (!commandLine)
587 {
588 return applicationArguments;
589 }
590
591 ArgumentT<TChar> line(commandLine);
592
593 while (!line.empty())
594 {
595 const typename ArgumentT<TChar>::size_type posQuote = line.find(quoteCharacter<TChar>());
596 const typename ArgumentT<TChar>::size_type posSpace = line.find(spaceCharacter<TChar>());
597
598 if (posQuote == 0)
599 {
600 // pase string command
601
602 typename ArgumentT<TChar>::size_type posEndQuote = line.find(quoteCharacter<TChar>(), 1);
603
604 while (posEndQuote != ArgumentT<TChar>::npos)
605 {
606 if (line[posEndQuote - 1] == backslashCharacter<TChar>())
607 {
608 posEndQuote = line.find(quoteCharacter<TChar>(), posEndQuote + 1);
609 }
610 else
611 {
612 applicationArguments.push_back(line.substr(1, posEndQuote - 1));
613 line = line.substr(posEndQuote + 1);
614 break;
615 }
616 }
617
618 if (posEndQuote == ArgumentT<TChar>::npos)
619 {
620 Log::error() << "Invalid string command: " << String::toAString(line) << "The end quote is missing!";
621 return applicationArguments;
622 }
623
624 continue;
625 }
626
627 // parse string-less command
628 if (posSpace == ArgumentT<TChar>::npos)
629 {
630 ocean_assert(line.length() != 0);
631
632 applicationArguments.push_back(line);
633 break;
634 }
635
636 if (posSpace == 0)
637 {
638 line = line.substr(1);
639 }
640 else
641 {
642 applicationArguments.push_back(line.substr(0, posSpace));
643 line = line.substr(posSpace + 1);
644 }
645 }
646
647 return applicationArguments;
648}
649
650template <typename TChar>
651bool CommandArguments::isLongParameter(const TChar* parameter)
652{
653 ocean_assert(parameter != nullptr);
654
655 // we expect two '-' followed by at least one alphabetic character
656
657 return parameter[0] == dashCharacter<TChar>() && parameter[1] == dashCharacter<TChar>() && parameter[2] != dashCharacter<TChar>() && std::isalpha(int(parameter[2])) != 0;
658}
659
660template <typename TChar>
661bool CommandArguments::isShortParameter(const TChar* parameter)
662{
663 ocean_assert(parameter != nullptr);
664
665 // we expect one '-' followed by at least one alphabetic character
666
667 return parameter[0] == dashCharacter<TChar>() && std::isalpha(int(parameter[1])) != 0;
668}
669
670template <>
671inline char CommandArguments::dashCharacter<char>()
672{
673 return '-';
674}
675
676template <>
677inline wchar_t CommandArguments::dashCharacter<wchar_t>()
678{
679 return L'-';
680}
681
682template <>
683inline char CommandArguments::quoteCharacter<char>()
684{
685 return '"';
686}
687
688template <>
689inline wchar_t CommandArguments::quoteCharacter<wchar_t>()
690{
691 return L'"';
692}
693
694template <>
695inline char CommandArguments::spaceCharacter<char>()
696{
697 return ' ';
698}
699
700template <>
701inline wchar_t CommandArguments::spaceCharacter<wchar_t>()
702{
703 return L' ';
704}
705
706template <>
707inline char CommandArguments::backslashCharacter<char>()
708{
709 return '\\';
710}
711
712template <>
713inline wchar_t CommandArguments::backslashCharacter<wchar_t>()
714{
715 return L'\\';
716}
717
718}
719
720#endif // META_OCEAN_BASE_COMMAND_ARGUMENTS_H
This class implements a simple singleton holding the raw application's command arguments.
Definition CommandArguments.h:49
size_t size() const
Returns the number of command arguments of the application.
bool setRawArguments(const wchar_t *const *arguments, const size_t size)
Sets/registers the command arguments of the application.
bool setRawArguments(const char *const *arguments, const size_t size)
Sets/registers the command arguments of the application.
Lock lock_
The manager's lock.
Definition CommandArguments.h:103
const TChar *const * rawArguments() const
Returns the command arguments of the application.
Manager()
Protected default constructor.
This class defines a named value with long and short name, with default parameter and description.
Definition CommandArguments.h:112
Parameter(const std::string &longName, const std::string &shortName, const std::string &description, const Value &defaultValue)
Creates a new parameter object.
const std::string & description() const
Returns the description of this parameter.
Definition CommandArguments.h:419
std::string longName_
The long name of the parameter.
Definition CommandArguments.h:151
Value defaultValue_
The default value of this parameter, can be invalid.
Definition CommandArguments.h:160
const Value & defaultValue() const
Returns the default value of this parameter.
Definition CommandArguments.h:424
const std::string & shortName() const
Returns the short name of this parameter.
Definition CommandArguments.h:414
const std::string & longName() const
Returns the long name of this parameter.
Definition CommandArguments.h:409
std::string shortName_
The short name of the parameter, can be empty.
Definition CommandArguments.h:154
std::string description_
The description of this parameter, can be empty.
Definition CommandArguments.h:157
This class implements a manager for command arguments.
Definition CommandArguments.h:30
std::string makeSummary()
Creates a summary of all possible command arguments.
ShortToLongMap shortToLongMap_
The map mapping short parameter names to long parameter names.
Definition CommandArguments.h:394
bool registerNamelessParameters(std::string &&description)
Registers nameless parameters for the summary.
bool registerParameter(const std::string &longName, const std::string &shortName=std::string(), const std::string &description=std::string(), const Value &defaultValue=Value())
Registers a new named parameter which can be parsed as command argument.
bool isLongParameter(const TChar *parameter)
Returns whether a given string is the start of a long parameter name (whether it starts with "--").
Definition CommandArguments.h:651
const std::vector< std::string > & namelessValues() const
Returns all nameless values which have been parsed.
Definition CommandArguments.h:576
bool isShortParameter(const TChar *parameter)
Returns whether a given string is the start of a short parameter name (whether it starts with "--").
Definition CommandArguments.h:661
bool hasValue(const std::string &longName, T &value, const bool allowDefaultValue=true, const size_t namelessValueIndex=size_t(-1)) const
Checks whether a specific parameter value has been parsed with specific data type,...
static ArgumentsT< TChar > separateArguments(const TChar *commandLine)
Parses the command line and returns the individual command elements.
Definition CommandArguments.h:582
bool parse(const TChar *commandLine)
Parses A given command line.
Definition CommandArguments.h:430
static TChar dashCharacter()
Returns a dash character.
bool hasValue(const std::string &longName, Value *value=nullptr, const bool allowDefaultValue=true, const size_t namelessValueIndex=size_t(-1)) const
Checks whether a specific parameter value has been parsed, or whether a default value is defined.
std::string descriptionNamelessParameters_
Optional description for nameless parameters.
Definition CommandArguments.h:406
Value value(const std::string &longName, const bool allowDefaultValue=true, const size_t namelessValueIndex=size_t(-1)) const
Returns the value of a specific parameter which has been parsed.
ParameterMap parameterMap_
The map mapping long parameter names to parameter objects.
Definition CommandArguments.h:397
std::string applicationDescription_
The description text for the application using these command arguments.
Definition CommandArguments.h:391
std::vector< std::string > namelessValues_
The vector of values without name.
Definition CommandArguments.h:403
CommandArguments()
Creates a new object.
bool parse(const ArgumentsT< wchar_t > &separatedArguments)
Parses the command arguments already separated into individual arguments.
static TChar quoteCharacter()
Returns a quote character.
CommandArguments(const std::string &applicationDescription)
Creates a new object with a description of the application.
std::basic_string< T > ArgumentT
Definition of a string with either char or wchar_t.
Definition CommandArguments.h:37
std::vector< ArgumentT< T > > ArgumentsT
Definition of a vector holding strings with either char or wchar_t.
Definition CommandArguments.h:43
static TChar backslashCharacter()
Returns a backslash character.
std::unordered_map< std::string, Value > ValueMap
Definition of a map mapping long parameter names to values.
Definition CommandArguments.h:176
bool parse(const ArgumentsT< char > &separatedArguments)
Parses the command arguments already separated into individual arguments.
std::map< std::string, Parameter > ParameterMap
Definition of a map mapping long parameter names to parameter objects.
Definition CommandArguments.h:166
ValueMap valueMap_
The map mapping long parameter names to values.
Definition CommandArguments.h:400
static TChar spaceCharacter()
Returns a space character.
std::unordered_map< std::string, std::string > ShortToLongMap
Definition of a map mapping short parameter names to long parameter names.
Definition CommandArguments.h:171
This class implements a recursive lock object.
Definition Lock.h:31
static MessageObject error()
Returns the message for error messages.
Definition Messenger.h:1074
This template class is the base class for all singleton objects.
Definition Singleton.h:71
static std::string toAString(const char value)
Converts a value to a string with 8bit character.
This class implements a type independent value.
Definition Value.h:23
bool isString() const
Returns whether this object holds a string value as internal data.
Definition Value.h:395
bool isFloat64(const bool allowIntAndFloat=false) const
Returns whether this object holds a 64 bit float value as internal data.
Definition Value.h:383
bool boolValue() const
Returns the internal value as a boolean.
int32_t intValue() const
Returns the internal value as integer.
double float64Value(const bool allowIntAndFloat=false) const
Returns the internal value as 64 bit float.
bool isInt() const
Returns whether this object holds an integer value as internal data.
Definition Value.h:368
std::string stringValue() const
Returns the internal value as string.
bool isBool() const
Returns whether this object holds an boolean value as internal data.
Definition Value.h:363
The namespace covering the entire Ocean framework.
Definition Accessor.h:15