Soletta™ Framework
Framework for making IoT devices

Full online documentation | C API Index
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Typedefs | Functions

Soletta vector is an array that grows dynamically. More...

Data Structures

struct  sol_vector
 Soletta vector is an array that grows dynamically. More...
 

Macros

#define SOL_VECTOR_FOREACH_IDX(vector, itrvar, idx)
 Macro to iterate over the vector easily. More...
 
#define SOL_VECTOR_FOREACH_IDX_UNTIL(vector, itrvar, idx, until)
 Macro to iterate over the vector until a index. More...
 
#define SOL_VECTOR_FOREACH_REVERSE_IDX(vector, itrvar, idx)
 Macro to iterate over the vector easily in the reverse order. More...
 
#define SOL_VECTOR_INIT(TYPE)   { NULL, 0, sizeof(TYPE) }
 Helper macro to initialize a sol_vector structure to hold elements of type TYPE. More...
 

Typedefs

typedef struct sol_vector sol_vector
 Soletta vector is an array that grows dynamically. More...
 

Functions

void * sol_vector_append (struct sol_vector *v)
 Append an element to the end of the vector. More...
 
void * sol_vector_append_n (struct sol_vector *v, uint16_t n)
 Append n elements to the end of the vector. More...
 
void sol_vector_clear (struct sol_vector *v)
 Delete all elements from the vector. More...
 
int sol_vector_del (struct sol_vector *v, uint16_t i)
 Remove an element from the vector. More...
 
int sol_vector_del_element (struct sol_vector *v, const void *elem)
 Remove an element from the vector. More...
 
static int sol_vector_del_last (struct sol_vector *v)
 Remove the last element from the vector. More...
 
int sol_vector_del_range (struct sol_vector *v, uint16_t start, uint16_t len)
 Remove an range of element from the vector. More...
 
static void * sol_vector_get (const struct sol_vector *v, uint16_t i)
 Return the element of the vector at the given index. More...
 
static void * sol_vector_get_no_check (const struct sol_vector *v, uint16_t i)
 Return the element of the vector at the given index (no safety checks). More...
 
void sol_vector_init (struct sol_vector *v, uint16_t elem_size)
 Initializes a sol_vector structure. More...
 
static void * sol_vector_steal_data (struct sol_vector *v)
 Steal the memory holding the elements of the vector. More...
 

Detailed Description

Soletta vector is an array that grows dynamically.

It's suited for storing a small set of contiguous data.

Warning
Its dynamic resize might shuffle the data around, so pointers returned from sol_vector_get() and sol_vector_append() should be considered invalid after the vector size is modified.
See Also
Pointer Vector

Macro Definition Documentation

#define SOL_VECTOR_FOREACH_IDX (   vector,
  itrvar,
  idx 
)
Value:
for (idx = 0; \
idx < (vector)->len && (itrvar = (__typeof__(itrvar))sol_vector_get_no_check((vector), idx), true); \
idx++)
static void * sol_vector_get_no_check(const struct sol_vector *v, uint16_t i)
Return the element of the vector at the given index (no safety checks).
Definition: sol-vector.h:126
size_t len
Slice length.
Definition: sol-str-slice.h:85

Macro to iterate over the vector easily.

Parameters
vectorThe vector to iterate over
itrvarVariable pointing to the current element's data on each iteration
idxIndex integer variable that is increased while iterating
Examples:
/src/samples/coap/iotivity-test-client.c, /src/samples/coap/lwm2m-client.c, /src/samples/coap/lwm2m-server.c, /src/samples/coap/oic-client.c, /src/samples/http/client.c, /src/samples/network/echo-server.c, and /src/samples/network/network-status.c.

Referenced by _on_network_event(), create_access_control_obj(), create_location_obj(), create_post_data_params(), create_security_obj(), create_server_obj(), found_resource(), found_resource_print(), location_changed_cb(), read_access_control_obj(), shutdown_server(), write_access_control_tlv(), write_security_tlv(), and write_server_tlv().

#define SOL_VECTOR_FOREACH_IDX_UNTIL (   vector,
  itrvar,
  idx,
  until 
)
Value:
for (idx = 0; \
idx < until && (itrvar = (__typeof__(itrvar))sol_vector_get_no_check((vector), idx), true); \
idx++)
static void * sol_vector_get_no_check(const struct sol_vector *v, uint16_t i)
Return the element of the vector at the given index (no safety checks).
Definition: sol-vector.h:126

Macro to iterate over the vector until a index.

Parameters
vectorThe vector to iterate over
itrvarVariable pointing to the current element's data on each iteration
idxIndex integer variable that is increased while iterating
untilThe index that the iteration should stop
#define SOL_VECTOR_FOREACH_REVERSE_IDX (   vector,
  itrvar,
  idx 
)
Value:
for (idx = (vector)->len - 1; \
idx != ((__typeof__(idx)) - 1) && (itrvar = (__typeof__(itrvar))sol_vector_get_no_check((vector), idx), true); \
idx--)
static void * sol_vector_get_no_check(const struct sol_vector *v, uint16_t i)
Return the element of the vector at the given index (no safety checks).
Definition: sol-vector.h:126
size_t len
Slice length.
Definition: sol-str-slice.h:85

Macro to iterate over the vector easily in the reverse order.

