LibJuno 1.0.1
LibJuno is a lightweight C11 library designed specifically for embedded systems.
Loading...
Searching...
No Matches
stack_api.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
49#ifndef JUNO_DS_STACK_API_H
50#define JUNO_DS_STACK_API_H
51#include "juno/ds/array_api.h"
52#include "juno/macros.h"
53#include "juno/status.h"
54#include "juno/module.h"
55#ifdef __cplusplus
56extern "C"
57{
58#endif
59
61typedef struct JUNO_DS_STACK_ROOT_TAG JUNO_DS_STACK_ROOT_T;
63
68struct JUNO_DS_STACK_ROOT_TAG JUNO_MODULE_ROOT(JUNO_DS_STACK_API_T,
69 JUNO_DS_ARRAY_ROOT_T *ptStackArray;
70 size_t zLength;
71);
72
74{
88 JUNO_RESULT_POINTER_T (*Peek)(JUNO_DS_STACK_ROOT_T *ptStack);
89};
90
92{
93 JUNO_ASSERT_EXISTS(ptStack && ptStack->ptStackArray);
95 ptStack->ptApi &&
96 ptStack->ptApi->Push &&
97 ptStack->ptApi->Pop &&
98 ptStack->ptApi->Peek
99 );
100 return JunoDs_ArrayVerify(ptStack->ptStackArray);
101}
102
109JUNO_STATUS_T JunoDs_StackInit(JUNO_DS_STACK_ROOT_T *ptStack, JUNO_DS_ARRAY_ROOT_T *ptStackArray, JUNO_FAILURE_HANDLER_T pfcnFailureHdlr, JUNO_USER_DATA_T *pvFailureUserData);
110
116JUNO_RESULT_POINTER_T JunoDs_StackPeek(JUNO_DS_STACK_ROOT_T *ptStack);
117
118
119
120#ifdef __cplusplus
121}
122#endif
123#endif // JUNO_DS_STACK_API_H
Abstract fixed-capacity array interface for DS modules.
struct JUNO_DS_ARRAY_ROOT_TAG JUNO_DS_ARRAY_ROOT_T
Opaque array root carrying capacity and API pointer.
Definition array_api.h:58
static JUNO_STATUS_T JunoDs_ArrayVerify(const JUNO_DS_ARRAY_ROOT_T *ptArray)
Verify an array instance's capacity and API.
Definition array_api.h:117
#define JUNO_ASSERT_EXISTS(ptr)
Returns JUNO_STATUS_NULLPTR_ERROR if the expression is falsy.
Definition macros.h:50
#define JUNO_MODULE_ROOT(API_T,...)
Implement a module root struct containing ptApi and failure fields.
Definition module.h:126
void(* JUNO_FAILURE_HANDLER_T)(JUNO_STATUS_T tStatus, const char *pcCustomMessage, JUNO_USER_DATA_T *pvUserData)
Failure handler callback signature.
Definition status.h:104
int32_t JUNO_STATUS_T
Canonical status type for LibJuno functions.
Definition status.h:49
void JUNO_USER_DATA_T
Opaque user data type for failure callbacks.
Definition status.h:96
Common assertion and helper macros for LibJuno modules.
Module system and dependency injection primitives for LibJuno.
struct JUNO_POINTER_TAG JUNO_POINTER_T
Definition pointer_api.h:49
struct JUNO_DS_STACK_ROOT_TAG JUNO_DS_STACK_ROOT_T
The stack root module.
Definition stack_api.h:61
static JUNO_STATUS_T JunoDs_StackVerify(const JUNO_DS_STACK_ROOT_T *ptStack)
Definition stack_api.h:91
JUNO_STATUS_T JunoDs_StackPush(JUNO_DS_STACK_ROOT_T *ptStack, JUNO_POINTER_T tItem)
Push an item onto the top of the stack (O(1)).
Definition juno_buff_stack.c:27
JUNO_STATUS_T JunoDs_StackInit(JUNO_DS_STACK_ROOT_T *ptStack, JUNO_DS_ARRAY_ROOT_T *ptStackArray, JUNO_FAILURE_HANDLER_T pfcnFailureHdlr, JUNO_USER_DATA_T *pvFailureUserData)
Initialize a stack over a backing array with a given capacity.
Definition juno_buff_stack.c:98
JUNO_STATUS_T JunoDs_StackPop(JUNO_DS_STACK_ROOT_T *ptStack, JUNO_POINTER_T tReturn)
Pop the top item into tReturn (O(1)).
Definition juno_buff_stack.c:51
JUNO_RESULT_POINTER_T JunoDs_StackPeek(JUNO_DS_STACK_ROOT_T *ptStack)
Peek at the top item without removing it (O(1)).
Definition juno_buff_stack.c:75
Status codes and failure-handling helpers for LibJuno.
Definition stack_api.h:74
JUNO_STATUS_T(* Pop)(JUNO_DS_STACK_ROOT_T *ptStack, JUNO_POINTER_T tReturn)
Pop the top item into tReturn (O(1)).
Definition stack_api.h:84
JUNO_RESULT_POINTER_T(* Peek)(JUNO_DS_STACK_ROOT_T *ptStack)
Peek at the top item without removing it (O(1)).
Definition stack_api.h:88
JUNO_STATUS_T(* Push)(JUNO_DS_STACK_ROOT_T *ptStack, JUNO_POINTER_T tItem)
Push an item onto the top of the stack (O(1)).
Definition stack_api.h:79