Commit ffeaa434 authored by Ziirish's avatar Ziirish

adding cid_datatable_get_id function to get a specific case in a datatable

parent 1a1e32e6
......@@ -29,7 +29,7 @@ G_BEGIN_DECLS
#define TESTING_COVER "default.svg"
#define TESTING_FILE "cid.conf"
#define TESTING_DIR "../data"
#define TESTING_DIR "../../data"
#define IMAGE_CROSS "cross.png"
#define IMAGE_CONNECT "connect.png"
......
......@@ -195,6 +195,41 @@ cid_datatable_insert(CidDataTable **p_list, CidDataContent *data, gint position)
}
}
CidDataCase *
cid_datatable_get_id (CidDataTable *pTable, gint iPos)
{
g_return_val_if_fail (pTable != NULL, NULL);
size_t iSize = cid_datatable_length (pTable);
g_return_val_if_fail (iPos < (gint)iSize && iPos > -1, NULL);
CidDataCase *pRet = NULL;
gint cpt = 0;
if (iPos < (gint)iSize/2)
{
CidDataCase *pCase = pTable->head;
pRet = pCase;
for (; cpt < iPos; cpt++)
{
pRet = pCase->next;
pCase = pRet;
}
}
else
{
CidDataCase *pCase = pTable->tail;
pRet = pCase;
cpt = iSize - 1;
for (; cpt > iPos; cpt --)
{
pRet = pCase->prev;
pCase = pRet;
}
}
return pRet;
}
void
cid_free_datacase_full (CidDataCase *pCase, gpointer *pData)
{
......
......@@ -161,6 +161,14 @@ void cid_datatable_prepend(CidDataTable **p_list, CidDataContent *data);
*/
void cid_datatable_append(CidDataTable **p_list, CidDataContent *data);
/**
* Permet de retourner la case de l'indice donné.
* @param pTable liste dont on souhaite l'élément.
* @param iPos indice de l'élément souhaité.
* @return case de l'indice demandé.
*/
CidDataCase *cid_datatable_get_id (CidDataTable *pTable, gint iPos);
/**
* Permet de creer un nouvel element pouvant etre insere dans une liste
* @param iType type de l'element
......
......@@ -154,7 +154,7 @@ cid_read_parameters (CidMainContainer **pCid, int *argc, char ***argv)
g_free (cid->config->cConfFile);
if (cid->config->cDefaultImage)
g_free (cid->config->cDefaultImage);
cid->config->cConfFile = g_strdup_printf ("%s/%s", TESTING_DIR, TESTING_FILE);
cid->config->cConfFile = g_strdup_printf ("../data/%s", TESTING_FILE);
cid->config->cDefaultImage = g_strdup_printf ("%s/%s", TESTING_DIR, TESTING_COVER);
cid->config->bDevMode = TRUE;
}
......
......@@ -214,6 +214,7 @@ cid_display_init(CidMainContainer **pCid, int *argc, char ***argv)
int
main ( int argc, char **argv )
{
/*
struct sigaction action;
cid = g_malloc0 (sizeof(*cid));
......@@ -256,7 +257,7 @@ main ( int argc, char **argv )
cid_key_file_free(&cid);
cid_free_musicData();
cid_free_main_structure (cid);
*/
/*
GError *error = NULL;
GMatchInfo *match_info;
......@@ -346,6 +347,23 @@ main ( int argc, char **argv )
cid_clear_datatable (&table);
*/
CidDataTable *table = cid_create_datatable (G_TYPE_INT,
1,
2,
3,
4,
5,
6,
7,
8,
9,
G_TYPE_INVALID);
gint ind = 0;
fprintf (stdout, "table[%d] = %d\n", ind, cid_datatable_get_id (table, ind)->content->iNumber);
cid_clear_datatable (&table);
fprintf (stdout,"Bye !\n");
return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment