The happy API
is a generic and minimalistic composition API to support further development of modular API's
provide functionality with each part and have compile time errors if the functionality is not present/available in the composition.
or
Have fallback methods that usually do nothing. This will erase all calls.
No compile time errors, but also no runtime code, unless an override with some functionality is provided.
also
support CRTP style calls without infinite recursion, attempts are compile time errors.
Provide a virtual methods cap to encapsulate different composition under the same type for generic container storage.
A virtual (pure or fallback) interface must be provided along with a cap to redirect calls (virtual to static definition).
Automate creation of items parts for a specific API
composition parts are expected to have this structure
struct MyPart {
template<typename O> struct Part:O {
// some API implementation
};
};
a part setup can be a template with arbitrary parameters.
template<int defVal=30>
struct Power {
template<typename O> struct Part:O {
// some API implementation
};
};
Nil
is the default part chain terminator
struct Nil {};
this parts can be combined like this using c++ (tedious)
Power::Part<MyPart::Part<Nil>> example;
the example
object now has api functions from MyPart::Part<Nil>
override with Power::Part
.
Or chained with Parts tool: Parts<Power,MyPart>
.
template<typename... OO> struct Parts<OO...>;
combines a list of parts (OO...
) into a single part.
Parts<A,B,C>
=A::Part<B::Part<C>>
with advantage of future expansion ifC
is aPart
example:
//flat composition
using Example=Parts<Power,MyPart,Nil>;
compiles as a class derivation
Power::Part
+MyPart::Part
+Nil
defining new parts
//flat composition with no terminator
using Example=Parts<Power,MyPart>;
Parts<Example,Nil> example;//Example is a valid part
free use of parts, a composition of parts is also a valid part.
static and non-recursive API interface
static, recursive and cycle safe API calls
composing items with common virtual interface
store virtual interface items in std container