Skip to content

Commit 9d249b5

Browse files
authored
🧼🧽 Clean function signatures and doxygen (#19)
- Clean up function signatures, variable names, template names, and doxygen. - Move more details to detail folder and namespace.
1 parent 506910a commit 9d249b5

File tree

16 files changed

+713
-410
lines changed

16 files changed

+713
-410
lines changed

include/cib/builder_meta.hpp

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,33 @@
1-
#include "detail/compiler.hpp"
2-
3-
#include <utility>
4-
5-
61
#ifndef COMPILE_TIME_INIT_BUILD_BUILDER_META_HPP
72
#define COMPILE_TIME_INIT_BUILD_BUILDER_META_HPP
83

94

105
namespace cib {
6+
/**
7+
* Describe a builder to cib.
8+
*
9+
* @tparam BuilderType
10+
* The initial builder type cib should use when creating a builder.
11+
* This is only the initial type, the BuilderType::add(...) function
12+
* may return a different type and cib will track that correctly.
13+
*
14+
* @tparam InterfaceType
15+
* The type-erased interface services built with this builder
16+
* will implement. For example, cib::callback allows many other
17+
* callables to get executed when its service gets invoked. The
18+
* type-erased interface for cib::callback is a function pointer.
19+
*
20+
* @see cib::built
21+
*
22+
* @example cib::callback_meta
23+
*/
1124
template<
12-
typename BuilderT,
13-
typename InterfaceT>
25+
typename BuilderType,
26+
typename InterfaceType>
1427
struct builder_meta {
15-
BuilderT builder();
16-
InterfaceT interface();
28+
BuilderType builder();
29+
InterfaceType interface();
1730
};
18-
19-
namespace traits {
20-
template<typename MetaT>
21-
struct builder {
22-
using type = decltype(std::declval<MetaT>().builder());
23-
};
24-
25-
template<typename MetaT>
26-
using builder_t = typename builder<MetaT>::type;
27-
28-
template<typename MetaT>
29-
CIB_CONSTEXPR builder_t<MetaT> builder_v = {};
30-
31-
template<typename MetaT>
32-
struct interface {
33-
using type = decltype(std::declval<MetaT>().interface());
34-
};
35-
36-
template<typename MetaT>
37-
using interface_t = typename interface<MetaT>::type;
38-
}
3931
}
4032

4133

include/cib/built.hpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
#include "builder_meta.hpp"
2-
2+
#include "detail/builder_traits.hpp"
33

44
#ifndef COMPILE_TIME_INIT_BUILD_BUILT_HPP
55
#define COMPILE_TIME_INIT_BUILD_BUILT_HPP
66

77

88
namespace cib {
99
/**
10-
* Pointer to a concrete built service.
10+
* Pointer to a built service implementation.
11+
*
12+
* @tparam ServiceMeta
13+
* Tag name of the service.
1114
*
12-
* @tparam Tag Type name of the service.
15+
* @see cib::builder_meta
1316
*/
14-
template<typename Tag>
15-
traits::interface_t<Tag> built;
17+
template<typename ServiceMeta>
18+
traits::interface_t<ServiceMeta> service;
1619
}
1720

1821

include/cib/callback.hpp

Lines changed: 79 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,41 +12,63 @@
1212

1313
namespace cib {
1414
/**
15-
* Extension point/builder for simple callbacks.
15+
* Builder for simple callbacks.
1616
*
17-
* Modules can add their own callback function to this builder to be executed when
18-
* the builder is executed with the same function arguments.
17+
* Components can add their own callback function to this builder to be
18+
* executed when the service is executed with the same function arguments.
1919
*
20-
* @tparam Size
21-
* Maximum number of callbacks that may be registered.
20+
* @tparam NumFuncs
21+
* The number of functions currently registered with this builder.
2222
*
23-
* @tparam Args
23+
* @tparam ArgTypes
2424
* List of argument types that must be passed into the callback when it is invoked.
25+
*
26+
* @see cib::callback_meta
2527
*/
26-
template<int Size = 0, typename... Args>
28+
template<int NumFuncs = 0, typename... ArgTypes>
2729
struct callback {
2830
private:
29-
using func_ptr_t = void(*)(Args...);
31+
using func_ptr_t = void(*)(ArgTypes...);
3032

31-
std::array<func_ptr_t, Size> funcs;
33+
std::array<func_ptr_t, NumFuncs> funcs;
3234

35+
/**
36+
* Runtime implementation of a callback service.
37+
*
38+
* Calls each registered function in an undefined order. The order
39+
* functions are called should not be depended upon and could
40+
* change from one release to the next.
41+
*
42+
* This function will be available from nexus::builder<...> or
43+
* cib::built<...>.
44+
*
45+
* @tparam BuilderValue
46+
* A type that contains a constexpr static value field with the
47+
* fully initialized callback builder.
48+
*
49+
* @param args
50+
* The arguments to be passed to every registered function.
51+
*
52+
* @see cib::nexus
53+
* @see cib::built
54+
*/
3355
template<typename BuilderValue>
34-
static void run(Args... args) {
35-
CIB_CONSTEXPR auto handlerBuilder = BuilderValue::value;
36-
CIB_CONSTEXPR auto numFuncs = std::integral_constant<int, Size>{};
56+
static void run(ArgTypes... args) {
57+
CIB_CONSTEXPR auto handler_builder = BuilderValue::value;
58+
CIB_CONSTEXPR auto num_funcs = std::integral_constant<int, NumFuncs>{};
3759

38-
detail::for_each(numFuncs, [&](auto i){
39-
CIB_CONSTEXPR auto func = handlerBuilder.funcs[i];
60+
detail::for_each(num_funcs, [&](auto i){
61+
CIB_CONSTEXPR auto func = handler_builder.funcs[i];
4062
func(args...);
4163
});
4264
}
4365

4466
public:
4567
CIB_CONSTEVAL callback() = default;
4668

47-
template<typename PrevFuncsT>
69+
template<typename PrevFuncsType>
4870
CIB_CONSTEVAL callback(
49-
PrevFuncsT const & prev_funcs,
71+
PrevFuncsType const & prev_funcs,
5072
func_ptr_t new_func
5173
)
5274
: funcs{}
@@ -55,36 +77,67 @@ namespace cib {
5577
funcs[i] = prev_funcs[i];
5678
}
5779

58-
funcs[Size - 1] = new_func;
80+
funcs[NumFuncs - 1] = new_func;
5981
}
6082

61-
// cib uses "add(...)" to add features to service builders
62-
CIB_CONSTEVAL auto add(func_ptr_t const & func) const {
63-
return callback<Size + 1, Args...>{funcs, func};
83+
/**
84+
* Add a function to be executed when the callback service is invoked.
85+
*
86+
* Do not call this function directly. The library will add functions
87+
* to service builders based on a project's cib::config and cib::extend
88+
* declarations.
89+
*
90+
* @param func
91+
*
92+
* @return
93+
* A version of this callback builder with the addition of func.
94+
*
95+
* @see cib::extend
96+
* @see cib::nexus
97+
*/
98+
[[nodiscard]] CIB_CONSTEVAL auto add(func_ptr_t const & func) const {
99+
return callback<NumFuncs + 1, ArgTypes...>{funcs, func};
64100
}
65101

66102
/**
67-
* Build and return a function pointer to the implemented callback builder. Used
68-
* by cib library to automatically build an initialized builder. Do not call.
103+
* Build and return a function pointer to the implemented callback
104+
* builder. Used by cib nexus to automatically build an initialized
105+
* builder.
106+
*
107+
* Do not call directly.
69108
*
70109
* @tparam BuilderValue
71110
* Struct that contains a "static constexpr auto value" field with the initialized
72111
* builder.
73112
*
74113
* @return
75-
* Function pointer to callback builder.
114+
* Function pointer to the implemented callback service.
76115
*/
77116
template<typename BuilderValue>
78117
[[nodiscard]] CIB_CONSTEVAL static auto build() {
79118
return run<BuilderValue>;
80119
}
81120
};
82121

83-
template<typename... Args>
122+
/**
123+
* Extend this to create named callback services.
124+
*
125+
* Types that extend callback_meta can be used as unique names with
126+
* cib::exports and cib::extend.
127+
*
128+
* @tparam ArgTypes
129+
* The function arguments that must be passed into the callback
130+
* services implementation. Any function registered with this
131+
* callback service must also have a compatible signature.
132+
*
133+
* @see cib::exports
134+
* @see cib::extend
135+
*/
136+
template<typename... ArgTypes>
84137
struct callback_meta :
85138
public cib::builder_meta<
86-
callback<0, Args...>,
87-
void(*)(Args...)>
139+
callback<0, ArgTypes...>,
140+
void(*)(ArgTypes...)>
88141
{};
89142
}
90143

include/cib/cib.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@
4242
#include "nexus.hpp"
4343
#include "built.hpp"
4444
#include "config.hpp"
45-
#include "detail/compiler.hpp"
46-
#include "detail/meta.hpp"
4745
#include "builder_meta.hpp"
4846

4947

0 commit comments

Comments
 (0)