1 #ifndef REMOTE_UTIL_CONFIG_H
2 #define REMOTE_UTIL_CONFIG_H
11 namespace remote
{ namespace util
{
13 /** Configuration handling.
15 * This class reads options from the command line and from a
21 /** Option value type. */
23 ALIAS
, /**< Alias option type. */
24 BOOL
, /**< Boolean option type. */
25 STRING
, /**< String option type. */
26 UINT16
, /**< Unsigned 16-bit integer option type. */
27 UINT64
, /**< Unsigned 64-bit integer option type. */
28 HELP
, /**< Special type for handling the --help option. */
29 VERSION
/**< Special type for handling the --version option. */
32 /** Initial the configuration module for a program
34 * @param program The program name.
35 * @param configFile The default path to the configuration file.
37 Config(std::string program
, std::string configFile
);
39 /** Add boolean option.
41 * @param name The option name.
42 * @param value Reference to the option value.
43 * @param help A short option description.
45 void operator()(std::string name
, bool *value
, std::string help
);
47 /** Add uint16 option.
49 * @param name The option name.
50 * @param value Reference to the option value.
51 * @param help A short option description.
53 void operator()(std::string name
, uint16_t *value
, std::string help
);
55 /** Add uint64 option.
57 * @param name The option name.
58 * @param value Reference to the option value.
59 * @param help A short option description.
61 void operator()(std::string name
, uint64_t *value
, std::string help
);
63 /** Add string option.
65 * @param name The option name.
66 * @param value Reference to the option value.
67 * @param help A short option description.
69 void operator()(std::string name
, std::string
*value
, std::string help
);
71 /** Add alias to an existing option.
73 * @param name The name of the alias.
74 * @param alias The name of the aliased option.
76 void operator()(std::string name
, std::string alias
);
78 /** Read options from command line and configuration file.
80 * @param argc Number of command line arguments.
81 * @param argv String array of command line arguments.
82 * @return True if reading options succeeded.
84 bool read(int argc
, char **argv
);
89 /** Read options from file.
91 * @param name Name of configuration file.
92 * @param fail Whether to error out if opening the file fails.
93 * @return True if parsing the file succeeded.
95 bool parseFile(std::string name
, bool fail
);
97 /** Parse option name and value.
99 * @param name The option name.
100 * @param value The option value to parse.
101 * @return True if parsing the option succeeded.
103 bool parseOption(std::string name
, std::string value
);
105 /** Print usage help and option descriptions. */
108 /** Lookup an option by name.
110 * @param name Name of the option to get.
111 * @return The matching option or NULL if no option matched.
113 Option
*get(std::string name
);
115 /** Lookup an option by name.
117 * @param name Name of the option to add.
118 * @param help A short option description.
119 * @param type The type of the option.
120 * @return The newly added option or NULL.
122 Option
*add(std::string name
, std::string help
, enum type type
);
124 std::list
<Option
*> options
; /**< List of known options. */
125 std::string program
; /**< The program name. */
126 std::string configFile
; /**< The config file option string. */