wlmaker
Loading...
Searching...
No Matches
Classes | Functions | Variables
model.c File Reference
#include "model.h"
#include <libbase/libbase.h>
Include dependency graph for model.c:

Classes

struct  _wlmcfg_object_t
 
struct  _wlmcfg_string_t
 
struct  _wlmcfg_dict_t
 
struct  wlmcfg_dict_item_t
 
struct  _wlmcfg_array_t
 

Functions

static bool _wlmcfg_object_init (wlmcfg_object_t *object_ptr, wlmcfg_type_t type, void(*destroy_fn)(wlmcfg_object_t *object_ptr))
 
static void _wlmcfg_string_object_destroy (wlmcfg_object_t *object_ptr)
 
static void _wlmcfg_dict_object_destroy (wlmcfg_object_t *object_ptr)
 
static void _wlmcfg_array_object_destroy (wlmcfg_object_t *object_ptr)
 
static wlmcfg_dict_item_t_wlmcfg_dict_item_create (const char *key_ptr, wlmcfg_object_t *object_ptr)
 
static void _wlmcfg_dict_item_destroy (wlmcfg_dict_item_t *item_ptr)
 
static int _wlmcfg_dict_item_node_cmp (const bs_avltree_node_t *node_ptr, const void *key_ptr)
 
static void _wlmcfg_dict_item_node_destroy (bs_avltree_node_t *node_ptr)
 
wlmcfg_object_twlmcfg_object_ref (wlmcfg_object_t *object_ptr)
 
void wlmcfg_object_unref (wlmcfg_object_t *object_ptr)
 
wlmcfg_string_twlmcfg_string_create (const char *value_ptr)
 
const char * wlmcfg_string_value (const wlmcfg_string_t *string_ptr)
 
wlmcfg_object_twlmcfg_object_from_string (wlmcfg_string_t *string_ptr)
 
wlmcfg_string_twlmcfg_string_from_object (wlmcfg_object_t *object_ptr)
 
wlmcfg_dict_twlmcfg_dict_create (void)
 
bool wlmcfg_dict_add (wlmcfg_dict_t *dict_ptr, const char *key_ptr, wlmcfg_object_t *object_ptr)
 
wlmcfg_object_twlmcfg_dict_get (wlmcfg_dict_t *dict_ptr, const char *key_ptr)
 
wlmcfg_object_twlmcfg_object_from_dict (wlmcfg_dict_t *dict_ptr)
 
wlmcfg_dict_twlmcfg_dict_from_object (wlmcfg_object_t *object_ptr)
 
bool wlmcfg_dict_foreach (wlmcfg_dict_t *dict_ptr, bool(*fn)(const char *key_ptr, wlmcfg_object_t *object_ptr, void *userdata_ptr), void *userdata_ptr)
 
wlmcfg_array_twlmcfg_array_create (void)
 
bool wlmcfg_array_push_back (wlmcfg_array_t *array_ptr, wlmcfg_object_t *object_ptr)
 
size_t wlmcfg_array_size (wlmcfg_array_t *array_ptr)
 
wlmcfg_object_twlmcfg_array_at (wlmcfg_array_t *array_ptr, size_t index)
 
wlmcfg_object_twlmcfg_object_from_array (wlmcfg_array_t *array_ptr)
 
wlmcfg_array_twlmcfg_array_from_object (wlmcfg_object_t *object_ptr)
 
static void test_string (bs_test_t *test_ptr)
 
static void test_dict (bs_test_t *test_ptr)
 
static void test_array (bs_test_t *test_ptr)
 
static bool foreach_callback (const char *key_ptr, wlmcfg_object_t *object_ptr, void *userdata_ptr)
 

Variables

const bs_test_case_t wlmcfg_model_test_cases []
 

Detailed Description

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Function Documentation

◆ _wlmcfg_array_object_destroy()

void _wlmcfg_array_object_destroy ( wlmcfg_object_t * object_ptr)
static

Implementation of wlmcfg_object_t::destroy_fn. Destroys the array, including all contained elements.

Parameters
object_ptr

◆ _wlmcfg_dict_item_create()

wlmcfg_dict_item_t * _wlmcfg_dict_item_create ( const char * key_ptr,
wlmcfg_object_t * object_ptr )
static

Ctor: Creates a dict item. Copies the key, and duplicates the object.

◆ _wlmcfg_dict_item_destroy()

void _wlmcfg_dict_item_destroy ( wlmcfg_dict_item_t * item_ptr)
static

Dtor: Destroys the dict item.

◆ _wlmcfg_dict_item_node_cmp()

int _wlmcfg_dict_item_node_cmp ( const bs_avltree_node_t * node_ptr,
const void * key_ptr )
static

Comparator for the dictionary item with another key.

◆ _wlmcfg_dict_item_node_destroy()

void _wlmcfg_dict_item_node_destroy ( bs_avltree_node_t * node_ptr)
static

Destroy dict item by avlnode. Forward to _wlmcfg_dict_item_destroy.

◆ _wlmcfg_dict_object_destroy()

void _wlmcfg_dict_object_destroy ( wlmcfg_object_t * object_ptr)
static

Implementation of wlmcfg_object_t::destroy_fn. Destroys the dict, including all contained elements.

Parameters
object_ptr

◆ _wlmcfg_object_init()

bool _wlmcfg_object_init ( wlmcfg_object_t * object_ptr,
wlmcfg_type_t type,
void(*)(wlmcfg_object_t *object_ptr) destroy_fn )
static

Initializes the object base class.

Parameters
object_ptr
type
destroy_fn
Returns
true on success.

◆ _wlmcfg_string_object_destroy()

void _wlmcfg_string_object_destroy ( wlmcfg_object_t * object_ptr)
static

Implementation of wlmcfg_object_t::destroy_fn. Destroys the string.

