Skip to content

InternetOfPins/HAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HAPI

The happy API

is a generic and minimalistic composition API to support further development of modular API's

building an API

we can

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

Parts

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

Nil is the default part chain terminator

struct Nil {};

combining parts with C++

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.

using sugar to bind the parts

Or chained with Parts tool: Parts<Power,MyPart>.

How it works

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 if C is a Part

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

Examples

free

free use of parts, a composition of parts is also a valid part.

flat

static and non-recursive API interface

crtp

static, recursive and cycle safe API calls

virt

composing items with common virtual interface

std

store virtual interface items in std container

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published