8#include "Arp/System/Core/Enum.hxx"
9#include "Arp/System/Commons/Exceptions/Exceptions.h"
10#include "boost/program_options.hpp"
13namespace Arp {
namespace System {
namespace Commons {
namespace Configuration
16using namespace boost::program_options;
43 void AddOption(
const String& name,
const T& defaultValue,
const String& help);
45 void AddOptionEnum(
const String& name,
const String& help);
48 void ParseArgs(
int argc,
const char*
const argv[]);
49 void PrintDescription(std::ostream& os = std::cout);
50 bool ExistsOption(
const String& optionName)
const;
53 T GetOptionValue(
const String& optionName)
const;
55 bool TryGetOptionValue(
const String& optionName, T& result)
const;
57 Enum<T> GetOptionValueEnum(
const char* optionName);
59 bool TryGetOptionValueEnum(
const char* optionName,
Enum<T>& value);
68 options_description desc;
69 variables_map optionMap;
72 static const String helpOptionName;
75 static const String helpOptionDescription;
81 : desc(
"Allowed options")
84 (helpOptionName, helpOptionDescription);
87inline void CommandLineOptions::AddOption(
const String& name,
const String& help)
94inline void CommandLineOptions::AddOption(
const String& name,
const String& help)
97 (name, value<T>(), help);
101inline void CommandLineOptions::AddOption(
const String& name,
const T& defaultValue,
const String& help)
104 (name, value<T>()->default_value(defaultValue), help);
108inline void CommandLineOptions::AddOptionEnum(
const String& name,
const String& help)
111 (name, value<String>(), help);
115inline void CommandLineOptions::AddOptionEnum(
const String& name,
const Enum<T>& defaultValue,
const String& help)
118 (name, value<String>()->default_value(defaultValue.ToString()), help);
121inline void CommandLineOptions::ParseArgs(
int argc,
const char*
const argv[])
123 store(parse_command_line(argc, argv, this->desc), optionMap);
127inline void CommandLineOptions::PrintDescription(std::ostream& os)
129 os << desc << std::endl;
132inline bool CommandLineOptions::ExistsOption(
const String& optionName)
const
135 if (optionMap.count(optionName))
143inline T CommandLineOptions::GetOptionValue(
const String& optionName)
const
146 if(!this->TryGetOptionValue(optionName, result))
154inline bool CommandLineOptions::TryGetOptionValue(
const String& optionName, T& result)
const
157 if(optionMap.count(optionName) > 0)
159 result = optionMap[optionName].as<T>();
166Enum<T> CommandLineOptions::GetOptionValueEnum(
const char* optionName)
170 if (TryGetOptionValueEnum(optionName, returnValue))
176 throw Exception(
"GetOptionValueEnum failed for mandatory option: {0}", optionName);
182bool CommandLineOptions::TryGetOptionValueEnum(
const char* optionName, Enum<T>& value)
185 if (!this->TryGetOptionValue<String>(optionName, returnValue))
Adapter class for enums to make them loggable and parsable from e.g. XML files.
Definition: Enum.hxx:23
Definition: CommandLineOptions.hpp:19
~CommandLineOptions(void)=default
Destructs this instance and frees all resources.
CommandLineOptions & operator=(const CommandLineOptions &arg)=delete
Assignment operator.
CommandLineOptions(const CommandLineOptions &arg)=delete
Copy constructor.
CommandLineOptions(void)
Constructs an CommandLineOptions instance.
Definition: CommandLineOptions.hpp:80
static KeyNotFoundException Create(const T &keyValue)
Creates an KeyNotFoundException instance using a default message text.
Definition: KeyNotFoundException.hpp:79
static Enum Parse(const String &input)
Parses the given input string.
Definition: Enum.hxx:228
Arp::BasicString< char8 > String
The Arp String class.
Definition: TypeSystem.h:27
Root namespace for the PLCnext API