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;
 
   35    void    AddOption(
const String& name, 
const T& defaultValue, 
const String& help);
 
   37    void    AddOptionEnum(
const String& name, 
const String& help);
 
   40    void    ParseArgs(
int argc, 
const char* 
const argv[]);
 
   41    void    PrintDescription();
 
   42    void    PrintDescription(std::ostream& os);
 
   43    bool    ExistsOption(
const String& optionName) 
const;
 
   46    T       GetOptionValue(
const String& optionName) 
const;
 
   48    bool    TryGetOptionValue(
const String& optionName, T& result) 
const;
 
   50    Enum<T> GetOptionValueEnum(
const char* optionName);
 
   52    bool TryGetOptionValueEnum(
const char* optionName, 
Enum<T>& value);
 
   55    options_description desc;
 
   56    variables_map       optionMap;
 
   59    static const String helpOptionName;
 
   62    static const String helpOptionDescription;
 
   69inline void CommandLineOptions::AddOption(
const String& name, 
const String& help)
 
   72    (name, value<T>(), help);
 
   76inline void CommandLineOptions::AddOption(
const String& name, 
const T& defaultValue, 
const String& help)
 
   79    (name, value<T>()->default_value(defaultValue), help);
 
   83inline void CommandLineOptions::AddOptionEnum(
const String& name, 
const String& help)
 
   86    (name, value<String>(), help);
 
   90inline void CommandLineOptions::AddOptionEnum(
const String& name, 
const Enum<T>& defaultValue, 
const String& help)
 
   93    (name, value<String>()->default_value(defaultValue.
ToString()), help);
 
   99inline T CommandLineOptions::GetOptionValue(
const String& optionName)
 const 
  102    if(!this->TryGetOptionValue(optionName, result))
 
  110inline bool CommandLineOptions::TryGetOptionValue(
const String& optionName, T& result)
 const 
  113    if(optionMap.count(optionName) > 0)
 
  115        result = optionMap[optionName].as<T>();
 
  122Enum<T> CommandLineOptions::GetOptionValueEnum(
const char* optionName)
 
  126    if (TryGetOptionValueEnum(optionName, returnValue))
 
  132        throw Exception(
"GetOptionValueEnum failed for mandatory option: {0}", optionName);
 
  138bool CommandLineOptions::TryGetOptionValueEnum(
const char* optionName, Enum<T>& value)
 
  141    if (!this->TryGetOptionValue<String>(optionName, returnValue))
 
Adapter class for enums to make them loggable and parsable from e.g. XML files.
Definition: Enum.hxx:21
 
This class represents the Arp String. The implementation is based on std::string.
Definition: String.hpp:39
 
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.cpp:16
 
static KeyNotFoundException Create(const T &keyValue)
Creates an KeyNotFoundException instance using a default message text.
Definition: KeyNotFoundException.hpp:56
 
String ToString(bool throwIfInvalid=true) const
Converts this instance to its string representation.
Definition: Enum.ipp:199
 
static Enum Parse(const String &input)
Parses the given input string.
Definition: Enum.ipp:90
 
Root namespace for the PLCnext API