summaryrefslogtreecommitdiff
path: root/liveengineUnmapped/ofxSVGTiny/libs/svgtiny_list.c
diff options
context:
space:
mode:
authorTim Redfern <tim@eclectronics.org>2014-04-26 18:20:21 +0100
committerTim Redfern <tim@eclectronics.org>2014-04-26 18:20:21 +0100
commit6f74f80e4c116c61b4734ffbae86aff881daaf5b (patch)
treec0044aa2efefd53711cba63ed91860e265831703 /liveengineUnmapped/ofxSVGTiny/libs/svgtiny_list.c
parentba9af7648a79b54836019ca792e40e81ca863c86 (diff)
started GLFW version
Diffstat (limited to 'liveengineUnmapped/ofxSVGTiny/libs/svgtiny_list.c')
-rw-r--r--liveengineUnmapped/ofxSVGTiny/libs/svgtiny_list.c125
1 files changed, 0 insertions, 125 deletions
diff --git a/liveengineUnmapped/ofxSVGTiny/libs/svgtiny_list.c b/liveengineUnmapped/ofxSVGTiny/libs/svgtiny_list.c
deleted file mode 100644
index 53cfb34..0000000
--- a/liveengineUnmapped/ofxSVGTiny/libs/svgtiny_list.c
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * This file is part of Libsvgtiny
- * Licensed under the MIT License,
- * http://opensource.org/licenses/mit-license.php
- * Copyright 2008 James Bursa <james@semichrome.net>
- */
-
-/**
- * A svgtiny_list is a managed array of objects. It grows in chunks to reduce
- * calls to realloc(), but keeps wasted space low.
- */
-
-#include <assert.h>
-#include "svgtiny.h"
-#include "svgtiny_internal.h"
-
-
-struct svgtiny_list {
- unsigned int size; /* number of slots used */
- unsigned int allocated; /* number of slots allocated (>= size) */
- size_t item_size; /* size of each slot / bytes */
- char *items; /* array of slots */
-};
-
-
-/**
- * Create an empty svgtiny_list.
- */
-
-struct svgtiny_list *svgtiny_list_create(size_t item_size)
-{
- struct svgtiny_list *list = malloc(sizeof *list);
- if (!list)
- return 0;
- list->size = 0;
- list->allocated = 0;
- list->item_size = item_size;
- list->items = 0;
- return list;
-}
-
-
-/**
- * Return the number of objects in a list.
- */
-
-unsigned int svgtiny_list_size(struct svgtiny_list *list)
-{
- return list->size;
-}
-
-
-/**
- * Set the number of objects in a list. If the size is increased, the new
- * objects are not initialized in any way.
- *
- * The allocation size formula is taken from Python's list:
- * http://svn.python.org/view/python/trunk/Objects/listobject.c?view=markup
- *
- * Objects may have moved after this call. Use svgtiny_list_get() to get new
- * pointers.
- */
-
-svgtiny_code svgtiny_list_resize(struct svgtiny_list *list,
- unsigned int new_size)
-{
- unsigned int new_allocated;
- void *new_items;
-
- if (new_size <= list->allocated) {
- list->size = new_size;
- return svgtiny_OK;
- }
-
- new_allocated = (new_size >> 3) + (new_size < 9 ? 3 : 6) + new_size;
- if (new_size == 0)
- new_allocated = 0;
- new_items = realloc(list->items, new_allocated * list->item_size);
- if (!new_items)
- return svgtiny_OUT_OF_MEMORY;
-
- list->size = new_size;
- list->allocated = new_allocated;
- list->items = new_items;
-
- return svgtiny_OK;
-}
-
-
-/**
- * Return a pointer to an object in a list.
- */
-
-void *svgtiny_list_get(struct svgtiny_list *list,
- unsigned int i)
-{
- assert(i < list->size);
- return (void *) (list->items + i * list->item_size);
-}
-
-
-/**
- * Add space for one object to a list and return a pointer to it.
- */
-
-void *svgtiny_list_push(struct svgtiny_list *list)
-{
- svgtiny_code code;
- code = svgtiny_list_resize(list, list->size + 1);
- if (code != svgtiny_OK)
- return 0;
- return svgtiny_list_get(list, list->size - 1);
-}
-
-
-/**
- * Free an entire list.
- */
-
-void svgtiny_list_free(struct svgtiny_list *list)
-{
- free(list->items);
- free(list);
-}
-