From 0b44fc59734a92fc7276a44ddae82c6b557ef490 Mon Sep 17 00:00:00 2001 From: Jean-Louis Leroy Date: Thu, 8 May 2025 18:33:39 -0400 Subject: [PATCH] rework policies --- .gitignore | 1 + doc/BOOST_OPENMETHOD.adoc | 2 +- doc/BOOST_OPENMETHOD_CLASSES.adoc | 2 +- doc/BOOST_OPENMETHOD_DEFAULT_POLICY.adoc | 12 +- doc/basic_error_output.adoc | 4 +- doc/basic_policy.adoc | 24 +- doc/basic_trace_output.adoc | 4 +- doc/custom_rtti.adoc | 2 +- doc/error_output.adoc | 6 +- doc/html/index.html | 150 ++--- doc/initialize.adoc | 4 +- doc/method.adoc | 2 +- doc/overview.adoc | 14 +- doc/policies.adoc | 10 +- doc/reference.adoc | 6 +- doc/trace_output.adoc | 6 +- doc/type_hash.adoc | 2 +- doc/use_classes.adoc | 4 +- doc/vectored_error_handler.adoc | 2 +- doc/virtual_ptr.adoc | 26 +- doc/virtual_ptr_alt.adoc | 2 +- doc/with_vptr.adoc | 2 +- examples/accept_no_visitors.cpp | 2 +- examples/custom_rtti.cpp | 44 +- examples/deferred_custom_rtti.cpp | 68 +- examples/dl.hpp | 5 +- examples/throw_error_handler.cpp | 21 +- examples/vectored_error_handler.cpp | 4 +- examples/virtual_.cpp | 4 +- include/boost/openmethod/compiler.hpp | 229 ++++--- include/boost/openmethod/core.hpp | 625 +++++++++--------- include/boost/openmethod/default_registry.hpp | 39 ++ include/boost/openmethod/detail/trace.hpp | 75 +-- include/boost/openmethod/detail/types.hpp | 4 +- include/boost/openmethod/policies.hpp | 39 -- .../openmethod/policies/basic_policy.hpp | 160 ----- .../policies/basic_trace_output.hpp | 35 - .../openmethod/policies/fast_perfect_hash.hpp | 135 ++-- .../openmethod/policies/minimal_rtti.hpp | 2 +- .../boost/openmethod/policies/std_rtti.hpp | 58 +- ...sic_error_output.hpp => stderr_output.hpp} | 14 +- .../policies/throw_error_handler.hpp | 2 +- .../policies/vectored_error_handler.hpp | 108 +-- .../boost/openmethod/policies/vptr_map.hpp | 92 +-- .../boost/openmethod/policies/vptr_vector.hpp | 126 ++-- include/boost/openmethod/registry.hpp | 193 ++++++ include/boost/openmethod/shared_ptr.hpp | 18 +- include/boost/openmethod/unique_ptr.hpp | 14 +- include/boost/openmethod/with_vptr.hpp | 26 +- test/test_blackbox.cpp | 136 ++-- test/test_compiler.cpp | 72 +- test/test_core.cpp | 209 ++---- test/test_custom_rtti.cpp | 281 ++++---- test/test_intrusive.cpp | 8 +- test/test_policies.cpp | 74 +++ ...est_shared_virtual_ptr_value_semantics.cpp | 152 ++--- ...est_unique_virtual_ptr_value_semantics.cpp | 160 ++--- test/test_util.hpp | 13 +- test/test_virtual_ptr_dispatch.cpp | 102 +-- test/test_virtual_ptr_value_semantics.cpp | 174 ++--- test/test_virtual_ptr_value_semantics.hpp | 60 +- 61 files changed, 1994 insertions(+), 1876 deletions(-) create mode 100644 include/boost/openmethod/default_registry.hpp delete mode 100644 include/boost/openmethod/policies.hpp delete mode 100644 include/boost/openmethod/policies/basic_policy.hpp delete mode 100644 include/boost/openmethod/policies/basic_trace_output.hpp rename include/boost/openmethod/policies/{basic_error_output.hpp => stderr_output.hpp} (53%) create mode 100644 include/boost/openmethod/registry.hpp create mode 100644 test/test_policies.cpp diff --git a/.gitignore b/.gitignore index b4d4d7c..a500e63 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,4 @@ fetch_and_include/ tmpinst/ CMakeFiles/ +build/ diff --git a/doc/BOOST_OPENMETHOD.adoc b/doc/BOOST_OPENMETHOD.adoc index cc2cc8d..7b429e7 100644 --- a/doc/BOOST_OPENMETHOD.adoc +++ b/doc/BOOST_OPENMETHOD.adoc @@ -39,5 +39,5 @@ auto BOOST_OPENMETHOD_NAME(NAME)_guide(...) NOTE: `NAME` must be an *identifier*. Qualified names are not allowed. NOTE: The default value for `POLICY` is the value of -`BOOST_OPENMETHOD_DEFAULT_POLICY` at the point `` is +`BOOST_OPENMETHOD_DEFAULT_REGISTRY` at the point `` is included. Changing the value of this symbol has no effect after that point. diff --git a/doc/BOOST_OPENMETHOD_CLASSES.adoc b/doc/BOOST_OPENMETHOD_CLASSES.adoc index 91798de..c112af3 100644 --- a/doc/BOOST_OPENMETHOD_CLASSES.adoc +++ b/doc/BOOST_OPENMETHOD_CLASSES.adoc @@ -16,7 +16,7 @@ BOOST_OPENMETHOD_CLASSES(CLASSES...[, POLICY]); Register `CLASSES` in POLICY. NOTE: The default value for `POLICY` is the value of -`BOOST_OPENMETHOD_DEFAULT_POLICY` when `` is +`BOOST_OPENMETHOD_DEFAULT_REGISTRY` when `` is included. Subsequently changing it has no retroactive effect. This macro is a wrapper around `use_classes`; see its documentation for more diff --git a/doc/BOOST_OPENMETHOD_DEFAULT_POLICY.adoc b/doc/BOOST_OPENMETHOD_DEFAULT_POLICY.adoc index 4400b25..230952b 100644 --- a/doc/BOOST_OPENMETHOD_DEFAULT_POLICY.adoc +++ b/doc/BOOST_OPENMETHOD_DEFAULT_POLICY.adoc @@ -1,22 +1,22 @@ -[#BOOST_OPENMETHOD_DEFAULT_POLICY] +[#BOOST_OPENMETHOD_DEFAULT_REGISTRY] -## BOOST_OPENMETHOD_DEFAULT_POLICY +## BOOST_OPENMETHOD_DEFAULT_REGISTRY ### Description The name of the default policy. -`BOOST_OPENMETHOD_DEFAULT_POLICY` is the default value for the `Policy` template +`BOOST_OPENMETHOD_DEFAULT_REGISTRY` is the default value for the `Policy` template parameter of `method`, `use_classes`, and other constructs defined in ``. If it is not defined, -`::boost::openmethod::policy::default_policy` is used. +`::boost::openmethod::policy::default_registry` is used. -`BOOST_OPENMETHOD_DEFAULT_POLICY` can be defined by a program to change the +`BOOST_OPENMETHOD_DEFAULT_REGISTRY` can be defined by a program to change the default policy globally. Once `` has been included, redefining the symbol has no effect. To override the default policy, proceed as follows: 1. Include headers under `boost/openmethod/policies/` as needed. -2. Create a policy class, and set `BOOST_OPENMETHOD_DEFAULT_POLICY`. +2. Create a policy class, and set `BOOST_OPENMETHOD_DEFAULT_REGISTRY`. 3. Include ``. diff --git a/doc/basic_error_output.adoc b/doc/basic_error_output.adoc index d6820d7..db32928 100644 --- a/doc/basic_error_output.adoc +++ b/doc/basic_error_output.adoc @@ -9,7 +9,7 @@ Defined in . namespace boost::openmethod::policies { template -struct basic_error_output : error_output { +struct basic_error_output : output { static Stream error_stream; }; @@ -18,7 +18,7 @@ struct basic_error_output : error_output { ### Description -`basic_error_output` is an implementation of `error_output` that writes error +`basic_error_output` is an implementation of `output` that writes error messages to a `RestrictedOutputStream`. ### Members diff --git a/doc/basic_policy.adoc b/doc/basic_policy.adoc index 340c78e..1d39301 100644 --- a/doc/basic_policy.adoc +++ b/doc/basic_policy.adoc @@ -11,7 +11,7 @@ namespace policies { template struct basic_policy : abstract_policy, domain, Facets... { template - static constexpr bool has_facet = /*unspecified*/; + static constexpr bool has = /*unspecified*/; template using fork = /*unspecified*/; @@ -30,9 +30,9 @@ struct debug : release::add<...> {}; } // policies #ifdef NDEBUG -using default_policy = policies::release; +using default_registry = policies::release; #else -using default_policy = policies::debug; +using default_registry = policies::debug; #endif } // boost::openmethod @@ -55,11 +55,11 @@ allow distinct policies to have distinct sets of static variables. ### Members -#### has_facet +#### has ```c++ template -static constexpr bool has_facet; +static constexpr bool has; ``` Evaluates to `true` if _Policy_ contains _Facet_. @@ -93,14 +93,14 @@ Returns:: A new policy containing _Facets_, and the facets from the original that do not have the same category as _Facets_. Examples:: -* `struct dyn_load : default_policy::fork::with {};` + - Creates a policy just like `default_policy`, with an extra indirection added +* `struct dyn_load : default_registry::fork::with {};` + + Creates a policy just like `default_registry`, with an extra indirection added to the v-table pointers. This policy is suitable for use with dynamic loading. * `struct release_with_diags : release::fork::with> {};` + Creates a policy just like `release`, except that it prints a diagnostic message before terminating with `abort()`. -* `struct default_throw : default_policy::fork::with {};` + - Creates a policy just like `default_policy`, except that it reports errors by +* `struct default_throw : default_registry::fork::with {};` + + Creates a policy just like `default_registry`, except that it reports errors by throwing exceptions, instead of calling a `std::function` like the default error handler does. @@ -117,8 +117,8 @@ Returns:: A new policy containing the facets from the original that do not have the same category as _Facets_. Examples:: -* `struct use_map : default_policy::fork::with>::without {};` + - Creates a policy just like `default_policy`, except that it stores pointers to +* `struct use_map : default_registry::fork::with>::without {};` + + Creates a policy just like `default_registry`, except that it stores pointers to v-table in a `std::unordered_map`. Also removes the hash function, since it will not be used. @@ -145,6 +145,6 @@ The `release` policy with additional facet implementations `runtime_checks`, NOTE: `debug` extends `release` but it does not a fork it. Both policies use the same `domain`. -#### default_policy +#### default_registry An alias for `release` if `NDEBUG` is defined, and for `debug` otherwise. diff --git a/doc/basic_trace_output.adoc b/doc/basic_trace_output.adoc index 33dda4f..844cce2 100644 --- a/doc/basic_trace_output.adoc +++ b/doc/basic_trace_output.adoc @@ -9,7 +9,7 @@ Defined in . namespace boost::openmethod::policies { template -struct basic_trace_output : trace_output { +struct basic_trace_output : trace { static bool trace_enabled; static Stream trace_stream; }; @@ -19,7 +19,7 @@ struct basic_trace_output : trace_output { ### Description -`basic_error_output` is an implementation of `trace_output` that writes error +`basic_error_output` is an implementation of `trace` that writes error messages to a `RestrictedOutputStream`. ### Members diff --git a/doc/custom_rtti.adoc b/doc/custom_rtti.adoc index ec70bc4..04ff726 100644 --- a/doc/custom_rtti.adoc +++ b/doc/custom_rtti.adoc @@ -116,7 +116,7 @@ CRTP template: include::{examplesdir}/custom_rtti.cpp[tag=policy] ---- -Next, we include the main header. Because `BOOST_OPENMETHOD_DEFAULT_POLICY` is +Next, we include the main header. Because `BOOST_OPENMETHOD_DEFAULT_REGISTRY` is defined, its value is used for the default policy. Then comes the usual example. [source,c++] diff --git a/doc/error_output.adoc b/doc/error_output.adoc index 6ec1dea..e851931 100644 --- a/doc/error_output.adoc +++ b/doc/error_output.adoc @@ -1,5 +1,5 @@ -## error_output +## output ### Synopsis @@ -8,14 +8,14 @@ Defined in . ```c++ namespace boost::openmethod::policies { -struct error_output : facet {}; +struct output : facet {}; } // boost::openmethod::policies ``` ### Description -`error_output` is a facet that provides a stream for writing error messages. +`output` is a facet that provides a stream for writing error messages. ### Requirements diff --git a/doc/html/index.html b/doc/html/index.html index 320cffa..a0bb1ec 100644 --- a/doc/html/index.html +++ b/doc/html/index.html @@ -537,7 +537,7 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
  • Description
  • -
  • BOOST_OPENMETHOD_DEFAULT_POLICY +
  • BOOST_OPENMETHOD_DEFAULT_REGISTRY @@ -733,7 +733,7 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
  • Members
  • -
  • error_output +
  • output
    • Synopsis
    • Description
    • @@ -747,7 +747,7 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
    • Members
  • -
  • trace_output +
  • trace