FDOSTUI
FreeDOS Text User Interface
Classes | Functions
array.h File Reference

A dynamic array that holds pointers to objects. More...

Go to the source code of this file.

Classes

struct  array
 container to hold objects More...
 

Functions

void array_assign (struct array *const o_arr, size_t const i_growby)
 initialize arrary object More...
 
void array_discharge (struct array *const io_arr)
 release resources held by object. The routine will not release resources held by the object itself. More...
 
void * array_pop (struct array *const io_arr)
 remove an element from the end of the array. Ownership of the object is transferred to the caller. More...
 
int array_push (struct array *const io_arr, void *io_object)
 adds an element to the end of the array More...
 
void * array_remove (struct array *const io_arr, size_t const i_index)
 removes an element from the array Ownership of the object is transferred to the caller. More...
 

Detailed Description

A dynamic array that holds pointers to objects.

#include "array.h"
struct array myarray;
char * textptr;
#define GROWBY 30
assign_array(&myarray, GROWBY);
#undef GROWBY
for (some loop construct)
{
textptr= input_get_text();
array_push(&m_array, textptr);
}
for (; textptr= array_pop(&m_array) ;)
{
free(text_ptr);
}
array_discharge(&my_array;

Function Documentation

◆ array_assign()

void array_assign ( struct array *const  o_arr,
size_t const  i_growby 
)

initialize arrary object

Parameters
[out]o_arrobject ot initialize
[in]i_growbynumber of elements to growby (expand) when array is full
Returns
none

Memory allocated to store objects is peformed in array_push.

◆ array_discharge()

void array_discharge ( struct array *const  io_arr)

release resources held by object. The routine will not release resources held by the object itself.

Parameters
[in,ou]io_arr object to release
Returns
none
array myarray;
array_assign(&myarray, 1);
struct mydata* ptr= (struct mydata*)malloc(sizeof(*ptr));
for(; ptr= array_pop(&myarray); ) free(ptr);
array_discharge(&myarray);

◆ array_pop()

void * array_pop ( struct array *const  io_arr)

remove an element from the end of the array. Ownership of the object is transferred to the caller.

Parameters
[in,out]io_arrobject to remove an element
Returns
0 array is empty
!0 pointer to element

◆ array_push()

int array_push ( struct array *const  io_arr,
void *  io_object 
)

adds an element to the end of the array

Parameters
[in,out]io_arrobject to store element
[in,out]io_objectobject to store
Returns
0 success object added
-1 error unable to add object

◆ array_remove()

void * array_remove ( struct array *const  io_arr,
size_t const  i_index 
)

removes an element from the array Ownership of the object is transferred to the caller.

Parameters
[in,out]io_arrobject to remove element from
[in]i_indexzero based slot containing element to remove
Returns
0 array is empty or out of bounds
!0 pointer to removed object