Parameters
object_ptr

◆ foreach_callback()

static bool foreach_callback ( const char * key_ptr,
wlmcfg_object_t * object_ptr,
void * userdata_ptr )
static

Test helper: A callback for wlmcfg_dict_foreach.

◆ test_array()

void test_array ( bs_test_t * test_ptr)
static

Tests the wlmcfg_array_t methods.

◆ test_dict()

void test_dict ( bs_test_t * test_ptr)
static

Tests the wlmcfg_dict_t methods.

◆ test_string()

void test_string ( bs_test_t * test_ptr)
static

Tests the wlmcfg_string_t methods.

◆ wlmcfg_array_at()

wlmcfg_object_t * wlmcfg_array_at ( wlmcfg_array_t * array_ptr,
size_t index )

Returns the object at the position index of the array.

Parameters
array_ptr
index
Returns
Pointer to the object at the specified position in the array. Returns NULL if index is out of bounds.

◆ wlmcfg_array_create()

wlmcfg_array_t * wlmcfg_array_create ( void )

Creates an array object.

Returns
The array object, or NULL on error.

◆ wlmcfg_array_from_object()

wlmcfg_array_t * wlmcfg_array_from_object ( wlmcfg_object_t * object_ptr)
Returns
the wlmcfg_array_t for object_ptr. NULL if not an array.

◆ wlmcfg_array_push_back()

bool wlmcfg_array_push_back ( wlmcfg_array_t * array_ptr,
wlmcfg_object_t * object_ptr )

Adds an object to the end of the array.

Parameters
array_ptr
object_ptr
Returns
true on success. Adding the object can fail if the array does not have space and fails to grow.

◆ wlmcfg_array_size()

size_t wlmcfg_array_size ( wlmcfg_array_t * array_ptr)
Returns
Size of the array, ie. the number of contained objects.

◆ wlmcfg_dict_add()

bool wlmcfg_dict_add ( wlmcfg_dict_t * dict_ptr,
const char * key_ptr,
wlmcfg_object_t * object_ptr )

Adds an object to the dict.

Parameters
dict_ptr
key_ptr
object_ptrThe object to add. It will be duplicated by calling wlmcfg_object_ref.
Returns
true on success. Adding the object can fail if the key already exists, or if memory could not get allocated.

◆ wlmcfg_dict_create()

wlmcfg_dict_t * wlmcfg_dict_create ( void )

Creates a dict object.

Returns
The dict object, or NULL on error.

◆ wlmcfg_dict_foreach()

bool wlmcfg_dict_foreach ( wlmcfg_dict_t * dict_ptr,
bool(*)(const char *key_ptr, wlmcfg_object_t *object_ptr, void *userdata_ptr) fn,
void * userdata_ptr )

Executes fn for each key and object of the dict.

Parameters
dict_ptr
fn
userdata_ptr
Returns
true if all calls to fn returned true. The iteration will be aborted on the first failed call to fn.

◆ wlmcfg_dict_from_object()

wlmcfg_dict_t * wlmcfg_dict_from_object ( wlmcfg_object_t * object_ptr)
Returns
the wlmcfg_dict_t for object_ptr. NULL if not a dict.

◆ wlmcfg_dict_get()

wlmcfg_object_t * wlmcfg_dict_get ( wlmcfg_dict_t * dict_ptr,
const char * key_ptr )
Returns
the given object from the dict.

◆ wlmcfg_object_from_array()

wlmcfg_object_t * wlmcfg_object_from_array ( wlmcfg_array_t * array_ptr)
Returns
the superclass wlmcfg_object_t of the array.

◆ wlmcfg_object_from_dict()

wlmcfg_object_t * wlmcfg_object_from_dict ( wlmcfg_dict_t * dict_ptr)
Returns
the superclass wlmcfg_object_t of the dict.

◆ wlmcfg_object_from_string()

wlmcfg_object_t * wlmcfg_object_from_string ( wlmcfg_string_t * string_ptr)

Gets the superclass wlmcfg_object_t from the string.

◆ wlmcfg_object_ref()

wlmcfg_object_t * wlmcfg_object_ref ( wlmcfg_object_t * object_ptr)

Gets a reference to the object. Increases the reference count.

The reference should be released by calling wlmcfg_object_unref.

Parameters
object_ptr
Returns
Same as "object_ptr".

◆ wlmcfg_object_unref()

void wlmcfg_object_unref ( wlmcfg_object_t * object_ptr)

Removes reference to the object.

Once no more references are pending, will call all into the virtual dtor of the implementation.

Parameters
object_ptr

◆ wlmcfg_string_create()

wlmcfg_string_t * wlmcfg_string_create ( const char * value_ptr)

Creates a string object.

Parameters
value_ptr
Returns
The string object, or NULL on error.

◆ wlmcfg_string_from_object()

wlmcfg_string_t * wlmcfg_string_from_object ( wlmcfg_object_t * object_ptr)

Gets the wlmcfg_string_t for object_ptr. NULL if not a string.

◆ wlmcfg_string_value()

const char * wlmcfg_string_value ( const wlmcfg_string_t * string_ptr)

Returns the value of the string.

Parameters
string_ptr
Returns
Pointer to the string's value.

Variable Documentation

◆ wlmcfg_model_test_cases

const bs_test_case_t wlmcfg_model_test_cases[]
Initial value:
= {
{ 1, "string", test_string },
{ 1, "dict", test_dict },
{ 1, "array", test_array },
{ 0, NULL, NULL }
}
static void test_array(bs_test_t *test_ptr)
Definition model.c:547
static void test_dict(bs_test_t *test_ptr)
Definition model.c:504
static void test_string(bs_test_t *test_ptr)
Definition model.c:485

Unit tests for the config data model.