Parameters
vectorThe vector to iterate over
itrvarVariable pointing to the current element's data on each iteration
idxIndex integer variable that is decreased while iterating
#define SOL_VECTOR_INIT (   TYPE)    { NULL, 0, sizeof(TYPE) }

Helper macro to initialize a sol_vector structure to hold elements of type TYPE.

Typedef Documentation

typedef struct sol_vector sol_vector

Soletta vector is an array that grows dynamically.

For storing pointers, see sol_ptr_vector.

See Also
sol_ptr_vector

Function Documentation

void* sol_vector_append ( struct sol_vector v)

Append an element to the end of the vector.

Creates a new element in end of the vector and returns a pointer to it.

Parameters
vVector pointer
Returns
Pointer to the added element
Remarks
Time complexity: amortized constant
Examples:
/src/samples/coap/lwm2m-client.c, and /src/samples/network/echo-server.c.

Referenced by on_can_read(), read_access_control_obj(), write_access_control_res(), and write_or_create_acl().

void* sol_vector_append_n ( struct sol_vector v,
uint16_t  n 
)

Append n elements to the end of the vector.

Creates n new elements in end of the vector and returns a pointer to the first of the n elements.

Parameters
vVector pointer
nNumber of elements to be appended
Returns
Pointer to the first of the n elements appended
Remarks
Time complexity: amortized linear in the number of elements appended
void sol_vector_clear ( struct sol_vector v)

Delete all elements from the vector.

And frees the memory allocated for them. The vector returns to the initial state (empty).

Parameters
vVector pointer
Remarks
Time complexity: constant
Examples:
/src/samples/coap/lwm2m-client.c, /src/samples/http/client.c, and /src/samples/network/echo-server.c.

Referenced by create_access_control_obj(), create_post_data_params(), del_access_control_obj(), read_access_control_obj(), shutdown_server(), sol_ptr_vector_clear(), write_access_control_res(), and write_access_control_tlv().

int sol_vector_del ( struct sol_vector v,
uint16_t  i 
)

Remove an element from the vector.

Removes the element of index i from the vector.

Parameters
vVector pointer
iIndex of the element to remove
Returns
0 on success, error code (always negative) otherwise
Remarks
Time complexity: linear in distance between i and the end of the vector
Examples:
/src/samples/network/echo-server.c.

Referenced by on_can_write(), sol_ptr_vector_del(), and sol_vector_del_last().

int sol_vector_del_element ( struct sol_vector v,
const void *  elem 
)

Remove an element from the vector.

Removes the element pointed by elem from the vector.

Parameters
vVector pointer
elemPointer of the element to remove
Returns
0 on success, error code (always negative) otherwise
Remarks
Time complexity: linear in distance between elem and the end of the vector
static int sol_vector_del_last ( struct sol_vector v)
inlinestatic

Remove the last element from the vector.

Parameters
vVector pointer
Returns
0 on success, error code (always negative) otherwise
Remarks
Time complexity: amortized constant

References sol_vector::len, and sol_vector_del().

int sol_vector_del_range ( struct sol_vector v,
uint16_t  start,
uint16_t  len 
)

Remove an range of element from the vector.

Removes the range starting at index start from the vector and goes until start + len.

Parameters
vVector pointer
startIndex of the first element to remove
lenthe number of elements to remover
Returns
0 on success, error code (always negative) otherwise

Referenced by sol_ptr_vector_del_range().

static void* sol_vector_get ( const struct sol_vector v,
uint16_t  i 
)
inlinestatic

Return the element of the vector at the given index.

Parameters
vVector pointer
iIndex of the element to return
Returns
Pointer to the element at the index i or NULL on errors.
Remarks
Time complexity: constant
Examples:
/src/samples/coap/lwm2m-client.c, and /src/samples/network/echo-server.c.

References sol_vector::len, and sol_vector_get_no_check().

Referenced by on_can_write(), and write_or_create_acl().

static void* sol_vector_get_no_check ( const struct sol_vector v,
uint16_t  i 
)
inlinestatic

Return the element of the vector at the given index (no safety checks).

This is similar to sol_vector_get(), but does no safety checks such as array boundaries. Only use this whenever you're sure the index i exists.

Parameters
vVector pointer
iIndex of the element to return
Returns
Pointer to the element at the index i
Remarks
Time complexity: constant
See Also
sol_vector_get()

References sol_vector::data, and sol_vector::elem_size.

Referenced by sol_ptr_vector_get_no_check(), and sol_vector_get().

void sol_vector_init ( struct sol_vector v,
uint16_t  elem_size 
)

Initializes a sol_vector structure.

Parameters
vPointer to the sol_vector structure to be initialized
elem_sizeThe size of each element in bytes
Examples:
/src/samples/coap/lwm2m-client.c, and /src/samples/network/echo-server.c.

Referenced by create_access_control_obj(), read_access_control_obj(), sol_http_params_init(), sol_ptr_vector_init(), and startup_server().

static void* sol_vector_steal_data ( struct sol_vector v)
inlinestatic

Steal the memory holding the elements of the vector.

And returns the vector to the initial state.

Parameters
vVector pointer
Returns
Pointer to the memory containing the elements
Remarks
Time complexity: constant

References sol_vector::data, and sol_vector::len.

Referenced by sol_ptr_vector_steal_data().