aboutsummaryrefslogtreecommitdiffstats
path: root/src/serd_stack.h
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-01-23 09:16:38 +0000
committerDavid Robillard <d@drobilla.net>2011-01-23 09:16:38 +0000
commitebcef72577398fa10a6ad6545317f704bcf9a1c4 (patch)
treecb6ada04b2a4c4eefa1fa86c6b8a854c7fc7488d /src/serd_stack.h
parent5de15ccf0a0216e5aadd93ab9095bf15279bfb7c (diff)
downloadserd-ebcef72577398fa10a6ad6545317f704bcf9a1c4.tar.gz
serd-ebcef72577398fa10a6ad6545317f704bcf9a1c4.tar.bz2
serd-ebcef72577398fa10a6ad6545317f704bcf9a1c4.zip
Rearrange code, put common internal stuff in serd_internal.h.
git-svn-id: http://svn.drobilla.net/serd/trunk@46 490d8e77-9747-427b-9fa3-0b8f29cee8a0
Diffstat (limited to 'src/serd_stack.h')
-rw-r--r--src/serd_stack.h79
1 files changed, 0 insertions, 79 deletions
diff --git a/src/serd_stack.h b/src/serd_stack.h
deleted file mode 100644
index 7d8bcd07..00000000
--- a/src/serd_stack.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/* Serd, an RDF serialisation library.
- * Copyright 2011 David Robillard <d@drobilla.net>
- *
- * Serd is free software: you can redistribute it and/or modify it under
- * the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Serd is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
- * License for details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef SERD_STACK_H
-#define SERD_STACK_H
-
-#include <assert.h>
-
-#include "serd/serd.h"
-
-/** An offset to start the stack at. Note 0 is reserved for NULL. */
-#define SERD_STACK_BOTTOM sizeof(void*)
-
-typedef struct {
- uint8_t* buf; ///< Stack memory
- size_t buf_size; ///< Allocated size of buf (>= size)
- size_t size; ///< Conceptual size of stack in buf
-} SerdStack;
-
-static inline SerdStack
-serd_stack_new(size_t size)
-{
- SerdStack stack;
- stack.buf = malloc(size);
- stack.buf_size = size;
- stack.size = SERD_STACK_BOTTOM;
- return stack;
-}
-
-static inline bool
-serd_stack_is_empty(SerdStack* stack)
-{
- return stack->size <= SERD_STACK_BOTTOM;
-}
-
-static inline void
-serd_stack_free(SerdStack* stack)
-{
- free(stack->buf);
- stack->buf = NULL;
- stack->buf_size = 0;
- stack->size = 0;
-}
-
-static inline uint8_t*
-serd_stack_push(SerdStack* stack, size_t n_bytes)
-{
- const size_t new_size = stack->size + n_bytes;
- if (stack->buf_size < new_size) {
- stack->buf_size *= 2;
- stack->buf = realloc(stack->buf, stack->buf_size);
- }
- uint8_t* const ret = (stack->buf + stack->size);
- stack->size = new_size;
- return ret;
-}
-
-static inline void
-serd_stack_pop(SerdStack* stack, size_t n_bytes)
-{
- assert(stack->size >= n_bytes);
- stack->size -= n_bytes;
-}
-
-#endif // SERD_STACK_H