3 #ifndef INCLUDE_NN_NLIB_NFLAGS_H_
4 #define INCLUDE_NN_NLIB_NFLAGS_H_
24 static const int kMaxPath = 512;
25 static const int kMaxFileName = 256;
26 static const int kMaxDirName = 512;
27 static const int kMaxExtension = 256;
28 static errno_t GetFileName(
const char* path,
29 char (&filename)[kMaxFileName]) NLIB_NOEXCEPT
NLIB_NONNULL;
30 static errno_t GetDirName(
const char* path,
31 char (&dirname)[kMaxDirName]) NLIB_NOEXCEPT
NLIB_NONNULL;
33 static errno_t GetStringCommaList(
char* arg,
char** vec,
size_t vec_count,
38 return GetStringCommaList(arg, &vec[0], N, written_count);
41 static errno_t GetInt32CommaList(
char* arg, int32_t* vec,
size_t vec_count,
46 return GetInt32CommaList(arg, &vec[0], N, written_count);
49 static errno_t GetDoubleCommaList(
char* arg,
double* vec,
size_t vec_count,
54 return GetDoubleCommaList(arg, &vec[0], N, written_count);
58 static bool GetBoolFromEnv(
const char* varname,
bool defval)
NLIB_NOEXCEPT;
59 static int32_t GetInt32FromEnv(
const char* varname, int32_t defval)
NLIB_NOEXCEPT;
60 static int64_t GetInt64FromEnv(
const char* varname, int64_t defval)
NLIB_NOEXCEPT;
61 static double GetDoubleFromEnv(
const char* varname,
double defval)
NLIB_NOEXCEPT;
63 static const char* GetStringFromEnv(
UniquePtr<
char[]>& buf,
72 NLIB_VIS_PUBLIC void AddDefOptBool(
const char* opt_name,
bool def_value,
const char* desc,
74 NLIB_VIS_PUBLIC void AddDefOptInt32(
const char* opt_name, int32_t def_value,
const char* desc,
76 NLIB_VIS_PUBLIC void AddDefOptDouble(
const char* opt_name,
double def_value,
const char* desc,
78 NLIB_VIS_PUBLIC void AddDefOptString(
const char* opt_name,
const char* def_value,
const char* desc,
83 #define NLIB_FLAGS_DEFINE_bool(opt_name, def_value, desc) \
84 bool NLIB_FLAGS_##opt_name; \
85 class NLIB_FLAGS_CL_##opt_name { \
87 NLIB_FLAGS_CL_##opt_name() { \
88 ::nlib_ns::nflags::AddDefOptBool(#opt_name, def_value, desc, &NLIB_FLAGS_##opt_name); \
90 } NLIB_FLAGS_CL_##opt_name##_
92 #define NLIB_FLAGS_DEFINE_int32(opt_name, def_value, desc) \
93 int32_t NLIB_FLAGS_##opt_name; \
94 class NLIB_FLAGS_CL_##opt_name { \
96 NLIB_FLAGS_CL_##opt_name() { \
97 ::nlib_ns::nflags::AddDefOptInt32(#opt_name, def_value, desc, \
98 &NLIB_FLAGS_##opt_name); \
100 } NLIB_FLAGS_CL_##opt_name##_
102 #define NLIB_FLAGS_DEFINE_double(opt_name, def_value, desc) \
103 double NLIB_FLAGS_##opt_name; \
104 class NLIB_FLAGS_CL_##opt_name { \
106 NLIB_FLAGS_CL_##opt_name() { \
107 ::nlib_ns::nflags::AddDefOptDouble(#opt_name, def_value, desc, \
108 &NLIB_FLAGS_##opt_name); \
110 } NLIB_FLAGS_CL_##opt_name##_
112 #define NLIB_FLAGS_DEFINE_string(opt_name, def_value, desc) \
113 const char* NLIB_FLAGS_##opt_name; \
114 class NLIB_FLAGS_CL_##opt_name { \
116 NLIB_FLAGS_CL_##opt_name() { \
117 ::nlib_ns::nflags::AddDefOptString(#opt_name, def_value, desc, \
118 &NLIB_FLAGS_##opt_name); \
120 } NLIB_FLAGS_CL_##opt_name##_
122 #define NLIB_FLAGS_DECLARE_bool(opt_name) extern bool NLIB_FLAGS_##opt_name
123 #define NLIB_FLAGS_DECLARE_int32(opt_name) extern int32_t NLIB_FLAGS_##opt_name
124 #define NLIB_FLAGS_DECLARE_double(opt_name) extern double NLIB_FLAGS_##opt_name
125 #define NLIB_FLAGS_DECLARE_string(opt_name) extern const char* NLIB_FLAGS_##opt_name
133 #endif // INCLUDE_NN_NLIB_NFLAGS_H_
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
static errno_t GetDoubleCommaList(char *arg, double(&vec)[N], size_t *written_count) noexcept
The function template version of GetDoubleCommaList.
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
static errno_t GetStringCommaList(char *arg, char *(&vec)[N], size_t *written_count) noexcept
The function template version of GetStringCommaList.
UniquePtr owns the pointer, and when it goes out of scope, the pointer is released by the destructor ...
Defines that class that is corresponding to std::unique_ptr.
#define NLIB_FLAGS_DECLARE_bool(opt_name)
Enables the use of an NLIB_FLAGS_option name that was defined in a different place.
The class for parsing command line flags.
A file that contains the configuration information for each development environment.
static errno_t GetInt32CommaList(char *arg, int32_t(&vec)[N], size_t *written_count) noexcept
The function template version of GetInt32CommaList.