find a way to pick a default implementation for collection binding
...through the use of partial specialisation and SFINAE. There are some rather specific (yet expectedly not uncommon) cases, where we'd be able to provide a sensible default for the - match predicate - new element constructor of the binding. While in all other cases, the user has to provide an explicit implementation for these crucial building blocks anyway.
This commit is contained in:
parent
4e6fd86c8d
commit
3b116fe6ef
1 changed files with 54 additions and 15 deletions
|
|
@ -383,6 +383,55 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
using lib::meta::Yes_t;
|
||||||
|
using lib::meta::No_t;
|
||||||
|
using lib::meta::enable_if;
|
||||||
|
|
||||||
|
template<typename ELM>
|
||||||
|
struct can_wrap_in_GenNode
|
||||||
|
{
|
||||||
|
template<class X>
|
||||||
|
static Yes_t check(typename lib::variant::CanBuildFrom<X, lib::diff::DataValues>::Type*);
|
||||||
|
template<class X>
|
||||||
|
static No_t check(...);
|
||||||
|
|
||||||
|
public:
|
||||||
|
static const bool value = (sizeof(Yes_t)==sizeof(check<ELM>(0)));
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template<typename ELM, typename SEL =void>
|
||||||
|
struct _DefaultPayload
|
||||||
|
{
|
||||||
|
static bool
|
||||||
|
match (GenNode const& spec, ELM const& elm)
|
||||||
|
{
|
||||||
|
UNIMPLEMENTED("lalü");
|
||||||
|
}
|
||||||
|
|
||||||
|
static ELM
|
||||||
|
construct (GenNode const& spec)
|
||||||
|
{
|
||||||
|
UNIMPLEMENTED("lalü");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename ELM>
|
||||||
|
struct _DefaultPayload<ELM, enable_if<can_wrap_in_GenNode<ELM>>>
|
||||||
|
{
|
||||||
|
static bool
|
||||||
|
match (GenNode const& spec, ELM const& elm)
|
||||||
|
{
|
||||||
|
return spec.matches(elm);
|
||||||
|
}
|
||||||
|
|
||||||
|
static ELM
|
||||||
|
construct (GenNode const& spec)
|
||||||
|
{
|
||||||
|
return spec.data.get<ELM>();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* starting point for configuration of a binding to STL container.
|
* starting point for configuration of a binding to STL container.
|
||||||
* When using the "nested DSL" to setup a binding to child elements
|
* When using the "nested DSL" to setup a binding to child elements
|
||||||
|
|
@ -400,17 +449,7 @@
|
||||||
using Coll = typename Strip<COLL>::TypeReferred;
|
using Coll = typename Strip<COLL>::TypeReferred;
|
||||||
using Elm = typename Coll::value_type;
|
using Elm = typename Coll::value_type;
|
||||||
|
|
||||||
static bool
|
using Payload = _DefaultPayload<Elm>;
|
||||||
default_contentMatch (GenNode const& spec, Elm const& elm)
|
|
||||||
{
|
|
||||||
return spec.matches(elm);
|
|
||||||
}
|
|
||||||
|
|
||||||
static Elm
|
|
||||||
default_construct_from_payload (GenNode const& spec)
|
|
||||||
{
|
|
||||||
return spec.data.get<Elm>();
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
disable_selector (GenNode const&)
|
disable_selector (GenNode const&)
|
||||||
|
|
@ -433,8 +472,8 @@
|
||||||
|
|
||||||
using FallbackBindingConfiguration
|
using FallbackBindingConfiguration
|
||||||
= CollectionBindingBuilder<Coll
|
= CollectionBindingBuilder<Coll
|
||||||
,decltype(&default_contentMatch)
|
,decltype(&Payload::match)
|
||||||
,decltype(&default_construct_from_payload)
|
,decltype(&Payload::construct)
|
||||||
,decltype(&disable_selector)
|
,decltype(&disable_selector)
|
||||||
,decltype(&disable_assignment)
|
,decltype(&disable_assignment)
|
||||||
,decltype(&disable_childMutation)
|
,decltype(&disable_childMutation)
|
||||||
|
|
@ -444,8 +483,8 @@
|
||||||
attachTo (Coll& coll)
|
attachTo (Coll& coll)
|
||||||
{
|
{
|
||||||
return FallbackBindingConfiguration{ coll
|
return FallbackBindingConfiguration{ coll
|
||||||
, default_contentMatch
|
, Payload::match
|
||||||
, default_construct_from_payload
|
, Payload::construct
|
||||||
, disable_selector
|
, disable_selector
|
||||||
, disable_assignment
|
, disable_assignment
|
||||||
, disable_childMutation
|
, disable_childMutation
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue