|
CMagic
0.5.0
Portable C library of utilities and data structures
|
Implementation of a vector container. More...
#include <assert.h>#include <stdbool.h>#include <stddef.h>#include "cmagic/utils.h"#include "cmagic/memory.h"Go to the source code of this file.
Macros | |
| #define | CMAGIC_VECTOR(type) type** |
Convenient alias for type**. Returned type of CMAGIC_VECTOR_NEW. More... | |
| #define | CMAGIC_VECTOR_DATA(cmagic_vector) (*(cmagic_vector)) |
| Gets an address to the beginning of the vector data. More... | |
| #define | CMAGIC_VECTOR_BACK(cmagic_vector) |
| Gets an address of the last element in the vector. More... | |
| #define | CMAGIC_VECTOR_NEW(type, alloc_packet) ((CMAGIC_VECTOR(type))cmagic_vector_new(sizeof(type), (alloc_packet))) |
| Allocates and returns an address of a newly created empty vector. More... | |
| #define | CMAGIC_VECTOR_FREE(cmagic_vector) cmagic_vector_free((void**)(cmagic_vector)) |
| Frees the resources allocated by the vector before. More... | |
| #define | CMAGIC_VECTOR_ALLOCATE_BACK(cmagic_vector) cmagic_vector_allocate_back((void**)(cmagic_vector)) |
| Allocates space for a new element but does not initialize it. More... | |
| #define | CMAGIC_VECTOR_PUSH_BACK(cmagic_vector, new_element_ptr) |
Allocates space for a new element and initializes it with data under new_element_ptr. More... | |
| #define | CMAGIC_VECTOR_POP_BACK(cmagic_vector) cmagic_vector_pop_back((void**)(cmagic_vector)) |
| Deallocates the last element in the vector. More... | |
| #define | CMAGIC_VECTOR_SIZE(cmagic_vector) cmagic_vector_size((void**)(cmagic_vector)) |
| Deallocates the last element in the vector. More... | |
| #define | CMAGIC_VECTOR_GET_ALLOC_PACKET(cmagic_vector) cmagic_vector_get_alloc_packet((void**)(cmagic_vector)) |
| Extracts cmagic_memory_alloc_packet_t which was used as an argument of CMAGIC_VECTOR_NEW. More... | |
Implementation of a vector container.
Please use provided macros instead of raw functions to gain additional type checks.
| #define CMAGIC_VECTOR | ( | type | ) | type** |
Convenient alias for type**. Returned type of CMAGIC_VECTOR_NEW.
| type | type of vector elements |
| #define CMAGIC_VECTOR_ALLOCATE_BACK | ( | cmagic_vector | ) | cmagic_vector_allocate_back((void**)(cmagic_vector)) |
Allocates space for a new element but does not initialize it.
The new element can be accessed by CMAGIC_VECTOR_BACK
| cmagic_vector | a vector allocated before with CMAGIC_VECTOR_NEW |
true if allocation of the a new element was successful, false if there's not sufficient memory space and the vector was not modified | #define CMAGIC_VECTOR_BACK | ( | cmagic_vector | ) |
Gets an address of the last element in the vector.
| cmagic_vector | a vector allocated before with CMAGIC_VECTOR_NEW |
| #define CMAGIC_VECTOR_DATA | ( | cmagic_vector | ) | (*(cmagic_vector)) |
Gets an address to the beginning of the vector data.
| cmagic_vector | a vector allocated before with CMAGIC_VECTOR_NEW |
| #define CMAGIC_VECTOR_FREE | ( | cmagic_vector | ) | cmagic_vector_free((void**)(cmagic_vector)) |
Frees the resources allocated by the vector before.
Must not use cmagic_vector after free.
| cmagic_vector | a vector allocated before with CMAGIC_VECTOR_NEW |
| #define CMAGIC_VECTOR_GET_ALLOC_PACKET | ( | cmagic_vector | ) | cmagic_vector_get_alloc_packet((void**)(cmagic_vector)) |
Extracts cmagic_memory_alloc_packet_t which was used as an argument of CMAGIC_VECTOR_NEW.
| cmagic_vector | a vector allocated before with CMAGIC_VECTOR_NEW |
| #define CMAGIC_VECTOR_NEW | ( | type, | |
| alloc_packet | |||
| ) | ((CMAGIC_VECTOR(type))cmagic_vector_new(sizeof(type), (alloc_packet))) |
Allocates and returns an address of a newly created empty vector.
| type | type of vector elements |
| alloc_packet | cmagic_memory_alloc_packet_t suite of dynamic memory managing functions |
| #define CMAGIC_VECTOR_POP_BACK | ( | cmagic_vector | ) | cmagic_vector_pop_back((void**)(cmagic_vector)) |
Deallocates the last element in the vector.
| cmagic_vector | a vector allocated before with CMAGIC_VECTOR_NEW |
| #define CMAGIC_VECTOR_PUSH_BACK | ( | cmagic_vector, | |
| new_element_ptr | |||
| ) |
Allocates space for a new element and initializes it with data under new_element_ptr.
The new element can be accessed by CMAGIC_VECTOR_BACK
| cmagic_vector | a vector allocated before with CMAGIC_VECTOR_NEW |
| new_element_ptr | pointer to a value to be copied into the new element |
true if allocation and initialization of the a new element was successful, false if there's not sufficient memory space and the vector was not modified | #define CMAGIC_VECTOR_SIZE | ( | cmagic_vector | ) | cmagic_vector_size((void**)(cmagic_vector)) |
Deallocates the last element in the vector.
| cmagic_vector | a vector allocated before with CMAGIC_VECTOR_NEW |
1.8.13