libamxc  1.10.3
C Generic Data Containers
amxc_variant_priv.h File Reference

Go to the source code of this file.

Functions

uint32_t PRIVATE amxc_var_add_type (amxc_var_type_t *const type, const uint32_t index)
 
int PRIVATE amxc_var_remove_type (amxc_var_type_t *const type)
 
amxc_array_t PRIVATEamxc_variant_get_types_array (void)
 
int PRIVATE amxc_var_default_copy (amxc_var_t *const dest, const amxc_var_t *const src)
 
int PRIVATE amxc_var_default_move (amxc_var_t *const dest, amxc_var_t *const src)
 
int PRIVATE amxc_var_default_convert_to_null (amxc_var_t *const dest, const amxc_var_t *const src)
 
int PRIVATE amxc_var_default_convert_to_list (amxc_var_t *const dest, const amxc_var_t *const src)
 
int PRIVATE amxc_var_default_convert_to_htable (amxc_var_t *const dest, const amxc_var_t *const src)
 

Function Documentation

◆ amxc_var_add_type()

uint32_t PRIVATE amxc_var_add_type ( amxc_var_type_t *const  type,
const uint32_t  index 
)

Definition at line 119 of file amxc_variant_type.c.

120  {
121  uint32_t type_id = -1;
122  amxc_array_it_t* ait = NULL;
123  amxc_htable_it_t* hit = NULL;
124  when_null(type, exit);
125 
126  hit = amxc_htable_get(&amxc_variant_types, type->name);
127  if(hit == &type->hit) {
128  type_id = type->type_id;
129  goto exit;
130  }
131 
132  when_not_null(hit, exit);
133 
134  // TODO?: move into constructor, this is lib init code
136  // nothing allocated yet - pre-allocate all fixed items
138  }
139 
140  ait = amxc_var_get_type_position(index);
141  when_null(ait, exit);
142 
143  amxc_array_it_set_data(ait, type);
144  amxc_htable_it_init(&type->hit);
145  if(amxc_htable_insert(&amxc_variant_types, type->name, &type->hit) == -1) {
147  goto exit;
148  }
149 
150  type->type_id = amxc_array_it_index(ait);
151  type_id = type->type_id;
152 
153 exit:
154  return type_id;
155 }
#define when_not_null(x, l)
Definition: amxc_macros.h:130
#define when_failed(x, l)
Definition: amxc_macros.h:142
#define when_null(x, l)
Definition: amxc_macros.h:126
static int amxc_var_allocate_types(void)
static amxc_htable_t amxc_variant_types
static amxc_array_it_t * amxc_var_get_type_position(const uint32_t index)
int amxc_array_it_set_data(amxc_array_it_t *const it, void *data)
Sets the data pointer of an array iterator.
void * amxc_array_it_take_data(amxc_array_it_t *const it)
Gets and removes a data pointer from the iterator.
unsigned int amxc_array_it_index(const amxc_array_it_t *const it)
Gets the index of the iterator in the array.
int amxc_htable_it_init(amxc_htable_it_t *const it)
Initializes a hash table.iterator.
AMXC_INLINE bool amxc_htable_is_empty(const amxc_htable_t *const htable)
Checks that the hash table is empty.
Definition: amxc_htable.h:311
amxc_htable_it_t * amxc_htable_get(const amxc_htable_t *const htable, const char *const key)
Gets a hash table iterator from the hash table.
Definition: amxc_htable.c:278
int amxc_htable_insert(amxc_htable_t *const htable, const char *const key, amxc_htable_it_t *const it)
Inserts an item in the hash table.
Definition: amxc_htable.c:237
The array iterator structure.
Definition: amxc_array.h:174
The hash table iterator structure.
Definition: amxc_htable.h:138
const char * name
amxc_htable_it_t hit

◆ amxc_var_default_convert_to_htable()

int PRIVATE amxc_var_default_convert_to_htable ( amxc_var_t *const  dest,
const amxc_var_t *const  src 
)

Definition at line 174 of file amxc_variant.c.

