next up previous contents index Api Refernce
Next: 6.2.1 User defined functions Up: 6 Usage Previous: 6.1 Retrieve a single

6.2 Calling functions

This C++ CmdLine library handles user defined functions of these types:

This will lead to functions like these:

void PrintHelp();
void SetInt(const int& i);
void AddStringToList(const string& s);

A function is associated with a command line option using the CmdLine::Call-function:

   aCmdLineObject.Call( "-h", PrintHelp );
   aCmdLineObject.Call( "-N", SetInt );
   aCmdLineObject.Call( "-L", AddStringToList, CmdLine::cmdMultipleArgs );

If the optional argument cmdMultipleArgs is omitted, giving multiple arguments to the command line option causes an error, and a CmdLineException is thrown.

Call is an overloaded function with these signatures:


// Call a function like f()
unsigned short cmdl::CmdLine::Call ( const char * pszOpt, 
				     void(* function)(), 
				     char options = cmdLineDefault );

// Call a function like f(const T&)
template<class T> 
unsigned short cmdl::CmdLine::Call ( const char * pszOpt, 
				     void(* function)(const T &strDest), 
				     char options = cmdLineDefault );

// Call a member function like C::function( T& )
template<class C, class T> 
unsigned short cmdl::CmdLine::Call ( const char * pszOpt, 
				     C & anObject, 
				     void(C::*function)(const T &strDest), 
				     char options = cmdLineDefault);

In the next section the first two versions of call are explained. Calling member functions - using the third version - is explained later.



Subsections
next up previous contents index Api Refernce
Next: 6.2.1 User defined functions Up: 6 Usage Previous: 6.1 Retrieve a single
Christian Neise
2003-01-12