evas/cserve2: Add common fash for glyphs.
authorantognolli <antognolli@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Fri, 22 Jun 2012 20:31:09 +0000 (20:31 +0000)
committerantognolli <antognolli@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Fri, 22 Jun 2012 20:31:09 +0000 (20:31 +0000)
Fash was made available on a common file, so its implementation is
shared between server and client.

git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/evas@72698 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/lib/cserve2/Makefile.am
src/lib/cserve2/evas_cs2_utils.c [new file with mode: 0644]
src/lib/cserve2/evas_cs2_utils.h [new file with mode: 0644]

index 252899f..39d7048 100644 (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
diff --git a/src/lib/cserve2/evas_cs2_utils.c b/src/lib/cserve2/evas_cs2_utils.c
new file mode 100644 (file)
index 0000000..5323000
--- /dev/null
@@ -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;
+}
diff --git a/src/lib/cserve2/evas_cs2_utils.h b/src/lib/cserve2/evas_cs2_utils.h
new file mode 100644 (file)
index 0000000..50c178e
--- /dev/null
@@ -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_ */