175  {
176  int retval = -1;
177  amxc_var_t* var = NULL;
178 
179  if(amxc_var_new(&var) != 0) {
180  amxc_htable_clean(&dest->data.vm, NULL);
181  goto exit;
182  }
183 
184  amxc_var_copy(var, src);
185  amxc_htable_insert(&dest->data.vm, "1", &var->hit);
186 
187  retval = 0;
188 
189 exit:
190  return retval;
191 }
void amxc_htable_clean(amxc_htable_t *const htable, amxc_htable_it_delete_t func)
Removes all items from the hash table.
Definition: amxc_htable.c:200
int amxc_var_new(amxc_var_t **var)
Allocates a variant and initializes it to the null variant type.
Definition: amxc_variant.c:194
int amxc_var_copy(amxc_var_t *const dest, const amxc_var_t *const src)
Copy the type and data from one variant (source) in another variant (destination).
Definition: amxc_variant.c:285
The variant struct definition.
Definition: amxc_variant.h:861
void * data
Definition: amxc_variant.h:883
amxc_htable_it_t hit
Definition: amxc_variant.h:863
static amxc_var_t * var
Definition: test_issue_58.c:77

◆ amxc_var_default_convert_to_list()

int PRIVATE amxc_var_default_convert_to_list ( amxc_var_t *const  dest,
const amxc_var_t *const  src 
)

Definition at line 155 of file amxc_variant.c.

156  {
157  int retval = -1;
158  amxc_var_t* var = NULL;
159 
160  if(amxc_var_new(&var) != 0) {
161  amxc_llist_clean(&dest->data.vl, NULL);
162  goto exit;
163  }
164 
165  amxc_var_copy(var, src);
166  amxc_llist_append(&dest->data.vl, &var->lit);
167 
168  retval = 0;
169 
170 exit:
171  return retval;
172 }
int amxc_llist_append(amxc_llist_t *const llist, amxc_llist_it_t *const it)
Adds an item to the end of the linked list.
Definition: amxc_llist.c:169
void amxc_llist_clean(amxc_llist_t *const llist, amxc_llist_it_delete_t func)
Removes all items from the linked list.
Definition: amxc_llist.c:124
amxc_llist_it_t lit
Definition: amxc_variant.h:862

◆ amxc_var_default_convert_to_null()

int PRIVATE amxc_var_default_convert_to_null ( amxc_var_t *const  dest,
const amxc_var_t *const  src 
)

◆ amxc_var_default_copy()

int PRIVATE amxc_var_default_copy ( amxc_var_t *const  dest,
const amxc_var_t *const  src 
)

Definition at line 136 of file amxc_variant.c.

137  {
138  dest->data = src->data;
139  return 0;
140 }

◆ amxc_var_default_move()

int PRIVATE amxc_var_default_move ( amxc_var_t *const  dest,
amxc_var_t *const  src 
)

Definition at line 142 of file amxc_variant.c.

143  {
144  dest->data = src->data;
145  src->data.data = NULL;
146  return 0;
147 }

◆ amxc_var_remove_type()

int PRIVATE amxc_var_remove_type ( amxc_var_type_t *const  type)

Definition at line 157 of file amxc_variant_type.c.

157  {
158  int retval = -1;
159  amxc_array_it_t* it = NULL;
161  when_null(hit, exit);
162  when_true(hit != &type->hit, exit);
163 
164  amxc_htable_it_take(hit);
165  amxc_htable_it_clean(hit, NULL);
166 
169 
170  type->type_id = AMXC_VAR_ID_MAX;
171 
172  // TODO?: move into destructor, this is lib exit code
173  // if hash table is empty, no more types are registered, clear buffers
176  }
177 
178  retval = 0;
179 
180 exit:
181  return retval;
182 }
#define when_true(x, l)
Definition: amxc_macros.h:134
static amxc_array_t amxc_array_types
static void amxc_var_free_types(void)
amxc_array_it_t * amxc_array_get_at(const amxc_array_t *const array, const unsigned int index)
Gets the item iterator for the given index.
Definition: amxc_array.c:504
void amxc_htable_it_clean(amxc_htable_it_t *const it, amxc_htable_it_delete_t func)
Removes the iterator from the htable and frees allocated memory.
void amxc_htable_it_take(amxc_htable_it_t *const it)
Removes the iterator from the hash table.
#define AMXC_VAR_ID_MAX
Same as AMXC_VAR_ID_INVALID.
Definition: amxc_variant.h:263
static amxc_htable_it_t it[2000]

◆ amxc_variant_get_types_array()

amxc_array_t PRIVATE* amxc_variant_get_types_array ( void  )

Definition at line 184 of file amxc_variant_type.c.

184  {
185  return &amxc_array_types;
186 }