Rice  1.5.2
 All Classes Files Functions Variables Typedefs Friends Pages
Classes | Public Member Functions | Public Attributes | List of all members
Rice::Arg Class Reference

Helper for defining default arguments of a method. More...

#include <Arg_impl.hpp>

Public Member Functions

 Arg (const char *name)
 Initialize a new Arg with the name of the argument. More...
 
 Arg (const Arg &other)
 Copy Constructor.
 
template<typename Arg_Type >
Argoperator= (Arg_Type val)
 Set the default value for this Arg. More...
 
bool hasDefaultValue () const
 Check if this Arg has a default value associated with it.
 
template<typename Arg_Type >
Arg_Type getDefaultValue ()
 Return the default value associated with this Arg. More...
 
const char * name () const
 Get the name of this Arg.
 

Public Attributes

type_base * defaultValue
 Our saved default value.
 

Detailed Description

Helper for defining default arguments of a method.

This class exposes the ability to define the default values of a wrapped method. Inspired by how Boost.Python handles keyword and default arguments, the syntax is simple:

* define_method(
* "method",
* &method,
* (Arg("arg1"), Arg("arg2") = 3, Arg("arg3") = true)
* );
*

which means "for method &method, it takes 3 arguments [arg1, arg2, arg3]. Of these arguments, arg2's default is 3 and arg3's default is true.

It may be required to explicitly cast the type of the default value to prevent compilation errors.

Constructor & Destructor Documentation

Rice::Arg::Arg ( const char *  name)
inline

Initialize a new Arg with the name of the argument.

We require the name of the argument because 1) it makes code easier to read and 2) hopefully Ruby gets keyword arguments in the future and this means Rice will be ready for it.

Member Function Documentation

template<typename Arg_Type >
Arg_Type Rice::Arg::getDefaultValue ( )
inline

Return the default value associated with this Arg.

Returns
the type saved to this Arg

References defaultValue.

template<typename Arg_Type >
Arg& Rice::Arg::operator= ( Arg_Type  val)
inline

Set the default value for this Arg.

Set the default value for this argument. If this isn't called on this Arg, then this Arg is required in the method call.

Parameters
valthe value to store as default

References defaultValue.


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