20 #ifndef COMMAND_LINE_H
21 #define COMMAND_LINE_H
178 void Usage (
const std::string usage);
189 template <
typename T>
190 void AddValue (
const std::string &name,
191 const std::string &help,
206 void AddValue (
const std::string &name,
207 const std::string &help,
224 void Parse (
int argc,
char *argv[]);
267 virtual bool Parse (
const std::string value) = 0;
282 template <
typename T>
292 virtual bool Parse (
const std::string value);
314 virtual bool Parse (
const std::string value);
325 void HandleArgument (
const std::string &name,
const std::string &value)
const;
333 void PrintAttributes (std::ostream &os,
const std::string &type)
const;
367 namespace CommandLineHelper {
378 template <
typename T>
392 template <
typename T>
406 template <
typename T>
409 const std::string &help,
417 std::stringstream ss;
425 template <
typename T>
432 template <
typename T>
436 return CommandLineHelper::GetDefault<T> (*m_valuePtr);
439 template <
typename T>
443 std::ostringstream oss;
449 template <
typename T>
453 return CommandLineHelper::UserItemParse<T> (value, *m_valuePtr);
456 template <
typename T>
460 std::istringstream iss;
463 return !iss.bad () && !iss.fail ();
~CommandLine()
Destructor.
T * m_valuePtr
Pointer to the POD location.
Items m_items
The list of arguments.
std::string m_default
String representation of default value.
void PrintGlobals(std::ostream &os) const
Handler for --PrintGlobals: print all global variables and values.
virtual bool Parse(const std::string value)
Parse from a string.
An argument Item assigning to POD.
virtual bool Parse(const std::string value)=0
Parse from a string.
std::string GetDefault< bool >(const bool &val)
Helper to specialize UserItem::GetDefault on bool.
std::list< Item * > Items
Argument list container.
std::string GetName() const
Get the program name.
void Usage(const std::string usage)
Supply the program usage and documentation.
void Clear(void)
Remove all arguments, Usage(), name.
void PrintAttributes(std::ostream &os, const std::string &type) const
Handler for --PrintAttributes: print the attributes for a given type.
An argument Item using a Callback to parse the input.
void PrintHelp(std::ostream &os) const
Print program usage to the desired output stream.
std::string m_usage
The Usage string.
virtual std::string GetDefault() const
std::string m_name
The program name.
Parse command-line arguments.
virtual bool Parse(const std::string value)
Parse from a string.
void PrintGroups(std::ostream &os) const
Handler for --PrintGroups: print all TypeId group names.
std::string GetDefault(const T &val)
Helper to specialize UserItem::GetDefault on bool.
CommandLine & operator=(const CommandLine &cmd)
Assignment.
std::string m_name
Argument label: ---m_name=...
bool UserItemParse< bool >(const std::string value, bool &val)
Helper to specialize UserItem::Parse on bool.
Callback< bool, std::string > m_callback
The Callback.
virtual bool HasDefault() const
virtual ~Item()
Destructor.
std::string m_help
Argument help string.
CommandLine()
Constructor.
void AddValue(const std::string &name, const std::string &help, T &value)
Add a program argument, assigning to POD.
std::string GetDefault() const
void PrintTypeIds(std::ostream &os) const
Handler for --PrintTypeIds: print all TypeId names.
void Copy(const CommandLine &cmd)
Copy constructor.
void PrintGroup(std::ostream &os, const std::string &group) const
Handler for --PrintGroup: print all types belonging to a given group.
void Parse(int argc, char *argv[])
Parse the program arguments.
bool UserItemParse(const std::string value, T &val)
Helper to specialize UserItem::Parse on bool.
void HandleArgument(const std::string &name, const std::string &value) const
Match name against the program or general arguments, and dispatch to the appropriate handler...