Kouhei Sutou
kous****@users*****
2006年 11月 22日 (水) 18:04:47 JST
Index: tomoe/lib/Makefile.am diff -u tomoe/lib/Makefile.am:1.34 tomoe/lib/Makefile.am:1.35 --- tomoe/lib/Makefile.am:1.34 Wed Nov 22 14:59:05 2006 +++ tomoe/lib/Makefile.am Wed Nov 22 18:04:47 2006 @@ -30,29 +30,51 @@ INCLUDES = $(LIBXML_CFLAGS) $(LIBXSLT_CFLAGS) $(GLIB_CFLAGS) -pkginclude_HEADERS = \ - tomoe.h \ - tomoe-candidate.h \ - tomoe-char.h \ - tomoe-context.h \ - tomoe-config.h \ - tomoe-dict.h \ - tomoe-recognizer.h \ - tomoe-shelf.h \ +tomoe_public_h_sources = \ + tomoe.h \ + tomoe-candidate.h \ + tomoe-char.h \ + tomoe-context.h \ + tomoe-config.h \ + tomoe-dict.h \ + tomoe-query.h \ + tomoe-reading.h \ + tomoe-recognizer.h \ + tomoe-shelf.h \ tomoe-writing.h +enum_source_prefix = tomoe-enum-types + +enum_sources_h = \ + $(tomoe_public_h_sources) + +enum_sources = \ + $(enum_source_prefix).c \ + $(enum_source_prefix).h + +BUILT_SOURCES = $(enum_sources) +CLEANFILES += $(enum_sources) + +pkginclude_HEADERS = \ + $(tomoe_public_h_sources) \ + $(enum_source_prefix).h + lib_LTLIBRARIES = libtomoe.la -libtomoe_la_SOURCES = \ - glib-utils.h \ - tomoe.c \ - tomoe-candidate.c \ - tomoe-char.c \ - tomoe-context.c \ - tomoe-config.c \ - tomoe-dict.c \ - tomoe-recognizer.c \ - tomoe-recognizer-impl.h \ - tomoe-shelf.c \ + +libtomoe_la_SOURCES = \ + glib-utils.h \ + tomoe-enum-types.c \ + tomoe.c \ + tomoe-candidate.c \ + tomoe-char.c \ + tomoe-context.c \ + tomoe-config.c \ + tomoe-dict.c \ + tomoe-query.c \ + tomoe-reading.c \ + tomoe-recognizer.c \ + tomoe-recognizer-impl.h \ + tomoe-shelf.c \ tomoe-writing.c libtomoe_la_LDFLAGS = \ @@ -63,3 +85,51 @@ -lm libtomoe_la_LIBADD = $(LIBXML_LIBS) $(LIBXSLT_LIBS) $(GLIB_LIBS) + + + +BUILT_SOURCES += \ + stamp-$(enum_source_prefix)-c \ + stamp-$(enum_source_prefix)-h + +CLEANFILES += \ + stamp-$(enum_source_prefix)-c \ + stamp-$(enum_source_prefix)-h + +$(enum_source_prefix).c: stamp-$(enum_source_prefix)-c $(enum_source_prefix).h + @true + +stamp-$(enum_source_prefix)-c: $(enum_sources_h) Makefile $(GLIB_MKENUMS) + (cd $(srcdir) && \ + include_headers="" && \ + for h in $(enum_sources_h); do \ + include_headers="$${include_headers}#include \"$${h}\"\n"; \ + done && \ + $(GLIB_MKENUMS) \ + --fhead "#include \"$(enum_source_prefix).h\"\n$${include_headers}" \ + --fprod "\n/* enumerations from \"@filename@\" */" \ + --vhead "GType\n @ enum_name@_get_type (void)\n{\n static GType etype = 0;\n if (etype == 0) {\n static const G @ Type@Value values[] = {" \ + --vprod " { @VALUENAME@, \"@VALUENAME@\", \"@valuenick@\" }," \ + --vtail " { 0, NULL, NULL }\n };\n etype = g_ @ type@_register_static (\"@EnumName@\", values);\n }\n return etype;\n}\n" \ + $(enum_sources_h)) > tmp-$(enum_source_prefix).c && \ + (cmp -s tmp-$(enum_source_prefix).c $(enum_source_prefix).c || \ + cp tmp-$(enum_source_prefix).c $(enum_source_prefix).c ) && \ + rm -f tmp-$(enum_source_prefix).c && \ + echo timestamp > $(@F) + +$(enum_source_prefix).h: stamp-$(enum_source_prefix)-h + @true + +stamp-$(enum_source_prefix)-h: $(enum_sources_h) Makefile $(GLIB_MKENUMS) + (cd $(srcdir) && \ + mark="__`echo $(enum_source_prefix) | sed -e 's/-/_/g' | tr a-z A-Z`_H__" && \ + $(GLIB_MKENUMS) \ + --fhead "#ifndef $${mark}\n#define $${mark}\n\n#include <glib-object.h>\n\nG_BEGIN_DECLS\n" \ + --fprod "/* enumerations from \"@filename@\" */\n" \ + --vhead "GType @enum_name @ _get_type (void);\n#define TOMOE_TYPE_ @ ENUMSHORT@ (@enum_name @ _get_type())\n" \ + --ftail "G_END_DECLS\n\n#endif /* $${mark} */" \ + $(enum_sources_h)) > tmp-$(enum_source_prefix).h && \ + (cmp -s tmp-$(enum_source_prefix).h $(enum_source_prefix).h || \ + cp tmp-$(enum_source_prefix).h $(enum_source_prefix).h) && \ + rm -f tmp-$(enum_source_prefix).h && \ + echo timestamp > $(@F) Index: tomoe/lib/tomoe-char.c diff -u tomoe/lib/tomoe-char.c:1.43 tomoe/lib/tomoe-char.c:1.44 --- tomoe/lib/tomoe-char.c:1.43 Wed Nov 22 15:39:44 2006 +++ tomoe/lib/tomoe-char.c Wed Nov 22 18:04:47 2006 @@ -18,7 +18,7 @@ * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307 USA * - * $Id: tomoe-char.c,v 1.43 2006/11/22 06:39:44 kous Exp $ + * $Id: tomoe-char.c,v 1.44 2006/11/22 09:04:47 kous Exp $ */ #include <stdlib.h> @@ -100,7 +100,7 @@ if (priv->meta) g_hash_table_destroy (priv->meta); if (priv->readings) { - g_list_foreach (priv->readings, (GFunc)g_free, NULL); + g_list_foreach (priv->readings, (GFunc)g_object_unref, NULL); g_list_free (priv->readings); } @@ -184,7 +184,7 @@ } void -tomoe_char_add_reading (TomoeChar* chr, const gchar *reading) +tomoe_char_add_reading (TomoeChar* chr, TomoeReading *reading) { TomoeCharPrivate *priv; @@ -192,7 +192,7 @@ priv = TOMOE_CHAR_GET_PRIVATE (chr); - priv->readings = g_list_prepend(priv->readings, g_strdup(reading)); + priv->readings = g_list_prepend(priv->readings, g_object_ref(reading)); } TomoeWriting* Index: tomoe/lib/tomoe-char.h diff -u tomoe/lib/tomoe-char.h:1.41 tomoe/lib/tomoe-char.h:1.42 --- tomoe/lib/tomoe-char.h:1.41 Wed Nov 22 15:39:44 2006 +++ tomoe/lib/tomoe-char.h Wed Nov 22 18:04:47 2006 @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * Copyright (C) 2005 Takuro Ashie <ashie****@homa*****> * Copyright (C) 2006 Juernjakob Harder <juern****@gmail*****> @@ -18,7 +18,7 @@ * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307 USA * - * $Id: tomoe-char.h,v 1.41 2006/11/22 06:39:44 kous Exp $ + * $Id: tomoe-char.h,v 1.42 2006/11/22 09:04:47 kous Exp $ */ /** @file tomoe-char.h @@ -32,8 +32,8 @@ G_BEGIN_DECLS -#include <glib/garray.h> -#include <tomoe-writing.h> +#include "tomoe-reading.h" +#include "tomoe-writing.h" #define TOMOE_TYPE_CHAR (tomoe_char_get_type ()) #define TOMOE_CHAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TOMOE_TYPE_CHAR, TomoeChar)) @@ -63,15 +63,21 @@ */ TomoeChar *tomoe_char_new (void); -const gchar *tomoe_char_get_code (const TomoeChar *chr); +const char *tomoe_char_get_code (const TomoeChar *chr); void tomoe_char_set_code (TomoeChar *chr, - const gchar *code); + const char *code); const GList *tomoe_char_get_readings (TomoeChar *chr); void tomoe_char_add_reading (TomoeChar *chr, - const gchar *reading); -TomoeWriting *tomoe_char_get_writing (TomoeChar *t_char); -void tomoe_char_set_writing (TomoeChar *t_char, + TomoeReading *reading); +GList *tomoe_char_get_radicals (TomoeChar *chr); +void tomoe_char_add_radical (TomoeChar *chr, + TomoeChar *radical); +TomoeWriting *tomoe_char_get_writing (TomoeChar *chr); +void tomoe_char_set_writing (TomoeChar *chr, TomoeWriting *writing); +TomoeChar *tomoe_char_get_variant (TomoeChar *chr); +void tomoe_char_set_variant (TomoeChar *chr, + TomoeChar *variant); /** * @brief Compare two tomoe_letter. Index: tomoe/lib/tomoe-context.c diff -u tomoe/lib/tomoe-context.c:1.34 tomoe/lib/tomoe-context.c:1.35 --- tomoe/lib/tomoe-context.c:1.34 Wed Nov 22 15:19:19 2006 +++ tomoe/lib/tomoe-context.c Wed Nov 22 18:04:47 2006 @@ -17,7 +17,7 @@ * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307 USA * - * $Id: tomoe-context.c,v 1.34 2006/11/22 06:19:19 makeinu Exp $ + * $Id: tomoe-context.c,v 1.35 2006/11/22 09:04:47 kous Exp $ */ #include "tomoe-dict.h" @@ -182,7 +182,8 @@ return tomoe_candidate_compare (ca, cb); } -GList * + +static GList * tomoe_context_search_by_strokes (TomoeContext *context, TomoeWriting *input) { TomoeContextPrivate *priv; @@ -208,8 +209,8 @@ return matched; } -GList * -tomoe_context_search_by_reading (TomoeContext *context, const char *input) +static GList * +tomoe_context_search_by_reading (TomoeContext *context, TomoeReading *reading) { GList *names, *name; GList *results = NULL; @@ -222,7 +223,7 @@ for (name = names; name; name = name->next) { TomoeDict *dict; dict = tomoe_context_get_dict(context, name->data); - results = g_list_concat (tomoe_dict_search_by_reading (dict, input), + results = g_list_concat (tomoe_dict_search_by_reading (dict, reading), results); } results = g_list_sort (results, _candidate_compare_func); @@ -230,6 +231,23 @@ return results; } +GList * +tomoe_context_search (TomoeContext *context, TomoeQuery *query) +{ + const GList *readings; + TomoeWriting *writing; + + writing = tomoe_query_get_writing (query); + if (writing) + return tomoe_context_search_by_strokes (context, writing); + + readings = tomoe_query_get_readings (query); + if (readings) + return tomoe_context_search_by_reading (context, readings->data); + + return NULL; +} + /* vi:ts=4:nowrap:ai:expandtab */ Index: tomoe/lib/tomoe-context.h diff -u tomoe/lib/tomoe-context.h:1.23 tomoe/lib/tomoe-context.h:1.24 --- tomoe/lib/tomoe-context.h:1.23 Wed Nov 22 15:19:19 2006 +++ tomoe/lib/tomoe-context.h Wed Nov 22 18:04:47 2006 @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * Copyright (C) 2006 Juernjakob Harder <juern****@gmail*****> * @@ -17,7 +17,7 @@ * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307 USA * - * $Id: tomoe-context.h,v 1.23 2006/11/22 06:19:19 makeinu Exp $ + * $Id: tomoe-context.h,v 1.24 2006/11/22 09:04:47 kous Exp $ */ /** @@ -34,6 +34,7 @@ #include "tomoe-candidate.h" #include "tomoe-dict.h" +#include "tomoe-query.h" #define TOMOE_TYPE_CONTEXT (tomoe_context_get_type ()) #define TOMOE_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TOMOE_TYPE_CONTEXT, TomoeContext)) @@ -69,35 +70,23 @@ * @param filename - Name of dictionary file to load. * @return The TomoeContext. */ -void tomoe_context_add_dict (TomoeContext *ctx, +void tomoe_context_add_dict (TomoeContext *ctx, TomoeDict *dict); -GList *tomoe_context_get_dict_names (TomoeContext *ctx); -TomoeDict *tomoe_context_get_dict (TomoeContext *ctx, +GList *tomoe_context_get_dict_names (TomoeContext *ctx); +TomoeDict *tomoe_context_get_dict (TomoeContext *ctx, const gchar *name); -gboolean tomoe_context_remove_dict (TomoeContext *ctx, +gboolean tomoe_context_remove_dict (TomoeContext *ctx, const gchar *name); -void tomoe_context_load_config (TomoeContext *ctx, +void tomoe_context_load_config (TomoeContext *ctx, const gchar *config_file); -void tomoe_context_save (TomoeContext *ctx); +void tomoe_context_save (TomoeContext *ctx); -/** - * @brief Match strokes of TomoeChar with input. - * @param ctx - Pointer to the TomoeContext object. - * @param input - Pointer to TomoeWriting matchkey. - * @return The array of TomoeCandidate. - */ -GList *tomoe_context_search_by_strokes (TomoeContext *ctx, - TomoeWriting *input); +GList *tomoe_context_search (TomoeContext *ctx, + TomoeQuery *query); +GList *tomoe_context_advanced_search (TomoeContext *ctx, + GList *queries); -/** - * @brief Match reading of TomoeChar with input. - * @param ctx - Pointer to the TomoeContext object. - * @param reading - Pointer to string matchkey - * @return The list of TomoeCandidate. - */ -GList *tomoe_context_search_by_reading (TomoeContext *ctx, - const char *reading); G_END_DECLS #endif /* __TOMOE_CONTEXT_H__ */ Index: tomoe/lib/tomoe-dict.c diff -u tomoe/lib/tomoe-dict.c:1.67 tomoe/lib/tomoe-dict.c:1.68 --- tomoe/lib/tomoe-dict.c:1.67 Wed Nov 22 15:39:44 2006 +++ tomoe/lib/tomoe-dict.c Wed Nov 22 18:04:47 2006 @@ -21,7 +21,7 @@ * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307 USA * - * $Id: tomoe-dict.c,v 1.67 2006/11/22 06:39:44 kous Exp $ + * $Id: tomoe-dict.c,v 1.68 2006/11/22 09:04:47 kous Exp $ */ #include <stdio.h> @@ -63,7 +63,7 @@ }; typedef struct _TomoeDictSearchContext { - const char *reading; + TomoeReading *reading; GList *results; } TomoeDictSearchContext; @@ -408,76 +408,70 @@ return TOMOE_DICT_GET_PRIVATE(dict)->letters->len; } -void -tomoe_dict_add_char (TomoeDict* dict, TomoeChar* add) +gboolean +tomoe_dict_register_char (TomoeDict* dict, TomoeChar* add) { TomoeDictPrivate *priv; - g_return_if_fail(dict); - g_return_if_fail(add); + g_return_val_if_fail(dict, FALSE); + g_return_val_if_fail(add, FALSE); priv = TOMOE_DICT_GET_PRIVATE(dict); g_ptr_array_add (priv->letters, g_object_ref (G_OBJECT (add))); g_ptr_array_sort (priv->letters, letter_compare_func); tomoe_dict_set_modified (dict, TRUE); -} -void -tomoe_dict_insert (TomoeDict *dict, int position, TomoeChar *insert) -{ - if (!dict || !insert) return; - /*tomoe_array_insert (dict->letters, position, insert);*/ - /* TODO do we need dict?? */ - tomoe_dict_set_modified (dict, TRUE); + return TRUE; } -void -tomoe_dict_remove_by_char (TomoeDict* dict, TomoeChar* remove) +gboolean +tomoe_dict_unregister_char (TomoeDict* dict, const gchar *code_point) { - g_return_if_fail(dict); - - g_ptr_array_remove_index (TOMOE_DICT_GET_PRIVATE(dict)->letters, - tomoe_dict_find_index (dict, remove)); - g_object_unref (G_OBJECT (remove)); - tomoe_dict_set_modified (dict, TRUE); -} + GPtrArray *chars; + TomoeChar *removed = NULL; + guint i, index = -1; -void -tomoe_dict_remove_by_index (TomoeDict* dict, int remove) -{ - TomoeChar *c; - TomoeDictPrivate *priv; + g_return_val_if_fail(dict, FALSE); + g_return_val_if_fail(code_point, FALSE); - g_return_if_fail(dict); + chars = TOMOE_DICT_GET_PRIVATE(dict)->letters; + for (i = 0; i < chars->len; i++) { + TomoeChar *chr = g_ptr_array_index (chars, i); + if (0 == strcmp(tomoe_char_get_code(chr), code_point)) { + index = i; + removed = chr; + break; + } + } - priv = TOMOE_DICT_GET_PRIVATE(dict); - c = (TomoeChar *) g_ptr_array_remove_index (priv->letters, remove); - g_object_unref (G_OBJECT (c)); - tomoe_dict_set_modified (dict, TRUE); + if (index >= 0) { + g_ptr_array_remove_index (chars, index); + g_object_unref (removed); + tomoe_dict_set_modified (dict, TRUE); + return TRUE; + } else { + return FALSE; + } } -glong -tomoe_dict_find_index (TomoeDict* dict, TomoeChar* find) +TomoeChar * +tomoe_dict_get_char (TomoeDict* dict, const gchar *code_point) { - TomoeDictPrivate *priv; + GPtrArray *chars; guint i; - g_return_val_if_fail(dict, -1); + g_return_val_if_fail(dict, NULL); + g_return_val_if_fail(code_point, NULL); - priv = TOMOE_DICT_GET_PRIVATE(dict); - for (i = 0; i < priv->letters->len; i++) { - TomoeChar *letter = g_ptr_array_index (priv->letters, i); - if (tomoe_char_compare (letter, find)) - return (glong)i; + chars = TOMOE_DICT_GET_PRIVATE(dict)->letters; + for (i = 0; i < chars->len; i++) { + TomoeChar *chr = g_ptr_array_index (chars, i); + if (0 == strcmp(tomoe_char_get_code(chr), code_point)) { + return chr; + } } - return -1; -} -TomoeChar* -tomoe_dict_char_by_index (TomoeDict* dict, int index) -{ - g_return_val_if_fail(dict, NULL); - return g_ptr_array_index (TOMOE_DICT_GET_PRIVATE(dict)->letters, index); + return NULL; } const GPtrArray* @@ -487,6 +481,17 @@ return TOMOE_DICT_GET_PRIVATE(dict)->letters; } +static gint +tomoe_dict_compare_reading (gconstpointer a, gconstpointer b) +{ + TomoeReading *reading, *searched_reading; + + reading = TOMOE_READING(a); + searched_reading = TOMOE_READING(b); + return strcmp(tomoe_reading_get_reading(reading), + tomoe_reading_get_reading(searched_reading)); +} + static void tomoe_dict_collect_chars_by_reading (gpointer data, gpointer user_data) { @@ -494,13 +499,13 @@ TomoeDictSearchContext *context = user_data; if (g_list_find_custom ((GList *)tomoe_char_get_readings (chr), - context->reading, (GCompareFunc)strcmp)) + context->reading, tomoe_dict_compare_reading)) context->results = g_list_prepend (context->results, tomoe_candidate_new (chr)); } GList * -tomoe_dict_search_by_reading (const TomoeDict* dict, const char *reading) +tomoe_dict_search_by_reading (TomoeDict* dict, TomoeReading *reading) { TomoeDictPrivate *priv; TomoeDictSearchContext context; @@ -521,8 +526,12 @@ xmlNodePtr child; for (child = node->children; child; child = child->next) { if (child->type == XML_ELEMENT_NODE) { - tomoe_char_add_reading (chr, - (const gchar *)child->children->content); + TomoeReading *reading; + reading = + tomoe_reading_new (TOMOE_READING_ON, + (const gchar *)child->children->content); + tomoe_char_add_reading (chr, reading); + g_object_unref (reading); } } } Index: tomoe/lib/tomoe-dict.h diff -u tomoe/lib/tomoe-dict.h:1.42 tomoe/lib/tomoe-dict.h:1.43 --- tomoe/lib/tomoe-dict.h:1.42 Wed Nov 22 15:04:22 2006 +++ tomoe/lib/tomoe-dict.h Wed Nov 22 18:04:47 2006 @@ -21,7 +21,7 @@ * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307 USA * - * $Id: tomoe-dict.h,v 1.42 2006/11/22 06:04:22 kous Exp $ + * $Id: tomoe-dict.h,v 1.43 2006/11/22 09:04:47 kous Exp $ */ /** @@ -112,50 +112,29 @@ /* Editable methods */ /** - * @brief Add a character + * @brief Register a character * @param dict - Pointer to the TomoeDict object. - * @param add - Pointer to the TomoeChar object. + * @param chr - Pointer to the TomoeChar object. */ -void tomoe_dict_add_char (TomoeDict *dict, - TomoeChar *remove); - -void tomoe_dict_insert (TomoeDict *dict, - int position, - TomoeChar *insert); - -/** - * @brief Remove a character by a character object - * @param dict - Pointer to the TomoeDict object. - * @param remove - Pointer to the TomoeChar object. - */ -void tomoe_dict_remove_by_char (TomoeDict *dict, - TomoeChar *remove); +gboolean tomoe_dict_register_char (TomoeDict *dict, + TomoeChar *chr); /** - * @brief Remove a character by index + * @brief Unregister a character by code point * @param dict - Pointer to the TomoeDict object. - * @param remove - Index of the character. - */ -void tomoe_dict_remove_by_index (TomoeDict *dict, - int remove); - -/** - * @brief Find a character - * @param dict - Pointer to the TomoeDict object. - * @param find - Pointer to the TomoeChar object. - * @return Index of the character. + * @param code_point - Code point of the character. */ -glong tomoe_dict_find_index (TomoeDict *dict, - TomoeChar *find); +gboolean tomoe_dict_unregister_char (TomoeDict *dict, + const gchar *code_point); /** - * @brief Get a character by index + * @brief Get a character by code point * @param dict - Pointer to the TomoeDict object. - * @param index - Index of the character. + * @param code_point - Code point of the character. * @return TomoeChar object. */ -TomoeChar *tomoe_dict_char_by_index (TomoeDict *dict, - int index); +TomoeChar *tomoe_dict_get_char (TomoeDict *dict, + const gchar *code_point); /** * @brief Return an GPtrArray of TomoeChar which is kept in a TomoeDict. @@ -171,8 +150,8 @@ * @param reading - Pointer to string matchkey * @return The GList of TomoeCandidate. */ -GList *tomoe_dict_search_by_reading (const TomoeDict *dict, - const char *reading); +GList *tomoe_dict_search_by_reading (TomoeDict *dict, + TomoeReading *reading); G_END_DECLS Index: tomoe/lib/tomoe-query.c diff -u /dev/null tomoe/lib/tomoe-query.c:1.1 --- /dev/null Wed Nov 22 18:04:47 2006 +++ tomoe/lib/tomoe-query.c Wed Nov 22 18:04:47 2006 @@ -0,0 +1,217 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Copyright (C) 2006 Kouhei Sutou <kou****@cozmi*****> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA + * + * $Id: tomoe-query.c,v 1.1 2006/11/22 09:04:47 kous Exp $ + */ + +#include <stdlib.h> +#include <string.h> +#include <glib.h> +#include <glib/gi18n.h> + +#include "tomoe-enum-types.h" +#include "tomoe-query.h" +#include "glib-utils.h" + +#define TOMOE_QUERY_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TOMOE_TYPE_QUERY, TomoeQueryPrivate)) + +typedef struct _TomoeQueryPrivate TomoeQueryPrivate; +struct _TomoeQueryPrivate +{ + GList *readings; + GList *radicals; + GList *variants; + gint number_of_strokes; + TomoeWriting *writing; +}; + +enum +{ + PROP_0, + PROP_READINGS, + PROP_RADICALS, + PROP_VARIANTS, + PROP_NUMBER_OF_STROKES, + PROP_WRITING +}; + +G_DEFINE_TYPE (TomoeQuery, tomoe_query, G_TYPE_OBJECT) + +static void tomoe_query_dispose (GObject *object); +static void tomoe_query_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec); +static void tomoe_query_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec); + +static void +tomoe_query_class_init (TomoeQueryClass *klass) +{ + GObjectClass *gobject_class; + + gobject_class = G_OBJECT_CLASS (klass); + + gobject_class->dispose = tomoe_query_dispose; + gobject_class->set_property = tomoe_query_set_property; + gobject_class->get_property = tomoe_query_get_property; + + g_type_class_add_private (gobject_class, sizeof (TomoeQueryPrivate)); +} + +static void +tomoe_query_init (TomoeQuery *query) +{ + TomoeQueryPrivate *priv = TOMOE_QUERY_GET_PRIVATE (query); + + priv->readings = NULL; + priv->radicals = NULL; + priv->variants = NULL; + priv->number_of_strokes = -1; + priv->writing = NULL; +} + +TomoeQuery * +tomoe_query_new (void) +{ + return g_object_new(TOMOE_TYPE_QUERY, NULL); +} + +static void +tomoe_query_dispose (GObject *object) +{ + TomoeQueryPrivate *priv = TOMOE_QUERY_GET_PRIVATE (object); + + if (priv->readings) { + g_list_foreach (priv->readings, (GFunc)g_object_unref, NULL); + g_list_free (priv->readings); + } + if (priv->radicals) { + g_list_foreach (priv->radicals, (GFunc)g_object_unref, NULL); + g_list_free (priv->radicals); + } + if (priv->variants) { + g_list_foreach (priv->variants, (GFunc)g_object_unref, NULL); + g_list_free (priv->variants); + } + + if (priv->writing) + g_object_unref (priv->writing); + + priv->readings = NULL; + priv->radicals = NULL; + priv->variants = NULL; + priv->number_of_strokes = -1; + priv->writing = NULL; + + G_OBJECT_CLASS (tomoe_query_parent_class)->dispose (object); +} +static void +tomoe_query_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + TomoeQuery *query; + TomoeQueryPrivate *priv; + + query = TOMOE_QUERY(object); + priv = TOMOE_QUERY_GET_PRIVATE (query); + + switch (prop_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; + } +} + +static void +tomoe_query_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + TomoeQuery *query; + TomoeQueryPrivate *priv; + + query = TOMOE_QUERY (object); + priv = TOMOE_QUERY_GET_PRIVATE (query); + + switch (prop_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; + } +} + +void +tomoe_query_add_reading (TomoeQuery* query, TomoeReading *reading) +{ + TomoeQueryPrivate *priv; + + g_return_if_fail (TOMOE_IS_QUERY (query)); + + priv = TOMOE_QUERY_GET_PRIVATE (query); + priv->readings = g_list_append (priv->readings, g_object_ref (reading)); +} + +const GList * +tomoe_query_get_readings (TomoeQuery* query) +{ + TomoeQueryPrivate *priv; + + g_return_val_if_fail (TOMOE_IS_QUERY (query), NULL); + + priv = TOMOE_QUERY_GET_PRIVATE (query); + return priv->readings; +} + + +void +tomoe_query_set_writing (TomoeQuery* query, TomoeWriting *writing) +{ + TomoeQueryPrivate *priv; + + g_return_if_fail (TOMOE_IS_QUERY (query)); + + priv = TOMOE_QUERY_GET_PRIVATE (query); + if (priv->writing) + g_object_unref (priv->writing); + + priv->writing = g_object_ref (writing); +} + +TomoeWriting * +tomoe_query_get_writing (TomoeQuery* query) +{ + TomoeQueryPrivate *priv; + + g_return_val_if_fail (TOMOE_IS_QUERY (query), NULL); + + priv = TOMOE_QUERY_GET_PRIVATE (query); + return priv->writing; +} + + +/* +vi:ts=4:nowrap:ai:expandtab +*/ Index: tomoe/lib/tomoe-query.h diff -u /dev/null tomoe/lib/tomoe-query.h:1.1 --- /dev/null Wed Nov 22 18:04:47 2006 +++ tomoe/lib/tomoe-query.h Wed Nov 22 18:04:47 2006 @@ -0,0 +1,86 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Copyright (C) 2006 Kouhei Sutou <kou****@cozmi*****> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA + * + * $Id: tomoe-query.h,v 1.1 2006/11/22 09:04:47 kous Exp $ + */ + +/** + * @file tomoe-search-condition.h + * @brief + */ + +#ifndef __TOMOE_QUERY_H__ +#define __TOMOE_QUERY_H__ + +#include <glib-object.h> + +G_BEGIN_DECLS + +#include "tomoe-char.h" +#include "tomoe-reading.h" +#include "tomoe-writing.h" + +#define TOMOE_TYPE_QUERY (tomoe_query_get_type ()) +#define TOMOE_QUERY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TOMOE_TYPE_QUERY, TomoeQuery)) +#define TOMOE_QUERY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TOMOE_TYPE_QUERY, TomoeQueryClass)) +#define TOMOE_IS_QUERY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TOMOE_TYPE_QUERY)) +#define TOMOE_IS_QUERY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TOMOE_TYPE_QUERY)) +#define TOMOE_QUERY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), TOMOE_TYPE_QUERY, TomoeQueryClass)) + +typedef struct _TomoeQuery TomoeQuery; +typedef struct _TomoeQueryClass TomoeQueryClass; + +struct _TomoeQuery +{ + GObject object; +}; + +struct _TomoeQueryClass +{ + GObjectClass parent_class; +}; + +GType tomoe_query_get_type (void) G_GNUC_CONST; + +/** + * @brief Create a database. + * @return Pointer to newly allocated TomoeQuery struct. + */ +TomoeQuery *tomoe_query_new (void); + +void tomoe_query_add_reading (TomoeQuery *query, + TomoeReading *reading); +const GList *tomoe_query_get_readings (TomoeQuery *query); +void tomoe_query_add_radical (TomoeQuery *query, + TomoeChar *chr); +void tomoe_query_add_variant (TomoeQuery *query, + TomoeChar *chr); +void tomoe_query_set_number_of_strokes (TomoeQuery *query, + gint num); +void tomoe_query_set_writing (TomoeQuery *query, + TomoeWriting *writing); +TomoeWriting *tomoe_query_get_writing (TomoeQuery *query); + +G_END_DECLS + +#endif /* __TOMOE_QUERY_H__ */ + +/* +vi:ts=4:nowrap:ai:expandtab +*/ Index: tomoe/lib/tomoe-reading.c diff -u /dev/null tomoe/lib/tomoe-reading.c:1.1 --- /dev/null Wed Nov 22 18:04:47 2006 +++ tomoe/lib/tomoe-reading.c Wed Nov 22 18:04:47 2006 @@ -0,0 +1,196 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Copyright (C) 2006 Kouhei Sutou <kou****@cozmi*****> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA + * + * $Id: tomoe-reading.c,v 1.1 2006/11/22 09:04:47 kous Exp $ + */ + +#include <stdlib.h> +#include <string.h> +#include <glib.h> +#include <glib/gi18n.h> + +#include "tomoe-enum-types.h" +#include "tomoe-reading.h" +#include "glib-utils.h" + +#define TOMOE_READING_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TOMOE_TYPE_READING, TomoeReadingPrivate)) + +typedef struct _TomoeReadingPrivate TomoeReadingPrivate; +struct _TomoeReadingPrivate +{ + TomoeReadingType type; + gchar *reading; +}; + +enum +{ + PROP_0, + PROP_TYPE, + PROP_READING +}; + +G_DEFINE_TYPE (TomoeReading, tomoe_reading, G_TYPE_OBJECT) + +static void tomoe_reading_dispose (GObject *object); +static void tomoe_reading_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec); +static void tomoe_reading_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec); + +static void +tomoe_reading_class_init (TomoeReadingClass *klass) +{ + GObjectClass *gobject_class; + GParamSpec *spec; + + gobject_class = G_OBJECT_CLASS (klass); + + gobject_class->dispose = tomoe_reading_dispose; + gobject_class->set_property = tomoe_reading_set_property; + gobject_class->get_property = tomoe_reading_get_property; + + spec = g_param_spec_enum ("type", + N_("Type"), + N_("A type of the reading."), + TOMOE_TYPE_READING_TYPE, + TOMOE_READING_INVALID, + G_PARAM_READABLE | G_PARAM_WRITABLE | + G_PARAM_CONSTRUCT_ONLY); + g_object_class_install_property (gobject_class, PROP_TYPE, spec); + + spec = g_param_spec_string ("reading", + N_("Reading"), + N_("Reading of the reading."), + NULL, + G_PARAM_READABLE | G_PARAM_WRITABLE | + G_PARAM_CONSTRUCT_ONLY); + g_object_class_install_property (gobject_class, PROP_READING, spec); + + g_type_class_add_private (gobject_class, sizeof (TomoeReadingPrivate)); +} + +static void +tomoe_reading_init (TomoeReading *reading) +{ + TomoeReadingPrivate *priv = TOMOE_READING_GET_PRIVATE (reading); + priv->type = TOMOE_READING_INVALID; + priv->reading = NULL; +} + +TomoeReading * +tomoe_reading_new (TomoeReadingType type, const gchar *reading) +{ + return g_object_new(TOMOE_TYPE_READING, + "type", type, + "reading", reading, + NULL); +} + +static void +tomoe_reading_dispose (GObject *object) +{ + TomoeReadingPrivate *priv = TOMOE_READING_GET_PRIVATE (object); + + if (priv->reading) + g_free(priv->reading); + priv->reading = NULL; + + G_OBJECT_CLASS (tomoe_reading_parent_class)->dispose (object); +} +static void +tomoe_reading_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + TomoeReading *reading; + TomoeReadingPrivate *priv; + + reading = TOMOE_READING(object); + priv = TOMOE_READING_GET_PRIVATE (reading); + + switch (prop_id) { + case PROP_TYPE: + priv->type = g_value_get_enum(value); + break; + case PROP_READING: + g_free(priv->reading); + priv->reading = g_value_dup_string(value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; + } +} + +static void +tomoe_reading_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + TomoeReading *reading; + TomoeReadingPrivate *priv; + + reading = TOMOE_READING (object); + priv = TOMOE_READING_GET_PRIVATE (reading); + + switch (prop_id) { + case PROP_TYPE: + g_value_set_enum(value, priv->type); + break; + case PROP_READING: + g_value_set_string(value, priv->reading); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; + } +} + +TomoeReadingType +tomoe_reading_get_reading_type (TomoeReading* reading) +{ + TomoeReadingPrivate *priv; + + g_return_val_if_fail (TOMOE_IS_READING (reading), TOMOE_READING_INVALID); + + priv = TOMOE_READING_GET_PRIVATE (reading); + return priv->type; +} + +const gchar * +tomoe_reading_get_reading (TomoeReading* reading) +{ + TomoeReadingPrivate *priv; + + g_return_val_if_fail (TOMOE_IS_READING (reading), NULL); + + priv = TOMOE_READING_GET_PRIVATE (reading); + return priv->reading; +} + +/* +vi:ts=4:nowrap:ai:expandtab +*/ Index: tomoe/lib/tomoe-reading.h diff -u /dev/null tomoe/lib/tomoe-reading.h:1.1 --- /dev/null Wed Nov 22 18:04:47 2006 +++ tomoe/lib/tomoe-reading.h Wed Nov 22 18:04:47 2006 @@ -0,0 +1,78 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Copyright (C) 2006 Kouhei Sutou <kou****@cozmi*****> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA + * + * $Id: tomoe-reading.h,v 1.1 2006/11/22 09:04:47 kous Exp $ + */ + +/** @file tomoe-reading.h + * @brief + */ + +#ifndef __TOMOE_READING_H__ +#define __TOMOE_READING_H__ + +#include <glib-object.h> + +G_BEGIN_DECLS + +#define TOMOE_TYPE_READING (tomoe_reading_get_type ()) +#define TOMOE_READING(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TOMOE_TYPE_READING, TomoeReading)) +#define TOMOE_READING_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TOMOE_TYPE_READING, TomoeReadingClass)) +#define TOMOE_IS_READING(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TOMOE_TYPE_READING)) +#define TOMOE_IS_READING_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TOMOE_TYPE_READING)) +#define TOMOE_READING_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), TOMOE_TYPE_READING, TomoeReadingClass)) + +typedef struct _TomoeReading TomoeReading; +typedef struct _TomoeReadingClass TomoeReadingClass; + +struct _TomoeReading +{ + GObject object; +}; + +struct _TomoeReadingClass +{ + GObjectClass parent_class; +}; + +typedef enum { + TOMOE_READING_INVALID, + TOMOE_READING_ON, + TOMOE_READING_KUN +} TomoeReadingType; + +GType tomoe_reading_get_type (void) G_GNUC_CONST; + +/** + * @brief Create a TomoeReading. + * @return Pointer to newly allocated TomoeReading struct. + */ +TomoeReading *tomoe_reading_new (TomoeReadingType type, + const gchar *reading); + +TomoeReadingType tomoe_reading_get_reading_type (TomoeReading *reading); +const gchar *tomoe_reading_get_reading (TomoeReading *reading); + +G_END_DECLS + +#endif /* __TOMOE_READING_H__ */ + +/* +vi:ts=4:nowrap:ai:expandtab +*/ Index: tomoe/lib/tomoe.h diff -u tomoe/lib/tomoe.h:1.30 tomoe/lib/tomoe.h:1.31 --- tomoe/lib/tomoe.h:1.30 Wed Nov 22 14:59:05 2006 +++ tomoe/lib/tomoe.h Wed Nov 22 18:04:47 2006 @@ -20,7 +20,7 @@ * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307 USA * - * $Id: tomoe.h,v 1.30 2006/11/22 05:59:05 makeinu Exp $ + * $Id: tomoe.h,v 1.31 2006/11/22 09:04:47 kous Exp $ */ /** @file tomoe.h @@ -35,6 +35,7 @@ G_BEGIN_DECLS #include "tomoe-config.h" +#include "tomoe-enum-types.h" #include "tomoe-writing.h" #include "tomoe-recognizer.h"