Policies and Facets
Methods and classes are scoped in a policy. A method can only reference classes registered in the same policy. If a class is used as a virtual parameter in methods using different policies, it must be registered with each of them.
Class templates use_classes
, method
, virtual_ptr
, and macros
BOOST_OPENMETHOD
and BOOST_OPENMETHOD_CLASSES
, accept an additional
argument, a policy class, which defaults to policies::debug
in debug builds,
and policies::release
in release builds.
A policy has a collection of facets. Each facet belongs to a facet category. A
policy may contain at most one facet of a given category. Facets control how
type information is obtained, how vptrs are fetched, how errors are handled and
printed, etc. Some are used in initialize
and method dispatch; some are used
by other facets in the same policy as part of their implementation. See the
reference for the list of facets. Policies and facets are placed in the
boost::openmethod::policies
namespace. Two stock policies are provided by the
library: release
and debug
.
The release
policy contains the following facets:
facet category | facet | role |
---|---|---|
rtti |
std_rtti |
provides type information for classes and objects |
extern_vptr |
vptr_vector |
stores vptrs in an indexed collection |
type_hash |
fast_perfect_hash |
hash type id to an index in a vector |
error_handler |
default_error_handler |
handles errors |
The debug
policy contains the same facets as release
, plus a few more:
facet category | facet | role |
---|---|---|
runtime_checks |
(itself) |
enables runtime checks |
output |
basic_error_output |
prints error descriptions to |
trace |
basic_trace_output |
enables |
Policies, and some facets, have static variables. When it is the case, they are implemented as CRTP classes.
Policies can be created from scratch, using the basic_policy
template, or
constructed from existing policies by adding and removing facets. For example,
policies::debug
is a tweak of policies::release
:
namespace boost::openmethod::policies {
struct debug : release::fork<debug>::with<
runtime_checks, basic_error_output<debug>,
basic_trace_output<debug>> {};
}
boost::openmethod::default_registry
is an alias to release
or debug
,
depending on the value of preprocessor symbols NDEBUG
. The default policy can
be overriden by defining the macroprocessor symbol
BOOST_OPENMETHOD_DEFAULT_REGISTRY
before including
<boost/openmethod/core.hpp>
. The value of the symbol is used as a default
template parameter for use_classes
, method
, virtual_ptr
, and others. Once
the core
header has been included, changing BOOST_OPENMETHOD_DEFAULT_REGISTRY
has no effect.