vec

Overview

Module that defines the macros to generate vector types.

Type and Definitions

cVecInfo

struct cVecInfo
{
   int64_t count;
   int64_t cap;
};
typedef struct cVecInfo cVecInfo;

cVecInfo stores the properties of the vector. The count value tells how much elements are stored in the vector, cap shows how much elements the vector can store without to grow.

Code Generation Macros

create

MAKE_VEC_C_

#define MAKE_VEC_C_(                                                           \
   FuncSuffix, VecType, ValType, Meta                                          \
)

Generates a constructor function to create an instance with an initial container capacity. The generated function has the following common signature:

VecType* make_FuncSuffix( int64_t cap );

NEW_VEC_C_

#define NEW_VEC_C_(                                                            \
   FuncSuffix, VecType                                                         \
)

Generates a constructor function to create an instance with the default initial container capacity. The generated function has the following common signature:

VecType* new_FuncSuffix();

manage

DATA_OF_VEC_C_

#define DATA_OF_VEC_C_(                                                        \
   FuncSuffix, VecType, ValType                                                \
)

Generates a function that returns a pointer to read the array of the vector. The generated function has the following common signature:

ValType const* data_of_FuncSuffix( VecType const* vec );

VAR_DATA_OF_VEC_C_

#define VAR_DATA_OF_VEC_C_(                                                    \
   FuncSuffix, VecType, ValType                                                \
)

Generates a function that returns a pointer to manipulate the array of the vector. The generated function has the following common signature:

ValType* var_data_of_FuncSuffix( VecType* vec );

RESIZE_VEC_C_

#define RESIZE_VEC_C_(                                                         \
   FuncSuffix, VecType, ValType                                                \
)

Generates a function to resize the vector capacity. Returns false if cap is less then the number of elements in the vector or the reallocation fails, otherwise true. The generated function has the following common signature:

bool resize_FuncSuffix( VecType* vec, int64_t cap );

INFO_OF_VEC_C_

#define INFO_OF_C_(                                                            \
   FuncSuffix, VecType                                                         \
)

Generates a function that returns a reference to the info from the vector. The generated function has the following common signature:

cVecInfo const* info_of_FuncSuffix( VecType* vec );

api

ACCESS_VEC_C_

#defien ACCESS_VEC_C_(                                                         \
   FuncSuffix, VecType, ValType                                                \
)

Generates a function to access the element in the vector at pos. The generated function has the following common signature:

ValType* access_FuncSuffx( VecType* vec, int64_t pos );

ADD_TO_VEC_C_

#define ADD_TO_VEC_C_(                                                         \
   FuncSuffix, VecType, ValType, Retain, DoDeref                               \
)

Generates a function to add a object to the vector. The generated function has the following common signature:

bool add_to_FuncSuffix( VecType* vec, ValType obj );

ADD_ARRAY_TO_VEC_C_

#define ADD_ARRAY_TO_VEC_C_(                                                   \
   FuncSuffix, VecType, ValType, Retain                                        \
)

Generates a function to fill the vector with the objects from an array. The generated function has the following common signature:

bool add_array_to_FuncSuffix( VecType* vec, int64_t n, ValType const* arr );

GET_FROM_VEC_C_

#define GET_FROM_VEC_C_(                                                       \
   FuncSuffix, VecType, ReturnType, DoDeref                                    \
)

Generates a function that returns the object at pos in the vector. The generated function has the following common signature:

ReturnType get_from_FuncSuffix( VecType const* vec, int64_t pos );

INSERT_INTO_VEC_C_

#define INSERT_INTO_VEC_C_(                                                    \
   FuncSuffix, VecType, ValType, Retain                                        \
)

Generates a function that inserts a object before the object at pos, increasing the container by the inserted object. The generated fucntion has the following common signature:

bool insert_into_FuncSuffix( VecType* vec, int64_t pos, ValType val );

REMOVE_FROM_VEC_C_

#define REMOVE_FROM_VEC_C_(                                                    \
   FuncName, VecType, ValType, Release                                         \
)

Generates a function that removes the value at pos in the vector. The generated function has the following common signature:

bool remove_from_FuncSuffix( VecType* vec, int64_t pos );

SET_ON_VEC_C_

#define SET_ON_VEC_C_(                                                         \
   FuncSuffix, VecType, ValType, Retain, Release, DoDeref                      \
)

Generates a function that overwrites the value at pos in the vector. The generated function has the following common signature:

void set_on_FuncSuffix( VecType* vec, int64_t pos, ValType val );

type

VEC_STRUCT_C_

#define VEC_STRUCT_C_(
   VecType, ValType
)

Generates the struct that all function in this module use.

OBJ_VEC_DEF_C_

#define OBJ_VEC_DEF_C_(                                                        \
   FuncName, VecType, ObjType, Meta                                            \
)

Generates the definition of a vector to store objects from type ObjType for a .h file.

struct VecType;
typedef struct VecType VecType;
extern cMeta const Meta;
/**************************************/
VecType* make_FuncSuffix( int64_t size );
VecType* new_FuncSuffix();
/**************************************/
ObjType* const* data_of_FuncSuffix( VecType const* vec );
cVecInfo const* info_of_FuncSuffix( VecType const* vec );
bool resize_FuncSuffix( VecType* vec, int64_t size );
ObjType** var_data_of_FuncSuffix( VecType* vec );
/**************************************/
bool add_to_FuncSuffix( VecType* vec, ObjType* obj );
bool add_array_to_FuncSuffix( VecType* vec, int64_t n, ObjType* const* arr );
ObjType* get_from_FuncSuffix( VecType const* vec, int64_t pos );
bool insert_into_FuncSuffix( VecType* vec, int64_t pos, ObjType* obj );
bool remove_from_FuncSuffix( VecType* vec, int64_t pos );
void set_on_FuncSuffix( VecType* vec, int64_t pos, ObjType* obj );

OBJ_VEC_IMPL_C_

#define OBJ_VEC_IMPL_C_(                                                       \
   Static, VecType, ObjType, FuncName, Meta                                    \
)

Generates the implementation of a vector to store objects from type ObjType for a .c file. The Static value can be used to define the visibility of the functions.

VAL_VEC_DEF_C_

#define VAL_VEC_DEF_C_(                                                        \
   VecType, ValType, FuncName, Meta                                            \
)

Generates the definition of a vector to store values from type ValType for a .h file.

struct VecType;
typedef struct VecType VecType;
extern cMeta const Meta;
/**************************************/
VecType* make_FuncSuffix( int64_t cap );
VecType* new_FuncSuffix();
/**************************************/
ValType const* data_of_FuncSuffix( VecType const* vec );
ValType* var_data_of_FuncSuffix( VecType* vec );
/**************************************/
cVecInfo const* info_of_FuncSuffix( VecType const* vec );
bool resize_FuncSuffix( VecType* vec, int64_t cap );
/**************************************/
bool add_to_FuncSuffix( VecType* vec, ValType val );
bool add_array_to_FuncSuffix( VecType* vec, int64_t n, ValType const* arr );
ValType const* get_from_FuncSuffix( VecType const* vec, int64_t pos );
ValType* get_var_from_FuncSuffix( VecType* vec, int64_t pos );
bool insert_into_FuncSuffix( VecType* vec, int64_t pos, ValType val );
bool remove_from_FuncSuffix( VecType* vec, int64_t pos );
void set_on_FuncSuffix( VecType* vec, int64_t pos, ValType val );

VAL_VEC_IMPL_C_

#define VAL_VEC_IMPL_C_(                                                       \
   Static, VecType, ValType, FuncName, Meta                                    \
)

Generates the implementation of a vector to store values from type ValType for a .c file. The static value can be used to define the visibility of the functions.

extra

SLICE_OF_VEC_C_

#defien SLICE_OF_VEC_C_(                                                       \
   FuncSuffix, VecType, SliceType                                              \
)

Generates a function to access the data of a vec as slice. The generated function has the following common signature:

SliceType slice_of_FuncSuffix( VecType const* vec );

VAR_SLICE_OF_VEC_C_

#define VAR_SLICE_OF_VEC_C_(                                                   \
   FuncSuffix, VecType, SliceType                                              \
)

Generates a function to access the data of a vec as var slice. The generated function has the following common signature:

SliceType var_slice_of_FuncSuffix( VecType* vec );

Functions

info

vec_load_c

float vec_load_c( cVecInfo const info[static 1] );

Returns the load factor of a vector.

vec_is_empty_c

bool vec_is_empty_c( cVecInfo const info[static 1] );

Returns if a vector os empty.