Skip to content

Commit 68ca382

Browse files
committed
Refactor source.hpp and module.hpp files
1 parent 5eaa9c7 commit 68ca382

File tree

3 files changed

+40
-38
lines changed

3 files changed

+40
-38
lines changed

phlex/detail/plugin_macros.hpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#ifndef PHLEX_DETAIL_PLUGIN_MACROS_HPP
2+
#define PHLEX_DETAIL_PLUGIN_MACROS_HPP
3+
4+
#include "boost/preprocessor.hpp"
5+
6+
#define PHLEX_DETAIL_NARGS(...) BOOST_PP_DEC(BOOST_PP_VARIADIC_SIZE(__VA_OPT__(, ) __VA_ARGS__))
7+
8+
#define PHLEX_DETAIL_CREATE_1ARG(token_type, func_name, m) \
9+
void func_name(token_type<phlex::experimental::void_tag>& m, \
10+
phlex::experimental::configuration const&)
11+
12+
#define PHLEX_DETAIL_CREATE_2ARGS(token_type, func_name, m, pset) \
13+
void func_name(token_type<phlex::experimental::void_tag>& m, \
14+
phlex::experimental::configuration const& config)
15+
16+
#define PHLEX_DETAIL_SELECT_SIGNATURE(token_type, func_name, ...) \
17+
BOOST_PP_IF(BOOST_PP_EQUAL(PHLEX_DETAIL_NARGS(__VA_ARGS__), 1), \
18+
PHLEX_DETAIL_CREATE_1ARG, \
19+
PHLEX_DETAIL_CREATE_2ARGS) \
20+
(token_type, func_name, __VA_ARGS__)
21+
22+
#define PHLEX_DETAIL_REGISTER_PLUGIN(token_type, func_name, dll_alias, ...) \
23+
static PHLEX_DETAIL_SELECT_SIGNATURE(token_type, func_name, __VA_ARGS__); \
24+
BOOST_DLL_ALIAS(func_name, dll_alias) \
25+
PHLEX_DETAIL_SELECT_SIGNATURE(token_type, func_name, __VA_ARGS__)
26+
27+
#endif // PHLEX_DETAIL_PLUGIN_MACROS_HPP

phlex/module.hpp

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@
55
#include "phlex/concurrency.hpp"
66
#include "phlex/configuration.hpp"
77
#include "phlex/core/graph_proxy.hpp"
8-
9-
#include "boost/preprocessor.hpp"
8+
#include "phlex/detail/plugin_macros.hpp"
109

1110
namespace phlex::experimental {
1211
template <typename T>
13-
class module_token : graph_proxy<T> {
12+
class module_graph_proxy : graph_proxy<T> {
1413
using base = graph_proxy<T>;
1514

1615
public:
1716
using base::graph_proxy;
1817

18+
// FIXME: make sure functions called from make<T>(...) are restricted to the functions below:
19+
// Users can call make<T>(...).fold(...) but not make<T>(...).provide(...)
1920
using base::make;
2021

2122
using base::fold;
@@ -30,21 +31,8 @@ namespace phlex::experimental {
3031
}
3132
}
3233

33-
#define NARGS(...) BOOST_PP_DEC(BOOST_PP_VARIADIC_SIZE(__VA_OPT__(, ) __VA_ARGS__))
34-
35-
#define CREATE_1ARG(m) \
36-
void create(phlex::experimental::module_token<phlex::experimental::void_tag>& m, \
37-
phlex::experimental::configuration const&)
38-
#define CREATE_2ARGS(m, pset) \
39-
void create(phlex::experimental::module_token<phlex::experimental::void_tag>& m, \
40-
phlex::experimental::configuration const& config)
41-
42-
#define SELECT_SIGNATURE(...) \
43-
BOOST_PP_IF(BOOST_PP_EQUAL(NARGS(__VA_ARGS__), 1), CREATE_1ARG, CREATE_2ARGS)(__VA_ARGS__)
44-
4534
#define PHLEX_EXPERIMENTAL_REGISTER_ALGORITHMS(...) \
46-
static SELECT_SIGNATURE(__VA_ARGS__); \
47-
BOOST_DLL_ALIAS(create, create_module) \
48-
SELECT_SIGNATURE(__VA_ARGS__)
35+
PHLEX_DETAIL_REGISTER_PLUGIN( \
36+
phlex::experimental::module_graph_proxy, create, create_module, __VA_ARGS__)
4937

5038
#endif // PHLEX_MODULE_HPP

phlex/source.hpp

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,21 @@
55
#include "phlex/concurrency.hpp"
66
#include "phlex/configuration.hpp"
77
#include "phlex/core/graph_proxy.hpp"
8-
9-
#include "boost/preprocessor.hpp"
8+
#include "phlex/detail/plugin_macros.hpp"
109

1110
namespace phlex::experimental {
1211
template <typename T>
13-
class source_token : graph_proxy<T> {
12+
class source_graph_proxy : graph_proxy<T> {
1413
using base = graph_proxy<T>;
1514

1615
public:
1716
using base::graph_proxy;
1817

18+
// FIXME: make sure functions called from make<T>(...) are restricted to the functions below:
19+
// Users can call make<T>(...).provide(...) but not make<T>(...).fold(...)
1920
using base::make;
2021

22+
// Only provide(...) should be accessible
2123
using base::provide;
2224
};
2325

@@ -26,23 +28,8 @@ namespace phlex::experimental {
2628
}
2729
}
2830

29-
#define SOURCE_NARGS(...) BOOST_PP_DEC(BOOST_PP_VARIADIC_SIZE(__VA_OPT__(, ) __VA_ARGS__))
30-
31-
#define CREATE_SOURCE_1ARG(m) \
32-
void create_src(phlex::experimental::source_token<phlex::experimental::void_tag>& m, \
33-
phlex::experimental::configuration const&)
34-
#define CREATE_SOURCE_2ARGS(m, pset) \
35-
void create_src(phlex::experimental::source_token<phlex::experimental::void_tag>& m, \
36-
phlex::experimental::configuration const& config)
37-
38-
#define SELECT_SOURCE_SIGNATURE(...) \
39-
BOOST_PP_IF(BOOST_PP_EQUAL(SOURCE_NARGS(__VA_ARGS__), 1), \
40-
CREATE_SOURCE_1ARG, \
41-
CREATE_SOURCE_2ARGS)(__VA_ARGS__)
42-
4331
#define PHLEX_EXPERIMENTAL_REGISTER_PROVIDERS(...) \
44-
static SELECT_SOURCE_SIGNATURE(__VA_ARGS__); \
45-
BOOST_DLL_ALIAS(create_src, create_source) \
46-
SELECT_SOURCE_SIGNATURE(__VA_ARGS__)
32+
PHLEX_DETAIL_REGISTER_PLUGIN( \
33+
phlex::experimental::source_graph_proxy, create, create_source, __VA_ARGS__)
4734

4835
#endif // PHLEX_SOURCE_HPP

0 commit comments

Comments
 (0)