Skip to content

Commit c502f80

Browse files
committed
Split member.hpp file
1 parent c219204 commit c502f80

19 files changed

+783
-518
lines changed

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ SET (HEADERS
7171
include/dracosha/validator/base_validator.hpp
7272
include/dracosha/validator/heterogeneous_property.hpp
7373
include/dracosha/validator/value_transformer.hpp
74+
include/dracosha/validator/member_with_name.hpp
75+
include/dracosha/validator/member_with_name_list.hpp
76+
include/dracosha/validator/make_member.hpp
77+
include/dracosha/validator/prepend_super_member.hpp
78+
include/dracosha/validator/prepend_super_member.ipp
79+
include/dracosha/validator/variadic_arg_tag.hpp
7480

7581
include/dracosha/validator/aggregation/and.hpp
7682
include/dracosha/validator/aggregation/or.hpp
@@ -182,6 +188,8 @@ SET (HEADERS
182188
include/dracosha/validator/detail/formatter_std.hpp
183189
include/dracosha/validator/detail/backend_formatter_helper.hpp
184190
include/dracosha/validator/detail/hint_helper.hpp
191+
include/dracosha/validator/detail/member_helper.hpp
192+
include/dracosha/validator/detail/member_helper.ipp
185193

186194
include/dracosha/validator/filter_member.hpp
187195
include/dracosha/validator/filter_member.ipp

TODO.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
- Split member.hpp file to a few separate files.
21
- Refactor formatting of variadic properties with taking into account preceding grammar categories.
32
- Check prevalidation with variadic properties, heterogeneous containers and trees.
43
- Implement filtering with predicates in element aggregation.

include/dracosha/validator/aggregation/aggregation.ipp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Distributed under the Boost Software License, Version 1.0.
2222
#include <dracosha/validator/config.hpp>
2323
#include <dracosha/validator/aggregation/aggregation.hpp>
2424
#include <dracosha/validator/member.hpp>
25+
#include <dracosha/validator/make_member.hpp>
2526
#include <dracosha/validator/extract.hpp>
2627
#include <dracosha/validator/get_member.hpp>
2728
#include <dracosha/validator/reporting/reporting_adapter_impl.hpp>

include/dracosha/validator/aggregation/any.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Distributed under the Boost Software License, Version 1.0.
2424
#include <dracosha/validator/make_validator.hpp>
2525
#include <dracosha/validator/aggregation/and.hpp>
2626
#include <dracosha/validator/prevalidation/strict_any.hpp>
27+
#include <dracosha/validator/properties/value.hpp>
2728

2829
DRACOSHA_VALIDATOR_NAMESPACE_BEGIN
2930

include/dracosha/validator/aggregation/element_aggregation.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ Distributed under the Boost Software License, Version 1.0.
2222
#include <dracosha/validator/config.hpp>
2323
#include <dracosha/validator/utils/adjust_storable_ignore.hpp>
2424
#include <dracosha/validator/aggregation/aggregation.hpp>
25-
#include <dracosha/validator/variadic_arg.hpp>
25+
#include <dracosha/validator/filter_member.hpp>
26+
#include <dracosha/validator/variadic_arg_tag.hpp>
2627

2728
DRACOSHA_VALIDATOR_NAMESPACE_BEGIN
2829

Lines changed: 273 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,273 @@
1+
/**
2+
@copyright Evgeny Sidorov 2020
3+
4+
Distributed under the Boost Software License, Version 1.0.
5+
(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
6+
7+
*/
8+
9+
/****************************************************************************/
10+
11+
/** @file validator/detail/member_helper.hpp
12+
*
13+
* Defines helpers to invoke member methods.
14+
*
15+
*/
16+
17+
/****************************************************************************/
18+
19+
#ifndef DRACOSHA_VALIDATOR_MEMBER_HELPER_HPP
20+
#define DRACOSHA_VALIDATOR_MEMBER_HELPER_HPP
21+
22+
#include <dracosha/validator/config.hpp>
23+
#include <dracosha/validator/aggregation/element_aggregation.hpp>
24+
#include <dracosha/validator/aggregation/any.hpp>
25+
#include <dracosha/validator/operators/flag.hpp>
26+
#include <dracosha/validator/make_validator.hpp>
27+
#include <dracosha/validator/reporting/concrete_phrase.hpp>
28+
#include <dracosha/validator/apply.hpp>
29+
#include <dracosha/validator/dispatcher.hpp>
30+
#include <dracosha/validator/properties.hpp>
31+
32+
DRACOSHA_VALIDATOR_NAMESPACE_BEGIN
33+
34+
namespace detail
35+
{
36+
37+
/**
38+
* @brief Helper for member's callable operator with 1 argument.
39+
*/
40+
template <typename T1, typename = hana::when<true>>
41+
struct member_helper_1arg_t
42+
{
43+
};
44+
45+
/**
46+
* @brief Helper for member's callable operator with 1 argument when the argument is validator.
47+
*/
48+
template <typename T1>
49+
struct member_helper_1arg_t<T1,
50+
hana::when<
51+
!(
52+
std::is_constructible<concrete_phrase,T1>::value
53+
&&
54+
!hana::is_a<operator_tag,T1>
55+
)
56+
>
57+
>
58+
{
59+
/**
60+
* @brief Bind compound validator to current member.
61+
* @param member Current member.
62+
* @param v Prepared partial validator.
63+
* @return Prepared partial validator bound to current member.
64+
*/
65+
template <typename MemberT>
66+
auto operator() (MemberT&& member, T1&& v) const
67+
{
68+
return make_member_validator(std::forward<MemberT>(member),std::forward<T1>(v));
69+
}
70+
};
71+
72+
/**
73+
* @brief Helper for member's callable operator with 1 argument when the argument is a concrete_phrase.
74+
*/
75+
template <typename T1>
76+
struct member_helper_1arg_t<T1,
77+
hana::when<
78+
(
79+
std::is_constructible<concrete_phrase,T1>::value
80+
&&
81+
!hana::is_a<operator_tag,T1>
82+
)
83+
>
84+
>
85+
{
86+
/**
87+
* @brief Construct a member from the current member with explicit name.
88+
* @param member Current member.
89+
* @param name Explicit name.
90+
* @return Member with explicit name.
91+
*/
92+
template <typename MemberT>
93+
auto operator() (MemberT&& member, T1&& name) const;
94+
};
95+
96+
/**
97+
* @brief Helper for member's callable operator with 2 arguments.
98+
*/
99+
template <typename T1, typename T2, typename = hana::when<true>>
100+
struct member_helper_2args_t
101+
{
102+
};
103+
104+
/**
105+
* @brief Helper for member's callable operator with 2 arguments when the second argument is enum of grammatical categories.
106+
*/
107+
template <typename T1, typename T2>
108+
struct member_helper_2args_t<T1,T2,
109+
hana::when<
110+
std::is_enum<std::decay_t<T2>>::value
111+
>
112+
>
113+
{
114+
/**
115+
* @brief Construct a member from the current member with explicit name and grammatical category.
116+
* @param member Current member.
117+
* @param name Name and grammatical catrgories.
118+
* @param grammar_category Grammatical categoty of the name.
119+
* @return Member with explicit name.
120+
*/
121+
template <typename MemberT>
122+
auto operator() (MemberT&& member, T1&& name, T2&& grammar_category) const;
123+
};
124+
125+
/**
126+
* @brief Helper for member's callable operator with 2 arguments when the first argument is operator.
127+
*/
128+
template <typename OpT, typename T1>
129+
struct member_helper_2args_t<OpT,T1,
130+
hana::when<
131+
(
132+
hana::is_a<operator_tag,OpT>
133+
&&
134+
!std::is_base_of<flag_t,std::decay_t<OpT>>::value
135+
)
136+
>
137+
>
138+
{
139+
/**
140+
* @brief Bind plain operator to current member.
141+
* @param member Current member.
142+
* @param op Operator.
143+
* @param b Argument to forward to operator.
144+
* @return Prepared partial validator of "value" property bound to current member.
145+
*/
146+
template <typename MemberT>
147+
auto operator() (MemberT&& member, OpT&& op, T1&& b) const
148+
{
149+
return member(value(std::forward<OpT>(op),std::forward<T1>(b)));
150+
}
151+
};
152+
153+
/**
154+
* @brief Helper for member's callable operator with 2 arguments when the first argument is a flag.
155+
*/
156+
template <typename OpT, typename T1>
157+
struct member_helper_2args_t<OpT,T1,
158+
hana::when<
159+
std::is_base_of<flag_t,std::decay_t<OpT>>::value
160+
>
161+
>
162+
{
163+
/**
164+
* @brief Rebind plain operator to the property validator if the last key in the path is a property and operator is a flag.
165+
* @param member Current member.
166+
* @param op Operator of flag type.
167+
* @param b Argument to forward to operator.
168+
* @return Prepared partial validator of the property corresponding to the last property key in the path.
169+
*/
170+
template <typename MemberT>
171+
auto operator() (MemberT&& member, OpT&& op, T1&& b,
172+
std::enable_if_t<!MemberT::is_nested,void*> =nullptr
173+
) const
174+
{
175+
return make_validator(member.key()(std::forward<OpT>(op),std::forward<T1>(b)));
176+
}
177+
178+
/**
179+
* @brief Rebind plain operator to the property validator of parent member if the last key in the path is a property and operator is a flag.
180+
* @param member Current member.
181+
* @param op Operator of flag type.
182+
* @param b Argument to forward to operator.
183+
* @return Prepared partial validator of the property of parent member corresponding to the last property key in the path.
184+
*/
185+
template <typename MemberT>
186+
auto operator () (MemberT&& member, OpT&& op, T1&& b,
187+
std::enable_if_t<MemberT::is_nested,void*> =nullptr
188+
) const
189+
{
190+
auto&& fn=[&member,&op,&b](auto&& key, auto&&... rpath)
191+
{
192+
return inherit_member(hana::reverse(hana::make_tuple(std::forward<decltype(rpath)>(rpath)...)),member)
193+
(
194+
key(std::forward<OpT>(op),std::forward<T1>(b))
195+
);
196+
};
197+
return hana::unpack(hana::reverse(std::move(member.path())),std::move(fn));
198+
}
199+
};
200+
201+
/**
202+
* @brief Helper for member's callable operator.
203+
*/
204+
template <typename ... Args>
205+
struct member_helper_t
206+
{
207+
/**
208+
* @brief Construct a member from the current member with explicit name and grammatical categories.
209+
* @param member Current member.
210+
* @param args Name and grammatical catrgories.
211+
* @return Member with explicit name.
212+
*/
213+
template <typename MemberT>
214+
auto operator() (MemberT&& member, Args&&... args) const;
215+
};
216+
217+
/**
218+
* @brief Helper for member's callable operator with 1 argument.
219+
*/
220+
template <typename T1>
221+
struct member_helper_t<T1> : public member_helper_1arg_t<T1>
222+
{
223+
};
224+
225+
/**
226+
* @brief Helper for member's callable operator with 2 arguments.
227+
*/
228+
template <typename T1, typename T2>
229+
struct member_helper_t<T1,T2> : public member_helper_2args_t<T1,T2>
230+
{
231+
};
232+
233+
/**
234+
* @brief Calable instance of helper for member's callable operator.
235+
*/
236+
template <typename ... Args>
237+
constexpr member_helper_t<Args...> member_helper{};
238+
239+
template <typename ... PathT>
240+
struct is_member_aggregated
241+
{
242+
constexpr static const auto value=hana::fold(
243+
hana::tuple_t<PathT...>,
244+
hana::false_{},
245+
is_element_aggregation
246+
);
247+
};
248+
249+
template <typename ... PathT>
250+
struct is_member_with_any
251+
{
252+
constexpr static const auto value=hana::fold(
253+
hana::tuple_t<PathT...>,
254+
hana::false_{},
255+
is_aggregation_any
256+
);
257+
};
258+
259+
template <typename ... PathT>
260+
struct is_member_with_varg
261+
{
262+
constexpr static const auto value=hana::fold(
263+
hana::tuple_t<PathT...>,
264+
hana::false_{},
265+
is_varg
266+
);
267+
};
268+
269+
}
270+
271+
DRACOSHA_VALIDATOR_NAMESPACE_END
272+
273+
#endif // DRACOSHA_VALIDATOR_MEMBER_HELPER_HPP

0 commit comments

Comments
 (0)