1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
#ifndef _TEST_PERFORMANCE_OPTIONARG_HPP_
#define _TEST_PERFORMANCE_OPTIONARG_HPP_
#include <optionparser.hpp>
#include <stdio.h>
#include <cstdint>
#include <iostream>
#include <string.h>
#ifdef WIN32
#define strncasecmp _strnicmp
#endif // ifdef WIN32
namespace option = eprosima::option;
struct Arg : public option::Arg
{
enum class EnablerValue : int32_t
{
NO_SET,
ON,
OFF
};
static void print_error(
const char* msg1,
const option::Option& opt,
const char* msg2)
{
fprintf(stderr, "%s", msg1);
fwrite(opt.name, opt.namelen, 1, stderr);
fprintf(stderr, "%s", msg2);
}
static option::ArgStatus Unknown(
const option::Option& option,
bool msg)
{
if (msg)
{
print_error("Unknown option '", option, "'\n");
}
return option::ARG_ILLEGAL;
}
static option::ArgStatus Required(
const option::Option& option,
bool msg)
{
if (option.arg != 0 && option.arg[0] != 0)
{
return option::ARG_OK;
}
if (msg)
{
print_error("Option '", option, "' requires an argument\n");
}
return option::ARG_ILLEGAL;
}
static option::ArgStatus Numeric(
const option::Option& option,
bool msg)
{
char* endptr = 0;
if (option.arg != 0 && strtol(option.arg, &endptr, 10))
{
}
if (endptr != option.arg && *endptr == 0)
{
return option::ARG_OK;
}
if (msg)
{
print_error("Option '", option, "' requires a numeric argument\n");
}
return option::ARG_ILLEGAL;
}
static option::ArgStatus String(
const option::Option& option,
bool msg)
{
if (option.arg != 0)
{
return option::ARG_OK;
}
if (msg)
{
print_error("Option '", option, "' requires a numeric argument\n");
}
return option::ARG_ILLEGAL;
}
static option::ArgStatus Enabler(
const option::Option& option,
bool msg)
{
if (nullptr == option.arg ||
(0 == strncasecmp(option.arg, "on", 2) ||
0 == strncasecmp(option.arg, "off", 3)))
{
return option::ARG_OK;
}
if (msg)
{
print_error("Option '", option, "' supports values 'on' or 'off'\n");
}
return option::ARG_ILLEGAL;
}
};
#endif // _TEST_PERFORMANCE_OPTIONARG_HPP_
|