|
LibJuno 1.0.1
LibJuno is a lightweight C11 library designed specifically for embedded systems.
|
Macros | |
| #define | JUNO_MODULE_DECLARE(NAME_T) typedef union NAME_T NAME_T |
| Forward-declare a Juno module union type. | |
| #define | JUNO_MODULE_ROOT_DECLARE(NAME_T) typedef struct NAME_T NAME_T |
| Forward-declare a module root struct type. | |
| #define | JUNO_MODULE_DERIVE_DECLARE(NAME_T) JUNO_MODULE_ROOT_DECLARE(NAME_T) |
| Forward-declare a derived module struct type. | |
| #define | JUNO_FAILURE_HANDLER _pfcnFailureHandler |
| Member name alias for a module's failure handler. | |
| #define | JUNO_FAILURE_USER_DATA _pvFailureUserData |
| Member name alias for failure handler user data. | |
| #define | JUNO_MODULE_EMPTY |
| Helper for module definitions with no additional members. | |
| #define | JUNO_MODULE_ARG(...) __VA_ARGS__ |
| Pass-through argument pack helper for module macros. | |
| #define | JUNO_MODULE_SUPER tRoot |
| Standard member name for the embedded module root. | |
| #define | JUNO_MODULE(API_T, ROOT_T, ...) |
| Define a module union consisting of the root and all derivations. | |
| #define | JUNO_MODULE_ROOT(API_T, ...) |
| Implement a module root struct containing ptApi and failure fields. | |
| #define | JUNO_TRAIT_ROOT(API_T, ...) |
| Define a trait root carrying only the API pointer and members. | |
| #define | JUNO_MODULE_DERIVE(ROOT_T, ...) |
| Implement a derived module embedding the root as the first member. | |
| #define | JUNO_TRAIT_DERIVE(ROOT_T, ...) JUNO_MODULE_DERIVE(ROOT_T, __VA_ARGS__) |
| Alias to define a trait derivation with the standard layout. | |
| #define | JUNO_MODULE_GET_API(ptModule, ROOT_T) ((const ROOT_T *)ptModule)->ptApi |
| Retrieve the API pointer from a module (via its root view). | |
| #define | JUNO_MODULE_RESULT(NAME_T, OK_T) |
| Define a result type combining a status and a success payload. | |
| #define | JUNO_OK(result) result.tOk |
| Access the success payload from a result produced by JUNO_MODULE_RESULT. | |
| #define | JUNO_ASSERT_OK(result, ...) JUNO_ASSERT_SUCCESS(result.tStatus, __VA_ARGS__) |
Execute the provided statements if result.tStatus is not success. | |
| #define | JUNO_OK_RESULT(value) {JUNO_STATUS_SUCCESS, value} |
| Construct a result indicating success with the provided payload. | |
| #define | JUNO_ERR_RESULT(err, value) {err, value} |
| Construct a result indicating error with a payload (may be default-initialized). | |
| #define | JUNO_MODULE_OPTION(NAME_T, SOME_T) |
| Define an option type combining a presence flag and a payload. | |
| #define | JUNO_SOME(result) result.tSome |
| Access the payload from an option produced by JUNO_MODULE_OPTION. | |
| #define | JUNO_ASSERT_SOME(result, ...) |
Execute the provided statements if result.bIsSome is false. | |
| #define | JUNO_SOME_OPTION(value) {true, value} |
| Construct an option in the present state with the provided payload. | |
| #define | JUNO_NONE_OPTION(default_value) {false, default_value} |
| Construct an option in the empty state, carrying a default payload. | |
LibJuno implements dependency injection (DI) via a small module system. A module consists of:
Key properties:
ptApi and failure handler fields and should avoid hosted dependencies to preserve freestanding portability.Example (defining a module union):
| #define JUNO_ASSERT_OK | ( | result, | |
| ... | |||
| ) | JUNO_ASSERT_SUCCESS(result.tStatus, __VA_ARGS__) |
Execute the provided statements if result.tStatus is not success.
This is a convenience wrapper over JUNO_ASSERT_SUCCESS. Typical usage:
| #define JUNO_ASSERT_SOME | ( | result, | |
| ... | |||
| ) |
Execute the provided statements if result.bIsSome is false.
Typical usage:
| #define JUNO_ERR_RESULT | ( | err, | |
| value | |||
| ) | {err, value} |
Construct a result indicating error with a payload (may be default-initialized).
| #define JUNO_FAILURE_HANDLER _pfcnFailureHandler |
Member name alias for a module's failure handler.
| #define JUNO_FAILURE_USER_DATA _pvFailureUserData |
Member name alias for failure handler user data.
| #define JUNO_MODULE | ( | API_T, | |
| ROOT_T, | |||
| ... | |||
| ) |
Define a module union consisting of the root and all derivations.
| API_T | The API (vtable) type for the module. |
| ROOT_T | The root struct type for the module. |
| ... | One or more derived struct members, each provided as a full struct member declaration and separated by semicolons in the invocation. Use JUNO_MODULE_EMPTY if there are no derivations. |
| #define JUNO_MODULE_ARG | ( | ... | ) | __VA_ARGS__ |
Pass-through argument pack helper for module macros.
| #define JUNO_MODULE_DECLARE | ( | NAME_T | ) | typedef union NAME_T NAME_T |
Forward-declare a Juno module union type.
| NAME_T | The module union type name. |
| #define JUNO_MODULE_DERIVE | ( | ROOT_T, | |
| ... | |||
| ) |
Implement a derived module embedding the root as the first member.
| ROOT_T | The module root type. |
| ... | Implementation-specific members. |
| #define JUNO_MODULE_DERIVE_DECLARE | ( | NAME_T | ) | JUNO_MODULE_ROOT_DECLARE(NAME_T) |
Forward-declare a derived module struct type.
| NAME_T | The derived struct type name. |
| #define JUNO_MODULE_EMPTY |
Helper for module definitions with no additional members.
| #define JUNO_MODULE_GET_API | ( | ptModule, | |
| ROOT_T | |||
| ) | ((const ROOT_T *)ptModule)->ptApi |
Retrieve the API pointer from a module (via its root view).
| ptModule | Pointer to the module instance (module union or any derived/root view). |
| ROOT_T | The root type of the module. |
const API_T* stored in the root's ptApi field. | #define JUNO_MODULE_OPTION | ( | NAME_T, | |
| SOME_T | |||
| ) |
Define an option type combining a presence flag and a payload.
| NAME_T | Name of the option struct to define. |
| SOME_T | Type of the payload when present. |
The generated struct has fields:
bool bIsSome;SOME_T tSome; | #define JUNO_MODULE_RESULT | ( | NAME_T, | |
| OK_T | |||
| ) |
Define a result type combining a status and a success payload.
| NAME_T | Name of the result struct to define. |
| OK_T | Type of the success payload contained in the result. |
The generated struct has fields:
JUNO_STATUS_T tStatus;OK_T tOk; | #define JUNO_MODULE_ROOT | ( | API_T, | |
| ... | |||
| ) |
Implement a module root struct containing ptApi and failure fields.
| API_T | The API (vtable) type for the module. |
| ... | Additional root members (freestanding types recommended). |
const API_T *ptApi;, failure handler pointer, and user-data pointer, followed by user-specified members. | #define JUNO_MODULE_ROOT_DECLARE | ( | NAME_T | ) | typedef struct NAME_T NAME_T |
Forward-declare a module root struct type.
| NAME_T | The root struct type name. |
| #define JUNO_MODULE_SUPER tRoot |
Standard member name for the embedded module root.
| #define JUNO_NONE_OPTION | ( | default_value | ) | {false, default_value} |
Construct an option in the empty state, carrying a default payload.
| #define JUNO_OK | ( | result | ) | result.tOk |
Access the success payload from a result produced by JUNO_MODULE_RESULT.
| #define JUNO_OK_RESULT | ( | value | ) | {JUNO_STATUS_SUCCESS, value} |
Construct a result indicating success with the provided payload.
| #define JUNO_SOME | ( | result | ) | result.tSome |
Access the payload from an option produced by JUNO_MODULE_OPTION.
| #define JUNO_SOME_OPTION | ( | value | ) | {true, value} |
Construct an option in the present state with the provided payload.
| #define JUNO_TRAIT_DERIVE | ( | ROOT_T, | |
| ... | |||
| ) | JUNO_MODULE_DERIVE(ROOT_T, __VA_ARGS__) |
Alias to define a trait derivation with the standard layout.
| #define JUNO_TRAIT_ROOT | ( | API_T, | |
| ... | |||
| ) |
Define a trait root carrying only the API pointer and members.
| API_T | The API (vtable) type for the trait. |
| ... | Additional members for the trait root. |