Skip to content

Commit d0a1024

Browse files
committed
more policy splitting
1 parent 3acc2de commit d0a1024

17 files changed

+757
-516
lines changed

include/yorel/yomm2/detail.hpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
#ifndef YOREL_YOMM2_DETAIL_HPP
22
#define YOREL_YOMM2_DETAIL_HPP
33

4-
#include <boost/assert.hpp>
5-
#include <boost/dynamic_bitset.hpp>
6-
#include <boost/mp11/algorithm.hpp>
7-
#include <boost/mp11/bind.hpp>
8-
94
#include <yorel/yomm2/detail/static_list.hpp>
105

6+
#include <boost/assert.hpp>
7+
118
namespace yorel {
129
namespace yomm2 {
1310
namespace detail {

include/yorel/yomm2/detail/compiler.hpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <boost/assert.hpp>
2626
#include <boost/dynamic_bitset.hpp>
2727

28-
2928
namespace yorel {
3029
namespace yomm2 {
3130
namespace detail {
@@ -37,20 +36,26 @@ struct aggregate_reports;
3736

3837
template<class... Reports, class Facet, class... MoreFacets>
3938
struct aggregate_reports<
40-
types<Reports...>, types<Facet, MoreFacets...>,
39+
types<Reports...>,
40+
types<Facet, MoreFacets...>,
4141
std::void_t<typename Facet::report>> {
4242
using type = typename aggregate_reports<
43-
types<Reports..., typename Facet::report>, types<MoreFacets...>>::type;
43+
types<Reports..., typename Facet::report>,
44+
types<MoreFacets...>>::type;
4445
};
4546

4647
template<class... Reports, class Facet, class... MoreFacets, typename Void>
47-
struct aggregate_reports<types<Reports...>, types<Facet, MoreFacets...>, Void> {
48+
struct aggregate_reports<
49+
types<Reports...>,
50+
types<Facet, MoreFacets...>, Void> {
4851
using type = typename aggregate_reports<
49-
types<Reports...>, types<MoreFacets...>>::type;
52+
types<Reports...>,
53+
types<MoreFacets...>>::type;
5054
};
5155

5256
template<class... Reports, typename Void>
53-
struct aggregate_reports<types<Reports...>, types<>, Void> {
57+
struct aggregate_reports<
58+
types<Reports...>, types<>, Void> {
5459
struct type : Reports... {};
5560
};
5661

@@ -224,7 +229,8 @@ struct compiler : generic_compiler {
224229
using type_index_type = decltype(Policy::type_index(0));
225230

226231
typename aggregate_reports<
227-
types<update_report>, typename Policy::facets>::type report;
232+
types<update_report>, typename Policy::facets>::type
233+
report;
228234

229235
std::unordered_map<type_index_type, class_*> class_map;
230236

include/yorel/yomm2/detail/trace.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef YOREL_YOMM2_DETAIL_TRACE_HPP
22
#define YOREL_YOMM2_DETAIL_TRACE_HPP
33

4+
#include <boost/dynamic_bitset.hpp>
5+
46
namespace yorel {
57
namespace yomm2 {
68
namespace detail {

include/yorel/yomm2/detail/types.hpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#ifndef YOREL_YOMM2_DETAIL_TYPES_HPP
2+
#define YOREL_YOMM2_DETAIL_TYPES_HPP
3+
4+
#include <cstdint>
5+
#include <limits>
6+
7+
#if defined(YOMM2_SHARED)
8+
#if defined(_MSC_VER)
9+
#if !defined(yOMM2_API_msc)
10+
#define yOMM2_API_msc __declspec(dllimport)
11+
#endif
12+
#endif
13+
#endif
14+
15+
#if !defined(yOMM2_API_gcc)
16+
#define yOMM2_API_gcc
17+
#endif
18+
19+
#if !defined(yOMM2_API_msc)
20+
#define yOMM2_API_msc
21+
#endif
22+
23+
#define yOMM2_API yOMM2_API_gcc yOMM2_API_msc
24+
25+
namespace yorel {
26+
namespace yomm2 {
27+
28+
using type_id = std::uintptr_t;
29+
constexpr type_id invalid_type = (std::numeric_limits<type_id>::max)();
30+
31+
namespace detail {
32+
33+
template<typename... Types>
34+
struct types;
35+
36+
}
37+
} // namespace yomm2
38+
} // namespace yorel
39+
40+
#endif
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
// Copyright (c) 2018-2024 Jean-Louis Leroy
3+
// Distributed under the Boost Software License, Version 1.0.
4+
// See accompanying file LICENSE_1_0.txt
5+
// or copy at http://www.boost.org/LICENSE_1_0.txt)
6+
7+
#ifndef YOREL_YOMM2_POLICY_BASIC_ERROR_OUTPUT_HPP
8+
#define YOREL_YOMM2_POLICY_BASIC_ERROR_OUTPUT_HPP
9+
10+
#include <yorel/yomm2/policies/core.hpp>
11+
12+
namespace yorel {
13+
namespace yomm2 {
14+
namespace policy {
15+
16+
template<class Policy, typename Stream = detail::ostderr>
17+
struct yOMM2_API_gcc basic_error_output : virtual error_output {
18+
static Stream error_stream;
19+
};
20+
21+
template<class Policy, typename Stream>
22+
Stream basic_error_output<Policy, Stream>::error_stream;
23+
24+
}
25+
}
26+
}
27+
28+
#endif
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
// Copyright (c) 2018-2024 Jean-Louis Leroy
3+
// Distributed under the Boost Software License, Version 1.0.
4+
// See accompanying file LICENSE_1_0.txt
5+
// or copy at http://www.boost.org/LICENSE_1_0.txt)
6+
7+
#ifndef YOREL_YOMM2_POLICY_BASIC_INDIRECT_VPTR_HPP
8+
#define YOREL_YOMM2_POLICY_BASIC_INDIRECT_VPTR_HPP
9+
10+
#include <yorel/yomm2/policies/core.hpp>
11+
12+
namespace yorel {
13+
namespace yomm2 {
14+
namespace policy {
15+
16+
template<class Policy>
17+
struct yOMM2_API_gcc basic_indirect_vptr : virtual indirect_vptr {
18+
static std::vector<std::uintptr_t const* const*> indirect_vptrs;
19+
};
20+
21+
template<class Policy>
22+
std::vector<std::uintptr_t const* const*>
23+
basic_indirect_vptr<Policy>::indirect_vptrs;
24+
25+
}
26+
}
27+
}
28+
29+
#endif
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
// Copyright (c) 2018-2024 Jean-Louis Leroy
3+
// Distributed under the Boost Software License, Version 1.0.
4+
// See accompanying file LICENSE_1_0.txt
5+
// or copy at http://www.boost.org/LICENSE_1_0.txt)
6+
7+
#ifndef YOREL_YOMM2_POLICY_BASIC_TRACE_OUTPUT_HPP
8+
#define YOREL_YOMM2_POLICY_BASIC_TRACE_OUTPUT_HPP
9+
10+
#include <yorel/yomm2/policies/core.hpp>
11+
12+
namespace yorel {
13+
namespace yomm2 {
14+
namespace policy {
15+
16+
template<class Policy, typename Stream = detail::ostderr>
17+
struct yOMM2_API_gcc basic_trace_output : virtual trace_output {
18+
static Stream trace_stream;
19+
static bool trace_enabled;
20+
};
21+
22+
template<class Policy, typename Stream>
23+
Stream basic_trace_output<Policy, Stream>::trace_stream;
24+
25+
template<class Policy, typename Stream>
26+
bool basic_trace_output<Policy, Stream>::trace_enabled([]() {
27+
auto env = getenv("YOMM2_TRACE");
28+
return env && *env++ == '1' && *env++ == 0;
29+
}());
30+
31+
}
32+
}
33+
}
34+
35+
#endif

include/yorel/yomm2/policies/core.hpp

Lines changed: 77 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,19 @@
1+
// Copyright (c) 2018-2024 Jean-Louis Leroy
2+
// Distributed under the Boost Software License, Version 1.0.
3+
// See accompanying file LICENSE_1_0.txt
4+
// or copy at http://www.boost.org/LICENSE_1_0.txt)
5+
16
#ifndef YOREL_YOMM2_POLICIES_CORE_HPP
27
#define YOREL_YOMM2_POLICIES_CORE_HPP
38

9+
#include <yorel/yomm2/detail/types.hpp>
410
#include <yorel/yomm2/detail/static_list.hpp>
511

6-
#if defined(YOMM2_SHARED)
7-
#if defined(_MSC_VER)
8-
#if !defined(yOMM2_API_msc)
9-
#define yOMM2_API_msc __declspec(dllimport)
10-
#endif
11-
#endif
12-
#endif
13-
14-
#if !defined(yOMM2_API_gcc)
15-
#define yOMM2_API_gcc
16-
#endif
17-
18-
#if !defined(yOMM2_API_msc)
19-
#define yOMM2_API_msc
20-
#endif
21-
22-
#define yOMM2_API yOMM2_API_gcc yOMM2_API_msc
23-
24-
// -----------------------------------------------------------------------------
25-
// Forward declarations needed by "detail.hpp"
12+
#include <boost/mp11/algorithm.hpp>
13+
#include <boost/mp11/bind.hpp>
2614

2715
namespace yorel {
2816
namespace yomm2 {
29-
30-
struct context;
31-
struct catalog;
32-
33-
using type_id = std::uintptr_t;
34-
constexpr type_id invalid_type = (std::numeric_limits<type_id>::max)();
35-
3617
namespace detail {
3718

3819
// -----------------------------------------------------------------------------
@@ -193,6 +174,75 @@ detail::method_catalog basic_domain<Key>::methods;
193174
template<class Key>
194175
std::vector<std::uintptr_t> basic_domain<Key>::dispatch_data;
195176

177+
template<typename Policy, class Facet>
178+
struct rebind_facet {
179+
using type = Facet;
180+
};
181+
182+
template<
183+
typename NewPolicy, typename OldPolicy,
184+
template<typename...> class GenericFacet, typename... Args>
185+
struct rebind_facet<NewPolicy, GenericFacet<OldPolicy, Args...>> {
186+
using type = GenericFacet<NewPolicy, Args...>;
187+
};
188+
189+
template<class Policy, class... Facets>
190+
struct basic_policy : virtual abstract_policy,
191+
virtual basic_domain<Policy>,
192+
virtual Facets... {
193+
using facets = detail::types<Facets...>;
194+
195+
template<class Facet>
196+
static constexpr bool has_facet = std::is_base_of_v<Facet, Policy>;
197+
198+
template<class Facet>
199+
using use_facet = boost::mp11::mp_first<boost::mp11::mp_filter_q<
200+
boost::mp11::mp_bind_front_q<
201+
boost::mp11::mp_quote_trait<std::is_base_of>, Facet>,
202+
facets>>;
203+
204+
template<class NewPolicy>
205+
using rebind = basic_policy<
206+
NewPolicy, typename rebind_facet<NewPolicy, Facets>::type...>;
207+
208+
template<class Base, class Facet>
209+
using replace = boost::mp11::mp_apply<
210+
basic_policy,
211+
boost::mp11::mp_push_front<
212+
boost::mp11::mp_replace_if_q<
213+
facets,
214+
boost::mp11::mp_bind_front_q<
215+
boost::mp11::mp_quote_trait<std::is_base_of>, Base>,
216+
Facet>,
217+
Policy>>;
218+
219+
template<class Base>
220+
using remove = boost::mp11::mp_apply<
221+
basic_policy,
222+
boost::mp11::mp_push_front<
223+
boost::mp11::mp_remove_if_q<
224+
facets,
225+
boost::mp11::mp_bind_front_q<
226+
boost::mp11::mp_quote_trait<std::is_base_of>, Base>>,
227+
Policy>>;
228+
};
229+
230+
template<class Policy, class Facet>
231+
constexpr bool has_facet = Policy::template has_facet<Facet>;
232+
233+
struct rtti {
234+
static type_id type_index(type_id type) {
235+
return type;
236+
}
237+
238+
template<typename Stream>
239+
static void type_name(type_id type, Stream& stream) {
240+
stream << "type_id(" << type << ")";
241+
}
242+
};
243+
244+
struct deferred_static_rtti : virtual rtti {};
245+
196246
} // namespace policy
197247

198248
} // namespace yomm2

0 commit comments

Comments
 (0)