Update code generation to create one file for dbl_list
This commit is contained in:
208
src/containers/dbl_list/dbl_list.c
Normal file
208
src/containers/dbl_list/dbl_list.c
Normal file
@@ -0,0 +1,208 @@
|
||||
/**
|
||||
* THIS FILE IS AUTOMATICALLY GENERATED. ANY MODIFICATIONS TO IT WILL BE OVERWRITTEN
|
||||
*/
|
||||
|
||||
#include "./dbl_list.h"
|
||||
#include "../../common/aliases/aliases.h"
|
||||
#include <stddef.h>
|
||||
|
||||
typedef struct str8 Str8;
|
||||
|
||||
internal Str8List str8_node_to_list(Str8Node *node);
|
||||
|
||||
Str8Node *wapp_str8_list_get(const Str8List *list, u64 index) {
|
||||
if (index >= list->node_count) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Str8Node *output = NULL;
|
||||
Str8Node *current = list->first;
|
||||
for (u64 i = 1; i <= index; ++i) {
|
||||
current = current->next;
|
||||
}
|
||||
|
||||
output = current;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
void wapp_str8_list_push_front(Str8List *list, Str8Node *node) {
|
||||
if (!list || !node || !(node->item)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Str8List node_list = str8_node_to_list(node);
|
||||
|
||||
if (list->node_count == 0) {
|
||||
*list = node_list;
|
||||
return;
|
||||
}
|
||||
|
||||
list->node_count += node_list.node_count;
|
||||
|
||||
Str8Node *first = list->first;
|
||||
if (first) {
|
||||
first->prev = node_list.last;
|
||||
}
|
||||
|
||||
list->first = node_list.first;
|
||||
node_list.last->next = first;
|
||||
}
|
||||
|
||||
void wapp_str8_list_push_back(Str8List *list, Str8Node *node) {
|
||||
if (!list || !node || !(node->item)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Str8List node_list = str8_node_to_list(node);
|
||||
|
||||
if (list->node_count == 0) {
|
||||
*list = node_list;
|
||||
return;
|
||||
}
|
||||
|
||||
list->node_count += node_list.node_count;
|
||||
|
||||
Str8Node *last = list->last;
|
||||
if (last) {
|
||||
last->next = node_list.first;
|
||||
}
|
||||
|
||||
list->last = node_list.last;
|
||||
node_list.first->prev = last;
|
||||
}
|
||||
|
||||
void wapp_str8_list_insert(Str8List *list, Str8Node *node, u64 index) {
|
||||
if (!list || !node || !(node->item)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (index == 0) {
|
||||
wapp_str8_list_push_front(list, node);
|
||||
return;
|
||||
} else if (index == list->node_count) {
|
||||
wapp_str8_list_push_back(list, node);
|
||||
return;
|
||||
}
|
||||
|
||||
Str8Node *dst_node = wapp_str8_list_get(list, index);
|
||||
if (!dst_node) {
|
||||
return;
|
||||
}
|
||||
|
||||
Str8List node_list = str8_node_to_list(node);
|
||||
|
||||
list->node_count += node_list.node_count;
|
||||
|
||||
Str8Node *prev = dst_node->prev;
|
||||
|
||||
dst_node->prev = node_list.last;
|
||||
prev->next = node_list.first;
|
||||
|
||||
node_list.first->prev = prev;
|
||||
node_list.last->next = dst_node;
|
||||
}
|
||||
|
||||
Str8Node *wapp_str8_list_pop_front(Str8List *list) {
|
||||
Str8Node *output = NULL;
|
||||
|
||||
if (!list || list->node_count == 0) {
|
||||
goto RETURN_STR8_LIST_POP_FRONT;
|
||||
}
|
||||
|
||||
output = list->first;
|
||||
|
||||
if (list->node_count == 1) {
|
||||
*list = (Str8List){0};
|
||||
goto RETURN_STR8_LIST_POP_FRONT;
|
||||
}
|
||||
|
||||
--(list->node_count);
|
||||
list->first = output->next;
|
||||
|
||||
output->prev = output->next = NULL;
|
||||
|
||||
RETURN_STR8_LIST_POP_FRONT:
|
||||
return output;
|
||||
}
|
||||
|
||||
Str8Node *wapp_str8_list_pop_back(Str8List *list) {
|
||||
Str8Node *output = NULL;
|
||||
|
||||
if (!list || list->node_count == 0) {
|
||||
goto RETURN_STR8_LIST_POP_BACK;
|
||||
}
|
||||
|
||||
output = list->last;
|
||||
|
||||
if (list->node_count == 1) {
|
||||
*list = (Str8List){0};
|
||||
goto RETURN_STR8_LIST_POP_BACK;
|
||||
}
|
||||
|
||||
--(list->node_count);
|
||||
list->last = output->prev;
|
||||
|
||||
output->prev = output->next = NULL;
|
||||
|
||||
RETURN_STR8_LIST_POP_BACK:
|
||||
return output;
|
||||
}
|
||||
|
||||
Str8Node *wapp_str8_list_remove(Str8List *list, u64 index) {
|
||||
Str8Node *output = NULL;
|
||||
if (!list) {
|
||||
goto RETURN_STR8_LIST_REMOVE;
|
||||
}
|
||||
|
||||
if (index == 0) {
|
||||
output = wapp_str8_list_pop_front(list);
|
||||
goto RETURN_STR8_LIST_REMOVE;
|
||||
} else if (index == list->node_count) {
|
||||
output = wapp_str8_list_pop_back(list);
|
||||
goto RETURN_STR8_LIST_REMOVE;
|
||||
}
|
||||
|
||||
output = wapp_str8_list_get(list, index);
|
||||
if (!output) {
|
||||
goto RETURN_STR8_LIST_REMOVE;
|
||||
}
|
||||
|
||||
output->prev->next = output->next;
|
||||
output->next->prev = output->prev;
|
||||
|
||||
--(list->node_count);
|
||||
|
||||
output->prev = output->next = NULL;
|
||||
|
||||
RETURN_STR8_LIST_REMOVE:
|
||||
return output;
|
||||
}
|
||||
|
||||
void wapp_str8_list_empty(Str8List *list) {
|
||||
if (!list) {
|
||||
return;
|
||||
}
|
||||
|
||||
u64 count = list->node_count;
|
||||
for (u64 i = 0; i < count; ++i) {
|
||||
wapp_str8_list_pop_back(list);
|
||||
}
|
||||
}
|
||||
|
||||
internal Str8List str8_node_to_list(Str8Node *node) {
|
||||
Str8List output = {.first = node, .last = node, .node_count = 1};
|
||||
|
||||
while (output.first->prev != NULL) {
|
||||
output.first = output.first->prev;
|
||||
++(output.node_count);
|
||||
}
|
||||
|
||||
while (output.last->next != NULL) {
|
||||
output.last = output.last->next;
|
||||
++(output.node_count);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
45
src/containers/dbl_list/dbl_list.h
Normal file
45
src/containers/dbl_list/dbl_list.h
Normal file
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* THIS FILE IS AUTOMATICALLY GENERATED. ANY MODIFICATIONS TO IT WILL BE OVERWRITTEN
|
||||
*/
|
||||
|
||||
#ifndef DBL_LIST_H
|
||||
#define DBL_LIST_H
|
||||
|
||||
#include "../../common/aliases/aliases.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
BEGIN_C_LINKAGE
|
||||
#endif // !__cplusplus
|
||||
|
||||
#define wapp_str8_list_node(ITEM_PTR) ((Str8Node){.item = ITEM_PTR})
|
||||
|
||||
typedef struct str8 Str8;
|
||||
|
||||
typedef struct Str8Node Str8Node;
|
||||
struct Str8Node {
|
||||
Str8 *item;
|
||||
Str8Node *prev;
|
||||
Str8Node *next;
|
||||
};
|
||||
|
||||
typedef struct Str8List Str8List;
|
||||
struct Str8List {
|
||||
Str8Node *first;
|
||||
Str8Node *last;
|
||||
u64 node_count;
|
||||
};
|
||||
|
||||
Str8Node *wapp_str8_list_get(const Str8List *list, u64 index);
|
||||
void wapp_str8_list_push_front(Str8List *list, Str8Node *node);
|
||||
void wapp_str8_list_push_back(Str8List *list, Str8Node *node);
|
||||
void wapp_str8_list_insert(Str8List *list, Str8Node *node, u64 index);
|
||||
Str8Node *wapp_str8_list_pop_front(Str8List *list);
|
||||
Str8Node *wapp_str8_list_pop_back(Str8List *list);
|
||||
Str8Node *wapp_str8_list_remove(Str8List *list, u64 index);
|
||||
void wapp_str8_list_empty(Str8List *list);
|
||||
|
||||
#ifdef __cplusplus
|
||||
END_C_LINKAGE
|
||||
#endif // !__cplusplus
|
||||
|
||||
#endif // !DBL_LIST_H
|
||||
6
src/containers/wapp_containers.c
Normal file
6
src/containers/wapp_containers.c
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef WAPP_CONTAINERS_C
|
||||
#define WAPP_CONTAINERS_C
|
||||
|
||||
#include "dbl_list/dbl_list.c"
|
||||
|
||||
#endif // !WAPP_CONTAINERS_C
|
||||
7
src/containers/wapp_containers.h
Normal file
7
src/containers/wapp_containers.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#ifndef WAPP_CONTAINERS_H
|
||||
#define WAPP_CONTAINERS_H
|
||||
|
||||
#include "dbl_list/dbl_list.h"
|
||||
#include "../common/wapp_common.h"
|
||||
|
||||
#endif // !WAPP_CONTAINERS_H
|
||||
Reference in New Issue
Block a user