parent
fa3d859ab8
commit
9fadf5ae2c
@ -0,0 +1,17 @@
|
||||
#include "remove.h"
|
||||
|
||||
|
||||
void template_remove_line() {
|
||||
int index = 0;
|
||||
GtkTreeIter iter;
|
||||
GtkTreeModel *model = GTK_TREE_MODEL(main_config.list);
|
||||
GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->treeViewMain));
|
||||
if(gtk_tree_selection_get_selected(selection, &model, &iter)) {
|
||||
char* str_iter = yon_char_new(gtk_tree_model_get_string_from_iter(model, &iter));
|
||||
index = atoi(str_iter);
|
||||
g_object_ref(main_config.list);
|
||||
gtk_tree_view_set_model(GTK_TREE_VIEW(widgets->treeViewMain), NULL);
|
||||
gtk_list_store_clear(main_config.list);
|
||||
char* key_del = save_format_key(index);
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
#include "model.h"
|
@ -0,0 +1,155 @@
|
||||
#include "vector.h"
|
||||
|
||||
int vectorTotal(vector *v)
|
||||
{
|
||||
int totalCount = UNDEFINE;
|
||||
if(v)
|
||||
{
|
||||
totalCount = v->vectorList.total;
|
||||
}
|
||||
return totalCount;
|
||||
}
|
||||
int vectorResize(vector *v, int capacity)
|
||||
{
|
||||
int status = UNDEFINE;
|
||||
if(v)
|
||||
{
|
||||
void **items = realloc(v->vectorList.items, sizeof(void *) * capacity);
|
||||
if (items)
|
||||
{
|
||||
v->vectorList.items = items;
|
||||
v->vectorList.capacity = capacity;
|
||||
status = SUCCESS;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
int vectorPushBack(vector *v, void *item)
|
||||
{
|
||||
int status = UNDEFINE;
|
||||
if(v)
|
||||
{
|
||||
if (v->vectorList.capacity == v->vectorList.total)
|
||||
{
|
||||
status = vectorResize(v, v->vectorList.capacity * 2);
|
||||
if(status != UNDEFINE)
|
||||
{
|
||||
v->vectorList.items[v->vectorList.total++] = item;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
v->vectorList.items[v->vectorList.total++] = item;
|
||||
status = SUCCESS;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
int vectorSet(vector *v, int index, void *item)
|
||||
{
|
||||
int status = UNDEFINE;
|
||||
if(v)
|
||||
{
|
||||
if ((index >= 0) && (index < v->vectorList.total))
|
||||
{
|
||||
v->vectorList.items[index] = item;
|
||||
status = SUCCESS;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
void *vectorGet(vector *v, int index)
|
||||
{
|
||||
void *readData = NULL;
|
||||
if(v)
|
||||
{
|
||||
if ((index >= 0) && (index < v->vectorList.total))
|
||||
{
|
||||
readData = v->vectorList.items[index];
|
||||
}
|
||||
}
|
||||
return readData;
|
||||
}
|
||||
int vectorDelete(vector *v, int index)
|
||||
{
|
||||
int status = UNDEFINE;
|
||||
int i = 0;
|
||||
if(v)
|
||||
{
|
||||
if ((index < 0) || (index >= v->vectorList.total))
|
||||
return status;
|
||||
v->vectorList.items[index] = NULL;
|
||||
for (i = index; (i < v->vectorList.total - 1); ++i)
|
||||
{
|
||||
v->vectorList.items[i] = v->vectorList.items[i + 1];
|
||||
v->vectorList.items[i + 1] = NULL;
|
||||
}
|
||||
v->vectorList.total--;
|
||||
if ((v->vectorList.total > 0) && ((v->vectorList.total) == (v->vectorList.capacity / 4)))
|
||||
{
|
||||
vectorResize(v, v->vectorList.capacity / 2);
|
||||
}
|
||||
status = SUCCESS;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
int vectorFree(vector *v)
|
||||
{
|
||||
int status = UNDEFINE;
|
||||
if(v)
|
||||
{
|
||||
free(v->vectorList.items);
|
||||
v->vectorList.items = NULL;
|
||||
status = SUCCESS;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
void vector_init(vector *v)
|
||||
{
|
||||
//init function pointers
|
||||
v->pfVectorTotal = vectorTotal;
|
||||
v->pfVectorResize = vectorResize;
|
||||
v->pfVectorAdd = vectorPushBack;
|
||||
v->pfVectorSet = vectorSet;
|
||||
v->pfVectorGet = vectorGet;
|
||||
v->pfVectorFree = vectorFree;
|
||||
v->pfVectorDelete = vectorDelete;
|
||||
//initialize the capacity and allocate the memory
|
||||
v->vectorList.capacity = VECTOR_INIT_CAPACITY;
|
||||
v->vectorList.total = 0;
|
||||
v->vectorList.items = malloc(sizeof(void *) * v->vectorList.capacity);
|
||||
}
|
||||
|
||||
/*
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i =0;
|
||||
//init vector
|
||||
VECTOR_INIT(v);
|
||||
//Add data in vector
|
||||
v.pfVectorAdd(&v,"aticleworld.com\n");
|
||||
v.pfVectorAdd(&v,"amlendra\n");
|
||||
v.pfVectorAdd(&v,"Pooja\n");
|
||||
v.pfVectorAdd(&v,"aticleworld.com\n");
|
||||
v.pfVectorAdd(&v,"amlendra\n");
|
||||
v.pfVectorAdd(&v,"Pooja\n");
|
||||
v.pfVectorAdd(&v,"aticleworld.com\n");
|
||||
v.pfVectorAdd(&v,"amlendra\n");
|
||||
v.pfVectorAdd(&v,"Pooja\n");
|
||||
//print the data and type cast it
|
||||
for (i = 0; i < v.pfVectorTotal(&v); i++)
|
||||
{
|
||||
printf("%s", (char*)v.pfVectorGet(&v, i));
|
||||
}
|
||||
//Set the data at index 0
|
||||
v.pfVectorSet(&v,0,"Apoorv\n");
|
||||
printf("\n\n\nVector list after changes\n\n\n");
|
||||
//print the data and type cast it
|
||||
for (i = 0; i < v.pfVectorTotal(&v); i++)
|
||||
{
|
||||
printf("%s", (char*)v.pfVectorGet(&v, i));
|
||||
}
|
||||
vectorFree(&v);
|
||||
return 0;
|
||||
}
|
||||
*/
|
@ -0,0 +1,31 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// https://aticleworld.com/implement-vector-in-c/
|
||||
|
||||
#define VECTOR_INIT_CAPACITY 6
|
||||
#define UNDEFINE -1
|
||||
#define SUCCESS 0
|
||||
#define VECTOR_INIT(vec) vector vec;\
|
||||
vector_init(&vec)
|
||||
//Store and track the stored data
|
||||
typedef struct sVectorList
|
||||
{
|
||||
void **items;
|
||||
int capacity;
|
||||
int total;
|
||||
} sVectorList;
|
||||
//structure contain the function pointer
|
||||
typedef struct sVector vector;
|
||||
struct sVector
|
||||
{
|
||||
sVectorList vectorList;
|
||||
//function pointers
|
||||
int (*pfVectorTotal)(vector *);
|
||||
int (*pfVectorResize)(vector *, int);
|
||||
int (*pfVectorAdd)(vector *, void *);
|
||||
int (*pfVectorSet)(vector *, int, void *);
|
||||
void *(*pfVectorGet)(vector *, int);
|
||||
int (*pfVectorDelete)(vector *, int);
|
||||
int (*pfVectorFree)(vector *);
|
||||
};
|
Binary file not shown.
Loading…
Reference in new issue