/home/nnn/Documents/Projects/dynarray/dynarray/include/dynarray.h File Reference
#include <malloc.h>
Go to the source code of this file.
Defines |
#define | DYNA_MALLOC(SIZE) |
#define | DYNA_REALLOC(POINTER, SIZE) |
#define | DYNA_FREE(POINTER) |
#define | DYNA_DECLARE(TYPE, NAME) |
#define | DYNA_DECLARE_STATIC(TYPE, NAME) |
#define | DYNA_INIT(TYPE, ARRAY) |
#define | DYNA_UNINIT(ARRAY) |
#define | DYNA_GET(ARRAY, INDEX) |
#define | DYNA_SET(ARRAY, INDEX) |
#define | DYNA_ADD(ARRAY, VALUE) |
#define | DYNA_INSERT(ARRAY, INDEX, VALUE) |
#define | DYNA_REMOVE(ARRAY, INDEX) |
#define | DYNA_DELETE(ARRAY, INDEX) |
#define | DYNA_REMOVE_ALL(ARRAY) |
#define | DYNA_DELETE_ALL(ARRAY) |
Detailed Description
- Author:
- Luiji Maryo <luiji@users.sourceforge.net>
- Version:
- 0.0
Copyright (c) 2010 Entertaining Software, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Macros to create and manipulate dynamically resizing arrays. It includes functions to add, insert, and remove elements from the array and has functions for properly maintaining lists of pointers (i.e. deallocating the pointers when they are removed from the array).
Define Documentation
#define DYNA_ADD |
( |
ARRAY, |
|
|
VALUE |
|
) |
|
Add the specified element to the array. Note: If you are passing a pointer, the array will contain a pointer to the same block of memory. This means that deallocating the memory that you pass to DYNA_ADD will also effect the array that you added the element to.
- Parameters:
-
| ARRAY | the name of the array to manipulate - Parameters:
-
| VALUE | the value to add to the array |
|
#define DYNA_DECLARE |
( |
TYPE, |
|
|
NAME |
|
) |
|
Declare a new array that accepts elements of the specified type. Afterwards you must call DYNA_INIT to initialize the array.
- Parameters:
-
| TYPE | the type that the array will hold - Parameters:
-
| NAME | the name for the array |
|
#define DYNA_DECLARE_STATIC |
( |
TYPE, |
|
|
NAME |
|
) |
|
Same as DYNA_DECLARE but with the variables declared with the static keyword.
#define DYNA_DELETE |
( |
ARRAY, |
|
|
INDEX |
|
) |
|
Free the block of memory pointed to by the specified element in the array then remove the pointer from the array (for use in pointer arrays only).
- Parameters:
-
| ARRAY | the name of the array to manipulate - Parameters:
-
| INDEX | the index of the pointer in question |
|
#define DYNA_DELETE_ALL |
( |
ARRAY |
|
) |
|
Call DYNA_DELETE on all of the elements of the array (for use in pointer arrays only).
- Parameters:
-
| ARRAY | the name of the array to manipulate |
#define DYNA_FREE |
( |
POINTER |
|
) |
|
Deallocate a chunk of memory.
Define DYNA_FREE before including dynarray.h in order to use an deallocation function other then C's standard free(). If DYNA_FREE is not declared, malloc.h will be automatically included.
- Parameters:
-
| POINTER | the pointer to the memory to deallocate |
#define DYNA_GET |
( |
ARRAY, |
|
|
INDEX |
|
) |
|
Get a value from a dynamic array.
- Parameters:
-
| ARRAY | the name of the array that has the value you want - Parameters:
-
| INDEX | the index of the value you want |
- Returns:
- the value you requested
|
#define DYNA_INIT |
( |
TYPE, |
|
|
ARRAY |
|
) |
|
Initialize a DynArray.
WARNING: Do NOT pass different values to DYNA_DECLARE or DYNA_DECLARE_STATIC and the corrosponding DYNA_INIT calls. It may result in seroius errors that may not be caught at compile-time.
- Parameters:
-
| TYPE | the same type that you passed to DYNA_DECLARE or DYNA_DECLARE_STATIC - Parameters:
-
| ARRAY | the array to initialize |
|
#define DYNA_INSERT |
( |
ARRAY, |
|
|
INDEX, |
|
|
VALUE |
|
) |
|
Insert the specified element into the array. Note: If you are passing a pointer, the array will contain a pointer to the same block of memory. This means that deallocating the memory that you pass to DYNA_INSERT will also effect the array that you inserted the element into.
- Parameters:
-
| ARRAY | the name of the array to manipulate - Parameters:
-
| INDEX | the index to insert the element at - Parameters:
-
| VALUE | the value to insert into the array |
|
|
#define DYNA_MALLOC |
( |
SIZE |
|
) |
|
Allocate a chunk of memory.
Define DYNA_MALLOC before including dynarray.h in order to use an allocation function other then C's standard malloc(). If DYNA_MALLOC is not declared, malloc.h will be automatically included.
- Parameters:
-
| SIZE | the size of the memory chunk to allocate |
#define DYNA_REALLOC |
( |
POINTER, |
|
|
SIZE |
|
) |
|
Allocate or resize a chunk of memory.
Define DYNA_REALLOC before including dynarray.h in order to use an allocation function other then C's standard realloc(). If DYNA_REALLOC is not declared, malloc.h will be automatically included.
- Parameters:
-
| POINTER | the pointer to the memory to resize - Parameters:
-
| SIZE | the new size for the memory chunk |
|
#define DYNA_REMOVE |
( |
ARRAY, |
|
|
INDEX |
|
) |
|
Remove the specified element from the array. Note: If it is a pointer array, the memory that is pointed to will NOT be deallocated. If it is a pointer that you want to remove and you want to free the memory pointed to, use DYNA_DELETE instead.
- Parameters:
-
| ARRAY | the name of the array to manipulate - Parameters:
-
| INDEX | the index of the value to remove from the array |
|
#define DYNA_REMOVE_ALL |
( |
ARRAY |
|
) |
|
Call DYNA_REMOVE on all of the elements of the array.
- Parameters:
-
| ARRAY | the name of the array to manipulate |
#define DYNA_SET |
( |
ARRAY, |
|
|
INDEX |
|
) |
|
Set a value in a dynamic array.
- Parameters:
-
| ARRAY | the name of the array to manipulate - Parameters:
-
| INDEX | the index in the array to manipulate - Parameters:
-
| VALUE | the new value for the specified index in the array |
|
|
#define DYNA_UNINIT |
( |
ARRAY |
|
) |
|
Uninitialize the specified array.
WARNING: If this is an array of pointers, you should use call DYNA_DELETE_ALL first to unallocate all of the memory chunks pointed to by the array.