Skip to content

Commit

Permalink
Added a whole bunch of comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gracicot committed Aug 4, 2019
1 parent 5aff6fa commit 8da85a9
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 4 deletions.
8 changes: 8 additions & 0 deletions include/kangaru/detail/default_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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*;
Expand Down Expand Up @@ -152,6 +157,9 @@ struct default_source {
~default_source() = default;
#endif

/*
* Adds a service in the service source
*/
template<typename T, typename... Parents, typename... Args>
auto emplace(Args&&... args) -> single_insertion_result_t<T> {
auto instance_ptr = make_instance_ptr<T>(std::forward<Args>(args)...);
Expand Down
8 changes: 8 additions & 0 deletions include/kangaru/detail/injected.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,17 @@ using injected_wrapper = typename std::conditional<is_polymorphic<T>::value,
injected<T>
>::type;

/*
* Gets the type of an argument of a wrapped service
*/
template<std::size_t n, typename F>
using injected_argument_t = injected_service_t<function_argument_t<n, F>>;

/*
* 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<typename, typename>
struct single_insertion_result;

Expand Down
8 changes: 8 additions & 0 deletions include/kangaru/detail/operator_service_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ struct all;

namespace detail {

/*
* Forward declaration of services defined in operator_service.hpp
*/
template<typename, typename>
struct forked_operator_service;

Expand All @@ -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<typename>
struct select_operator_service;

Expand Down
18 changes: 15 additions & 3 deletions include/kangaru/detail/service_storage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,24 @@ struct forward_storage {
forward_ptr<T> 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<typename T>
struct typed_service_storage {
void* service;
forward_ptr<T> forward;
};

template<typename>
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*);
Expand Down Expand Up @@ -82,6 +89,11 @@ struct service_storage {
aligned_storage_t<sizeof(function_pointer), alignof(function_pointer)> forward_function;
};

/*
* A non moveable and non copyable type wrapper for a service
*
* Also conveniently choose the right constructor
*/
template<typename T>
struct memory_block {
memory_block(memory_block const&) = delete;
Expand Down
22 changes: 22 additions & 0 deletions include/kangaru/detail/single.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

namespace kgr {

/*
* Tag base class to identify a single service
*
* Also disable copy construction
*/
struct single {
single() = default;
~single() = default;
Expand All @@ -16,23 +21,35 @@ 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<typename T>
struct defaults_to {
using default_service = T;
};

/*
* Used to list all types a service should override when constructing
*/
template<typename... Types>
struct overrides {
using parent_types = detail::meta_list<Types...>;
};

namespace detail {

/*
* Type trait to either get the specified overrides or an empty list
*/
template<typename, typename = void>
struct parent_type_helper {
using parent_types = meta_list<>;
Expand All @@ -46,6 +63,11 @@ struct parent_type_helper<T, void_t<typename T::parent_types>> {
template<typename T>
using parent_types = typename parent_type_helper<T>::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<typename, typename = void>
struct default_type_helper {
using has_default = std::false_type;
Expand Down
5 changes: 4 additions & 1 deletion include/kangaru/detail/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
namespace kgr {
namespace detail {

/*
* Dependent type false
* Useful for static asserts
*/
template<typename...>
struct to_false {
using type = std::false_type;
Expand All @@ -20,7 +24,6 @@ using false_t = typename to_false<Ts...>::type;
template<bool b>
using bool_constant = std::integral_constant<bool, b>;


/*
* Simple alias to member type `value_type`
* Used mostly for detection.
Expand Down
10 changes: 10 additions & 0 deletions include/kangaru/type_id.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,27 @@
namespace kgr {
namespace detail {

/*
* Declaration of built-in private service types.
*/
template<typename>
struct index_storage;

struct override_storage_service;

/*
* Trait that identify if some type is an index_storage
*/
template<typename>
struct is_index_storage : std::false_type {};

template<typename T>
struct is_index_storage<index_storage<T>> : 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;

Expand Down

0 comments on commit 8da85a9

Please sign in to comment.