evas/cserve2: Add common fash for glyphs.

Fash was made available on a common file, so its implementation is
shared between server and client.



SVN revision: 72698
This commit is contained in:
Rafael Antognolli 2012-06-22 20:31:09 +00:00
parent 2ba092ba4c
commit de28f1ed31
3 changed files with 140 additions and 2 deletions

View File

@ -14,7 +14,7 @@ AM_CPPFLAGS = \
if EVAS_CSERVE2
noinst_LTLIBRARIES = libevas_cserve2.la
noinst_LTLIBRARIES = libevas_cserve2.la libevas_cserve2_utils.la
libevas_cserve2_la_SOURCES = \
evas_cs2.h \
@ -22,6 +22,10 @@ evas_cs2_private.h \
evas_cs2_image_data.c \
evas_cs2_client.c
libevas_cserve2_la_LIBADD = @EINA_LIBS@
libevas_cserve2_utils_la_SOURCES = \
evas_cs2_utils.h \
evas_cs2_utils.c
libevas_cserve2_la_LIBADD = @EINA_LIBS@ libevas_cserve2_utils.la
endif

View File

@ -0,0 +1,121 @@
/* THIS FILE TO BE SHARED WITH THE BIN PART. KEEP IT CLEAN. THERE BE DRAGONS */
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdlib.h>
#include <Eina.h>
#include "evas_cs2_utils.h"
/* fash */
typedef struct _Fash_Glyph_Map Fash_Glyph_Map;
typedef struct _Fash_Glyph_Map2 Fash_Glyph_Map2;
struct _Fash_Glyph_Map
{
void *item[256];
};
struct _Fash_Glyph_Map2
{
Fash_Glyph_Map *bucket[256];
};
struct _Fash_Glyph
{
Fash_Glyph_Map2 *bucket[256];
void (*free_cb)(void *glyph);
};
static void
_fash_item_free(Fash_Glyph *fash, Fash_Glyph_Map *map)
{
int i;
if (fash->free_cb)
for (i = 0; i < 256; i++)
if (map->item[i])
fash->free_cb(map->item[i]);
free(map);
}
static void
_fash_gl2_free(Fash_Glyph *fash, Fash_Glyph_Map2 *fash2)
{
int i;
for (i = 0; i < 256; i++)
if (fash2->bucket[i]) _fash_item_free(fash, fash2->bucket[i]);
free(fash2);
}
void
fash_gl_free(Fash_Glyph *fash)
{
int i;
for (i = 0; i < 256; i++)
if (fash->bucket[i]) _fash_gl2_free(fash, fash->bucket[i]);
free(fash);
}
Fash_Glyph *
fash_gl_new(void (*free_cb)(void *glyph))
{
Fash_Glyph *fash = calloc(1, sizeof(Fash_Glyph));
fash->free_cb = free_cb;
return fash;
}
void *
fash_gl_find(Fash_Glyph *fash, int item)
{
int grp, maj, min;
// 24bits for unicode - v6 up to E01EF (chrs) & 10FFFD for private use (plane 16)
grp = (item >> 16) & 0xff;
maj = (item >> 8) & 0xff;
min = item & 0xff;
if (!fash->bucket[grp]) return NULL;
if (!fash->bucket[grp]->bucket[maj]) return NULL;
return fash->bucket[grp]->bucket[maj]->item[min];
}
void
fash_gl_add(Fash_Glyph *fash, int item, void *glyph)
{
int grp, maj, min;
// 24bits for unicode - v6 up to E01EF (chrs) & 10FFFD for private use (plane 16)
grp = (item >> 16) & 0xff;
maj = (item >> 8) & 0xff;
min = item & 0xff;
if (!fash->bucket[grp])
fash->bucket[grp] = calloc(1, sizeof(Fash_Glyph_Map2));
EINA_SAFETY_ON_NULL_RETURN(fash->bucket[grp]);
if (!fash->bucket[grp]->bucket[maj])
fash->bucket[grp]->bucket[maj] = calloc(1, sizeof(Fash_Glyph_Map));
EINA_SAFETY_ON_NULL_RETURN(fash->bucket[grp]->bucket[maj]);
fash->bucket[grp]->bucket[maj]->item[min] = glyph;
}
void
fash_gl_del(Fash_Glyph *fash, int item)
{
int grp, maj, min;
void *data;
// 24bits for unicode - v6 up to E01EF (chrs) & 10FFFD for private use (plane 16)
grp = (item >> 16) & 0xff;
maj = (item >> 8) & 0xff;
min = item & 0xff;
if (!fash->bucket[grp]) return;
if (!fash->bucket[grp]->bucket[maj]) return;
if (!fash->bucket[grp]->bucket[maj]->item[min]) return;
data = fash->bucket[grp]->bucket[maj]->item[min];
fash->free_cb(data);
fash->bucket[grp]->bucket[maj]->item[min] = NULL;
}

View File

@ -0,0 +1,13 @@
/* THIS FILE TO BE SHARED WITH THE BIN PART. KEEP IT CLEAN. THERE BE DRAGONS */
#ifndef _EVAS_CSERVE2_UTILS_H_
#define _EVAS_CSERVE2_UTILS_H_
typedef struct _Fash_Glyph Fash_Glyph;
Fash_Glyph *fash_gl_new(void (*free_cb)(void *glyph));
void fash_gl_free(Fash_Glyph *fash);
void *fash_gl_find(Fash_Glyph *fash, int item);
void fash_gl_add(Fash_Glyph *fash, int item, void *glyph);
void fash_gl_del(Fash_Glyph *fash, int item);
#endif /* EVAS_CSERVE2_UTILS_H_ */