1#ifndef BENCHMARK_COMMANDLINEFLAGS_H_
2#define BENCHMARK_COMMANDLINEFLAGS_H_
3
4#include <cstdint>
5#include <string>
6
7// Macro for referencing flags.
8#define FLAG(name) FLAGS_##name
9
10// Macros for declaring flags.
11#define DECLARE_bool(name) extern bool FLAG(name)
12#define DECLARE_int32(name) extern int32_t FLAG(name)
13#define DECLARE_int64(name) extern int64_t FLAG(name)
14#define DECLARE_double(name) extern double FLAG(name)
15#define DECLARE_string(name) extern std::string FLAG(name)
16
17// Macros for defining flags.
18#define DEFINE_bool(name, default_val, doc) bool FLAG(name) = (default_val)
19#define DEFINE_int32(name, default_val, doc) int32_t FLAG(name) = (default_val)
20#define DEFINE_int64(name, default_val, doc) int64_t FLAG(name) = (default_val)
21#define DEFINE_double(name, default_val, doc) double FLAG(name) = (default_val)
22#define DEFINE_string(name, default_val, doc) \
23 std::string FLAG(name) = (default_val)
24
25namespace benchmark {
26// Parses a bool/Int32/string from the environment variable
27// corresponding to the given Google Test flag.
28bool BoolFromEnv(const char* flag, bool default_val);
29int32_t Int32FromEnv(const char* flag, int32_t default_val);
30const char* StringFromEnv(const char* flag, const char* default_val);
31
32// Parses a string for a bool flag, in the form of either
33// "--flag=value" or "--flag".
34//
35// In the former case, the value is taken as true if it passes IsTruthyValue().
36//
37// In the latter case, the value is taken as true.
38//
39// On success, stores the value of the flag in *value, and returns
40// true. On failure, returns false without changing *value.
41bool ParseBoolFlag(const char* str, const char* flag, bool* value);
42
43// Parses a string for an Int32 flag, in the form of
44// "--flag=value".
45//
46// On success, stores the value of the flag in *value, and returns
47// true. On failure, returns false without changing *value.
48bool ParseInt32Flag(const char* str, const char* flag, int32_t* value);
49
50// Parses a string for a Double flag, in the form of
51// "--flag=value".
52//
53// On success, stores the value of the flag in *value, and returns
54// true. On failure, returns false without changing *value.
55bool ParseDoubleFlag(const char* str, const char* flag, double* value);
56
57// Parses a string for a string flag, in the form of
58// "--flag=value".
59//
60// On success, stores the value of the flag in *value, and returns
61// true. On failure, returns false without changing *value.
62bool ParseStringFlag(const char* str, const char* flag, std::string* value);
63
64// Returns true if the string matches the flag.
65bool IsFlag(const char* str, const char* flag);
66
67// Returns true unless value starts with one of: '0', 'f', 'F', 'n' or 'N', or
68// some non-alphanumeric character. As a special case, also returns true if
69// value is the empty string.
70bool IsTruthyFlagValue(const std::string& value);
71} // end namespace benchmark
72
73#endif // BENCHMARK_COMMANDLINEFLAGS_H_
74