MocoExtendProblem: Interface Between OpenSim and MATLAB for Rapidly Developing Direct Collocation Goals in Moco 1.1.0
add custom Moco goals to existing matlab scripts
InputArguments Class Reference

Utility to parse input arguments. More...

#include <arguments.h>

Classes

struct  CaseInsensitiveComparator
 Case-insensitive comparator for std::string. More...
 

Public Types

typedef std::map< std::string, const mxArray *, CaseInsensitiveComparatorOptionMap
 

Public Member Functions

 InputArguments ()
 Empty constructor.
 
 InputArguments (int nrhs, const mxArray *prhs[], int mandatory_size=1, int option_size=0,...)
 Shorthand constructor for a single argument definition.
 
virtual ~InputArguments ()
 
void define (const std::string name, int mandatory_size, int option_size=0,...)
 Define a new argument format.
 
void parse (int nrhs, const mxArray *prhs[], bool ignore_multi_signatures=false)
 Parse arguments from mexFunction input.
 
bool is (const std::string &name) const
 Return which format is chosen.
 
const mxArray * get (size_t index) const
 Get a parsed mandatory argument.
 
template<typename T >
get (size_t index) const
 Get a parsed mandatory argument.
 
template<typename T >
void get (size_t index, T *value) const
 
const mxArray * get (const std::string &option_name) const
 Get a parsed optional argument.
 
template<typename T >
get (const std::string &option_name, const T &default_value) const
 Get a parsed optional argument.
 
template<typename T >
void get (const std::string &option_name, const T &default_value, T *value) const
 
const mxArray * operator[] (size_t index) const
 Access raw mxArray* pointer.
 
const mxArray * operator[] (const std::string &option_name) const
 Access raw mxArray* pointer.
 

Private Member Functions

void fillOptionalDefinition (int option_size, OptionMap *optionals, va_list variable_list)
 Fill in optional arguments definition.
 
bool parseDefinition (size_t nrhs, const mxArray *prhs[], Definition *definition)
 Try to parse one definition or return false on failure.
 

Private Attributes

std::map< std::string, Definitiondefinitions_
 Format definitions.
 
std::string error_message_
 Last error message.
 

Detailed Description

Utility to parse input arguments.

Example: parse 2 mandatory and 2 optional arguments.

InputArguments input(nrhs, prhs, 2, 2, "option1", "option2");
myFunction2(input.get<double>(0),
            input.get<int>(1),
            input.get<string>("option1", "foo"),
            input.get<int>("option2", 10));

Example: parse 1 + 2 argument format or 2 + 2 argument format.

InputArguments input;
input.define("format1", 1, 2, "option1", "option2");
input.define("format2", 2, 2, "option1", "option2");
input.parse(nrhs, prhs);
if (input.is("format1"))
    myFunction(input.get<int>(0),
               input.get<string>("option1", "foo"),
               input.get<int>("option2", 10));
else if (input.is("format2"))
    myFunction2(input.get<int>(0),
                input.get<string>(1),
                input.get<string>("option1", "foo"),
                input.get<int>("option2", 10));

Member Typedef Documentation

◆ OptionMap

typedef std::map<std::string, const mxArray*, CaseInsensitiveComparator> OptionMap

Constructor & Destructor Documentation

◆ InputArguments() [1/2]

InputArguments ( )
inline

Empty constructor.

◆ InputArguments() [2/2]

InputArguments ( int nrhs,
const mxArray * prhs[],
int mandatory_size = 1,
int option_size = 0,
... )
inline

Shorthand constructor for a single argument definition.

Here is the call graph for this function:

◆ ~InputArguments()

virtual ~InputArguments ( )
inlinevirtual

Member Function Documentation

◆ define()

void define ( const std::string name,
int mandatory_size,
int option_size = 0,
... )
inline

Define a new argument format.

Here is the call graph for this function:

◆ fillOptionalDefinition()

void fillOptionalDefinition ( int option_size,
OptionMap * optionals,
va_list variable_list )
inlineprivate

Fill in optional arguments definition.

Here is the caller graph for this function:

◆ get() [1/6]

const mxArray * get ( const std::string & option_name) const
inline

Get a parsed optional argument.

◆ get() [2/6]

template<typename T >
T get ( const std::string & option_name,
const T & default_value ) const

Get a parsed optional argument.

Here is the call graph for this function:

◆ get() [3/6]

template<typename T >
void get ( const std::string & option_name,
const T & default_value,
T * value ) const
Here is the call graph for this function:

◆ get() [4/6]

const mxArray * get ( size_t index) const
inline

Get a parsed mandatory argument.

Here is the caller graph for this function:

◆ get() [5/6]

template<typename T >
T get ( size_t index) const

Get a parsed mandatory argument.

Here is the call graph for this function:

◆ get() [6/6]

template<typename T >
void get ( size_t index,
T * value ) const
Here is the call graph for this function:

◆ is()

bool is ( const std::string & name) const
inline

Return which format is chosen.

◆ operator[]() [1/2]

const mxArray * operator[] ( const std::string & option_name) const
inline

Access raw mxArray* pointer.

Here is the call graph for this function:

◆ operator[]() [2/2]

const mxArray * operator[] ( size_t index) const
inline

Access raw mxArray* pointer.

Here is the call graph for this function:

◆ parse()

void parse ( int nrhs,
const mxArray * prhs[],
bool ignore_multi_signatures = false )
inline

Parse arguments from mexFunction input.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parseDefinition()

bool parseDefinition ( size_t nrhs,
const mxArray * prhs[],
Definition * definition )
inlineprivate

Try to parse one definition or return false on failure.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ definitions_

std::map<std::string, Definition> definitions_
private

Format definitions.

◆ error_message_

std::string error_message_
private

Last error message.


The documentation for this class was generated from the following file: