File: stack.h

package info (click to toggle)
muon-meson 0.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 15,112 kB
  • sloc: ansic: 61,516; python: 4,429; cpp: 1,968; javascript: 586; sh: 443; asm: 178; xml: 67; objc: 36; makefile: 21; modula3: 8; f90: 7
file content (37 lines) | stat: -rw-r--r-- 1,162 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
 * SPDX-FileCopyrightText: Stone Tickle <lattis@mochiro.moe>
 * SPDX-License-Identifier: GPL-3.0-only
 */

#ifndef MUON_DATASTRUCTURES_STACK_H
#define MUON_DATASTRUCTURES_STACK_H

#include <stdbool.h>
#include <stdint.h>

#include "preprocessor_helpers.h"

struct stack_tag;

typedef void (*stack_print_cb)(void *ctx, void *mem, struct stack_tag *tag);

struct stack {
	char *mem;
	uint32_t len, cap;
};

void stack_init(struct stack *stack, uint32_t cap);
void stack_destroy(struct stack *stack);

void stack_print(struct stack *_stack);
void stack_push_sized(struct stack *stack, const void *mem, uint32_t size, const char *name);
void stack_pop_sized(struct stack *stack, void *mem, uint32_t size);
void stack_peek_sized(struct stack *stack, void *mem, uint32_t size);

#define stack_push(__stack, __it, __nv)                                                           \
	stack_push_sized((__stack), &(__it), (sizeof(__it)), __FILE__ ":" LINE_STRING " " #__it); \
	__it = __nv
#define stack_pop(__stack, __it) stack_pop_sized((__stack), &(__it), (sizeof(__it)))
#define stack_peek(__stack, __it) stack_peek_sized((__stack), &(__it), (sizeof(__it)))

#endif