From 8da85a9c39fa8ba721dddb0ab54ca8c619ecb682 Mon Sep 17 00:00:00 2001 From: Guillaume Racicot Date: Sat, 3 Aug 2019 23:56:43 -0400 Subject: [PATCH] Added a whole bunch of comments --- include/kangaru/detail/default_source.hpp | 8 +++++++ include/kangaru/detail/injected.hpp | 8 +++++++ .../detail/operator_service_helper.hpp | 8 +++++++ include/kangaru/detail/service_storage.hpp | 18 ++++++++++++--- include/kangaru/detail/single.hpp | 22 +++++++++++++++++++ include/kangaru/detail/utils.hpp | 5 ++++- include/kangaru/type_id.hpp | 10 +++++++++ 7 files changed, 75 insertions(+), 4 deletions(-) diff --git a/include/kangaru/detail/default_source.hpp b/include/kangaru/detail/default_source.hpp index 37593ce8..f92ebd90 100644 --- a/include/kangaru/detail/default_source.hpp +++ b/include/kangaru/detail/default_source.hpp @@ -21,6 +21,11 @@ namespace kgr { namespace detail { +/* + * Primary storage for services in the container. + * + * Also manages override meta information. + */ struct default_source { private: using alias_t = void*; @@ -152,6 +157,9 @@ struct default_source { ~default_source() = default; #endif + /* + * Adds a service in the service source + */ template auto emplace(Args&&... args) -> single_insertion_result_t { auto instance_ptr = make_instance_ptr(std::forward(args)...); diff --git a/include/kangaru/detail/injected.hpp b/include/kangaru/detail/injected.hpp index a5462cec..707a37e0 100644 --- a/include/kangaru/detail/injected.hpp +++ b/include/kangaru/detail/injected.hpp @@ -107,9 +107,17 @@ using injected_wrapper = typename std::conditional::value, injected >::type; +/* + * Gets the type of an argument of a wrapped service + */ template using injected_argument_t = injected_service_t>; +/* + * Traits that create a type which hold information about the insertion of a single service + * + * The insertion result is a tuple of typed service storage for the service itself and all its overrides + */ template struct single_insertion_result; diff --git a/include/kangaru/detail/operator_service_helper.hpp b/include/kangaru/detail/operator_service_helper.hpp index cd73f5ba..ad00bbec 100644 --- a/include/kangaru/detail/operator_service_helper.hpp +++ b/include/kangaru/detail/operator_service_helper.hpp @@ -9,6 +9,9 @@ struct all; namespace detail { +/* + * Forward declaration of services defined in operator_service.hpp + */ template struct forked_operator_service; @@ -18,6 +21,11 @@ struct operator_service; struct operator_base; struct forked_operator_base; +/* + * Indirect map that generate a service definition for an operator service + * + * It will choose between operator_service and forked_operator_service dependening on the operator_base type + */ template struct select_operator_service; diff --git a/include/kangaru/detail/service_storage.hpp b/include/kangaru/detail/service_storage.hpp index 7e747421..d8c899b6 100644 --- a/include/kangaru/detail/service_storage.hpp +++ b/include/kangaru/detail/service_storage.hpp @@ -19,17 +19,24 @@ struct forward_storage { forward_ptr forward; }; +/* + * Pair of a pointer to a service and it's forward function + * Used to passe around a type erase service that yield a particular type + */ template struct typed_service_storage { void* service; forward_ptr forward; }; -template -struct override_type_id {}; - +/* + * Tag type to tell service_storage that its supposed to contain an index of an override + */ struct override_index_t {} constexpr override_index{}; +/* + * Type erased storage for any service type or an override index + */ struct service_storage { private: using function_pointer = void*(*)(void*); @@ -82,6 +89,11 @@ struct service_storage { aligned_storage_t forward_function; }; +/* + * A non moveable and non copyable type wrapper for a service + * + * Also conveniently choose the right constructor + */ template struct memory_block { memory_block(memory_block const&) = delete; diff --git a/include/kangaru/detail/single.hpp b/include/kangaru/detail/single.hpp index fee36dd9..f30051f9 100644 --- a/include/kangaru/detail/single.hpp +++ b/include/kangaru/detail/single.hpp @@ -7,6 +7,11 @@ namespace kgr { +/* + * Tag base class to identify a single service + * + * Also disable copy construction + */ struct single { single() = default; ~single() = default; @@ -16,16 +21,25 @@ struct single { single& operator=(single&&) = default; }; +/* + * Bunch of other tag types for various features + */ struct polymorphic {}; struct final {}; struct supplied {}; struct abstract : polymorphic, single {}; +/* + * Mixin for abstract service to set the default implementation + */ template struct defaults_to { using default_service = T; }; +/* + * Used to list all types a service should override when constructing + */ template struct overrides { using parent_types = detail::meta_list; @@ -33,6 +47,9 @@ struct overrides { namespace detail { +/* + * Type trait to either get the specified overrides or an empty list + */ template struct parent_type_helper { using parent_types = meta_list<>; @@ -46,6 +63,11 @@ struct parent_type_helper> { template using parent_types = typename parent_type_helper::parent_types; +/* + * Type trait to either get the default implementation type of an abstract serivce + * + * Also tell if there is a default or not + */ template struct default_type_helper { using has_default = std::false_type; diff --git a/include/kangaru/detail/utils.hpp b/include/kangaru/detail/utils.hpp index c2eabfc6..143adab7 100644 --- a/include/kangaru/detail/utils.hpp +++ b/include/kangaru/detail/utils.hpp @@ -6,6 +6,10 @@ namespace kgr { namespace detail { +/* + * Dependent type false + * Useful for static asserts + */ template struct to_false { using type = std::false_type; @@ -20,7 +24,6 @@ using false_t = typename to_false::type; template using bool_constant = std::integral_constant; - /* * Simple alias to member type `value_type` * Used mostly for detection. diff --git a/include/kangaru/type_id.hpp b/include/kangaru/type_id.hpp index 717c962e..6ee24cfb 100644 --- a/include/kangaru/type_id.hpp +++ b/include/kangaru/type_id.hpp @@ -7,17 +7,27 @@ namespace kgr { namespace detail { +/* + * Declaration of built-in private service types. + */ template struct index_storage; struct override_storage_service; +/* + * Trait that identify if some type is an index_storage + */ template struct is_index_storage : std::false_type {}; template struct is_index_storage> : std::true_type {}; +/* + * We need to have a small amount of static data in order to + * get it's pointer. We reuse that space to store meta information. + */ struct type_id_data { enum struct kind_t : std::uint8_t { normal, override_storage, index_storage } kind;