BOOST_OPENMETHOD
Declare a method.
Synopsis
Declared in <boost/openmethod/macros.hpp>
#define BOOST_OPENMETHOD(ID, PARAMETERS, …)
Description
Declares a method, called ID, with the given parameters and return type, and adds it to a registry.
PARAMETERS is a comma‐separated list of types, possibly followed by parameter names, just like in a function declaration. Parameters with a type in the form virtual_ptr<T> or virtual_<T> are called virtual parameters. The dynamic type of the arguments passed in virtual parameters determines which overrider to call, following the same rules as overloaded function resolution:
-
Form the set of all applicable overriders. An overrider is applicable if it can be called with the arguments passed to the method.
-
If the set is empty, call the error handler (if present in the registry), then terminate the program with
abort. -
Remove the overriders that are dominated by other overriders in the set. Overrider A dominates overrider B if any of its virtual formal parameters is more specialized than B's, and if none of B's virtual parameters is more specialized than A's.
-
If the resulting set contains exactly one overrider, call it.
If a single most specialized overrider does not exist, the program is terminated via abort. If the registry contains an error_handler policy, its error function is called with an object that describes the error, prior to calling abort. error may prevent termination by throwing an exception.
For each virtual argument arg, the dispatch mechanism calls virtual_traits::peek(arg) and deduces the v‐table pointer from the result, using the first of the following methods that applies:
-
If
resultis avirtual_ptr, get the pointer to the v‐table from it. -
If boost_openmethod_vptr can be called with
resultand aRegistry*, and it returns avptr_type, call it. -
Call the dynamic_vptr of the registry's
vptrpolicy.
The macro creates an ordinary inline function in the current scope, with the virtual_ decorators removed from the parameter types. virtual_ptr parameters are preserved.
|
|
|
The default registry is the value of |
Example
See BOOST_OPENMETHOD_OVERRIDE for an example.
Implementation Notes
The macro creates several additional constructs:
-
A
structforward declaration that acts as the method's identifier:
struct BOOST_OPENMETHOD_ID(ID);
-
A class template declaration that acts as a container for the method's overriders in the current scope:
template<typename...> struct BOOST_OPENMETHOD_OVERRIDERS(ID);
-
A guide function used to match overriders with the method:
auto BOOST_OPENMETHOD_ID(ID)_guide(...)
-> ::boost::openmethod::method<
BOOST_OPENMETHOD_ID(ID)(PARAMETERS...), RETURN_TYPE [, REGISTRY]>;
-
A registrar (see
BOOST_OPENMETHOD_REGISTER) that adds the method to the registry.
Parameters
Name |
Description |
ID |
The method's name. |
PARAMETERS |
The method's parameter list, in parentheses. |
... |
The method's return type, optionally followed by the registry. |
See Also
Created with MrDocs