[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gnue/geas/src/classdef classdef.c classdef.h
From: |
Reinhard Mueller |
Subject: |
gnue/geas/src/classdef classdef.c classdef.h |
Date: |
Mon, 01 Oct 2001 15:49:36 -0400 |
CVSROOT: /cvsroot/gnue
Module name: gnue
Changes by: Reinhard Mueller <address@hidden> 01/10/01 15:49:36
Modified files:
geas/src/classdef: classdef.c classdef.h
Log message:
Resolve compound types.
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/geas/src/classdef/classdef.c.diff?tr1=1.16&tr2=1.17&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/geas/src/classdef/classdef.h.diff?tr1=1.14&tr2=1.15&r1=text&r2=text
Patches:
Index: gnue/geas/src/classdef/classdef.c
diff -u gnue/geas/src/classdef/classdef.c:1.16
gnue/geas/src/classdef/classdef.c:1.17
--- gnue/geas/src/classdef/classdef.c:1.16 Sat Sep 29 13:16:10 2001
+++ gnue/geas/src/classdef/classdef.c Mon Oct 1 15:49:36 2001
@@ -19,7 +19,7 @@
along with GEAS; if not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- $Id: classdef.c,v 1.16 2001/09/29 17:16:10 reinhard Exp $
+ $Id: classdef.c,v 1.17 2001/10/01 19:49:36 reinhard Exp $
*/
#include "config.h"
@@ -82,6 +82,7 @@
char *name; /* without module */
char *name_full; /* with module */
char *name_db; /* name of column in the database */
+ geas_cd_type *type;
geas_cd_datatype datatype;
int format; /* only for char types */
geas_cd_class *refclass; /* only for reference and list types */
@@ -483,12 +484,42 @@
}
/* ------------------------------------------------------------------------- *\
+ * Copy a single field into a class (called in g_hash_table_foreach)
+\* ------------------------------------------------------------------------- */
+static void
+_hf_copy_field (gpointer key, gpointer value, gpointer user_data)
+{
+ geas_cd_field *f;
+ geas_cd_field *original = (geas_cd_field *)value;
+ geas_cd_field *compound = (geas_cd_field *)user_data;
+
+ f = g_new0 (geas_cd_field, 1);
+ f->parent = compound->fields;
+ f->name = g_strconcat (compound->name, ".", original->name,
NULL);
+ f->name_full = g_strconcat (compound->name_full, ".", original->name,
NULL);
+ f->name_db = g_strconcat (compound->name_db, "__", original->name,
NULL);
+ f->type = original->type;
+ f->datatype = original->datatype;
+ f->format = original->format;
+ f->refclass = original->refclass;
+ f->default_val = g_strdup (original->default_val);
+ f->property = original->property;
+ g_hash_table_insert (compound->fields, f->name, f);
+ if ((f->type) && (f->type->fields))
+ {
+ /* copy recursively */
+ f->fields = g_hash_table_new (g_str_hash, g_str_equal);
+ g_hash_table_foreach (f->type->fields, _hf_copy_field, f);
+ }
+}
+
+/* ------------------------------------------------------------------------- *\
* Allocate a new field as a member of a class
* One of the parameters type, reference or list must be filled in
\* ------------------------------------------------------------------------- */
geas_cd_field *
geas_cd_class_field_new (geas_cd_class *c, const geas_cd_module *m,
- const char *name, const geas_cd_type *type,
+ const char *name, geas_cd_type *type,
geas_cd_class *reference, geas_cd_class *list)
{
geas_cd_field *f;
@@ -510,13 +541,16 @@
if (type)
{
f->name_db = g_strconcat (m->name, "__", name, NULL);
+ f->type = type;
f->datatype = type->datatype;
f->format = type->format;
f->refclass = type->refclass;
- if (f->datatype == GEAS_CD_DATATYPE_COMPOUND)
+ if (type->fields)
{
- f->fields = g_hash_table_new (g_str_hash, g_str_equal);
+ /* Copy the fields from typedef to actual class */
+ f->fields = g_hash_table_new (g_str_hash, g_str_equal);
+ g_hash_table_foreach (type->fields, _hf_copy_field, f);
}
}
else if (reference)
@@ -647,7 +681,7 @@
\* ------------------------------------------------------------------------- */
geas_cd_field *
geas_cd_type_field_new (geas_cd_type *t, const char *name,
- const geas_cd_type *type, geas_cd_class *reference,
+ geas_cd_type *type, geas_cd_class *reference,
geas_cd_class *list)
{
geas_cd_field *f;
@@ -664,18 +698,13 @@
f->parent = t->fields;
f->name = g_strdup (name);
f->name_full = g_strdup (name);
- f->name_db = g_strdup (name);
if (type)
{
+ f->type = type;
f->datatype = type->datatype;
f->format = type->format;
f->refclass = type->refclass;
-
- if (f->datatype == GEAS_CD_DATATYPE_COMPOUND)
- {
- f->fields = g_hash_table_new (g_str_hash, g_str_equal);
- }
}
else if (reference)
{
@@ -760,6 +789,11 @@
_hf_append_field (gpointer key, gpointer value, gpointer user_data)
{
*(GList **)user_data = g_list_append (*(GList **)user_data, value);
+ if (((geas_cd_field *)value)->fields)
+ {
+ g_hash_table_foreach (((geas_cd_field *)value)->fields, _hf_append_field,
+ user_data);
+ }
}
/* ------------------------------------------------------------------------- *\
@@ -770,10 +804,6 @@
{
geas_cd_fieldlist *fl;
- /* TODO: Should take the following options:
- a) list top level fields with compound types unresolved
- b) list all user visible fields with compound types resolved
- c) list database backend visible fields */
fl = g_new0 (geas_cd_fieldlist, 1);
g_hash_table_foreach (c->fields, _hf_append_field, &(fl->list));
return (fl);
Index: gnue/geas/src/classdef/classdef.h
diff -u gnue/geas/src/classdef/classdef.h:1.14
gnue/geas/src/classdef/classdef.h:1.15
--- gnue/geas/src/classdef/classdef.h:1.14 Mon Oct 1 10:42:31 2001
+++ gnue/geas/src/classdef/classdef.h Mon Oct 1 15:49:36 2001
@@ -19,7 +19,7 @@
along with GEAS; if not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- $Id: classdef.h,v 1.14 2001/10/01 14:42:31 reinhard Exp $
+ $Id: classdef.h,v 1.15 2001/10/01 19:49:36 reinhard Exp $
*/
/* ------------------------------------------------------------------------- *\
@@ -105,7 +105,7 @@
geas_cd_field *geas_cd_class_field_new (geas_cd_class *c,
const geas_cd_module *m,
const char *name,
- const geas_cd_type *type,
+ geas_cd_type *type,
geas_cd_class *reference,
geas_cd_class *list);
geas_cd_field *geas_cd_class_find_field (const geas_cd_class *c,
@@ -124,7 +124,7 @@
const char *geas_cd_type_get_name_full (const geas_cd_type *t);
const char *geas_cd_type_get_filename (const geas_cd_type *t);
geas_cd_field *geas_cd_type_field_new (geas_cd_type *t, const char *name,
- const geas_cd_type *type,
+ geas_cd_type *type,
geas_cd_class *reference,
geas_cd_class *list);
geas_cd_field *geas_cd_type_find_field (const geas_cd_type *t,
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- gnue/geas/src/classdef classdef.c classdef.h,
Reinhard Mueller <=