LibJuno 1.0.1
LibJuno is a lightweight C11 library designed specifically for embedded systems.
Loading...
Searching...
No Matches
module.h
Go to the documentation of this file.
1/*
2 MIT License
3
4 Copyright (c) 2025 Robin A. Onsay
5
6 Permission is hereby granted, free of charge, to any person obtaining
7 a copy of this software and associated documentation files
8 (the "Software"), to deal in the Software without restriction,
9 including without limitation the rights to use, copy, modify, merge,
10 publish, distribute, sublicense, and/or sell copies of the Software,
11 and to permit persons to whom the Software is furnished to do so,
12 subject to the following conditions:
13
14 The above copyright notice and this permission notice shall be
15 included in all copies or substantial portions of the Software.
16*/
17#ifndef JUNO_MODULE_H
18#define JUNO_MODULE_H
19
20#include "juno/status.h"
21#include <stdint.h>
22#include <stdbool.h>
61#define JUNO_MODULE_DECLARE(NAME_T) typedef union NAME_T NAME_T
67#define JUNO_MODULE_ROOT_DECLARE(NAME_T) typedef struct NAME_T NAME_T
73#define JUNO_MODULE_DERIVE_DECLARE(NAME_T) JUNO_MODULE_ROOT_DECLARE(NAME_T)
74
78#define JUNO_FAILURE_HANDLER _pfcnFailureHandler
82#define JUNO_FAILURE_USER_DATA _pvFailureUserData
86#define JUNO_MODULE_EMPTY
87
91#define JUNO_MODULE_ARG(...) __VA_ARGS__
92
96#define JUNO_MODULE_SUPER tRoot
97
110#define JUNO_MODULE(API_T, ROOT_T, ...) \
111{ \
112 ROOT_T JUNO_MODULE_SUPER; \
113 __VA_ARGS__ \
114}
115
126#define JUNO_MODULE_ROOT(API_T, ...) \
127{ \
128 const API_T *ptApi; \
129 JUNO_FAILURE_HANDLER_T JUNO_FAILURE_HANDLER; \
130 JUNO_USER_DATA_T *JUNO_FAILURE_USER_DATA; \
131 __VA_ARGS__ \
132}
133
142#define JUNO_TRAIT_ROOT(API_T, ...) \
143{ \
144 const API_T *ptApi; \
145 __VA_ARGS__ \
146}
147
157#define JUNO_MODULE_DERIVE(ROOT_T, ...) \
158{ \
159 ROOT_T JUNO_MODULE_SUPER; \
160 __VA_ARGS__ \
161}
162
166#define JUNO_TRAIT_DERIVE(ROOT_T, ...) JUNO_MODULE_DERIVE(ROOT_T, __VA_ARGS__)
167
180#define JUNO_MODULE_GET_API(ptModule, ROOT_T) ((const ROOT_T *)ptModule)->ptApi
181
182
193#define JUNO_MODULE_RESULT(NAME_T, OK_T) \
194typedef struct NAME_T \
195{ \
196 JUNO_STATUS_T tStatus; \
197 OK_T tOk; \
198} NAME_T
199
204#define JUNO_OK(result) result.tOk
215#define JUNO_ASSERT_OK(result, ...) JUNO_ASSERT_SUCCESS(result.tStatus, __VA_ARGS__)
220#define JUNO_OK_RESULT(value) {JUNO_STATUS_SUCCESS, value}
225#define JUNO_ERR_RESULT(err, value) {err, value}
236#define JUNO_MODULE_OPTION(NAME_T, SOME_T) \
237typedef struct NAME_T \
238{ \
239 bool bIsSome; \
240 SOME_T tSome; \
241} NAME_T
242
247#define JUNO_SOME(result) result.tSome
258#define JUNO_ASSERT_SOME(result, ...) if(!result.bIsSome){ \
259 __VA_ARGS__ \
260}
265#define JUNO_SOME_OPTION(value) {true, value}
270#define JUNO_NONE_OPTION(default_value) {false, default_value}
271
272#endif // JUNO_MODULE_H
Status codes and failure-handling helpers for LibJuno.