[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gnue/geas/src/classdef classdef.c classdef.h gc...
From: |
Reinhard Mueller |
Subject: |
gnue/geas/src/classdef classdef.c classdef.h gc... |
Date: |
Sat, 13 Oct 2001 17:46:33 -0400 |
CVSROOT: /cvsroot/gnue
Module name: gnue
Changes by: Reinhard Mueller <address@hidden> 01/10/13 17:46:33
Modified files:
geas/src/classdef: classdef.c classdef.h gcdinfo.c
Log message:
Create shadow fields for implementation of implicit references and
lists.
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/geas/src/classdef/classdef.c.diff?tr1=1.18&tr2=1.19&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/geas/src/classdef/classdef.h.diff?tr1=1.16&tr2=1.17&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/geas/src/classdef/gcdinfo.c.diff?tr1=1.7&tr2=1.8&r1=text&r2=text
Patches:
Index: gnue/geas/src/classdef/classdef.c
diff -u gnue/geas/src/classdef/classdef.c:1.18
gnue/geas/src/classdef/classdef.c:1.19
--- gnue/geas/src/classdef/classdef.c:1.18 Fri Oct 12 16:14:18 2001
+++ gnue/geas/src/classdef/classdef.c Sat Oct 13 17:46:33 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.18 2001/10/12 20:14:18 reinhard Exp $
+ $Id: classdef.c,v 1.19 2001/10/13 21:46:33 reinhard Exp $
*/
#include "config.h"
@@ -66,7 +66,7 @@
char *filename;
geas_cd_datatype datatype;
int format; /* only for char types */
- geas_cd_class *refclass; /* only for reference and list types */
+ geas_cd_class *otherclass; /* only for reference and list types */
GHashTable *fields; /* only for compound types */
};
@@ -79,13 +79,17 @@
struct _geas_cd_field
{
GHashTable *parent; /* hash table containing this field */
+ geas_cd_module *module; /* module that has defined this field
*/
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 */
+ geas_cd_class *thisclass; /* the class containing this field */
+ geas_cd_field *thisfield; /* only for reference and list types:
*/
+ geas_cd_class *otherclass; /* thisfield = otherclass.otherfield
*/
+ geas_cd_field *otherfield;
GHashTable *fields; /* only for compound types */
char *default_val; /* not for ref., list and compound */
int property;
@@ -512,6 +516,92 @@
}
/* ------------------------------------------------------------------------- *\
+ * Create a field
+\* ------------------------------------------------------------------------- */
+static geas_cd_field *
+_create_field (GHashTable *parent, geas_cd_class *cls, geas_cd_module *module,
+ char *name, geas_cd_datatype datatype)
+{
+ geas_cd_field *f;
+
+ f = g_new0 (geas_cd_field, 1);
+ f->parent = parent;
+ f->thisclass = cls;
+ f->module = module;
+ f->name = name;
+ f->datatype = datatype;
+ f->name_full = g_strconcat (f->module->name, "::", f->name, NULL);
+ g_hash_table_insert (f->parent, f->name, f);
+ return (f);
+}
+
+/* ------------------------------------------------------------------------- *\
+ * Create the shadow database fields for a implicit REFERENCE or LIST
+\* ------------------------------------------------------------------------- */
+static void
+_create_shadow_fields (geas_cd_field *f)
+{
+ if (f->datatype == GEAS_CD_DATATYPE_REFERENCE)
+ {
+ /* at least the otherclass must exist */
+ g_return_if_fail (f->otherclass);
+ if (f->thisfield)
+ {
+ /* if thisfield is set, otherfield must be set, too */
+ g_return_if_fail (f->otherfield);
+ }
+ else
+ {
+ /* if thisfield is not set, it is an implicit reference, and we must
+ create a shadow field */
+ geas_cd_field *shadow;
+
+ shadow = _create_field (f->parent, f->thisclass, f->module,
+ g_strconcat ("_", f->name, NULL),
+ GEAS_CD_DATATYPE_ID);
+ /* The shadow field db column starts with an underscore */
+ shadow->name_db = g_strconcat ("_", f->name_db, NULL);
+
+ f->thisfield = shadow;
+ f->otherfield = geas_cd_class_find_field (f->otherclass,
+ _geas_module, "id");
+ }
+ }
+ else if (f->datatype == GEAS_CD_DATATYPE_LIST)
+ {
+ /* at least the otherclass must exist */
+ g_return_if_fail (f->otherclass);
+ if (f->thisfield)
+ {
+ /* if thisfield is set, otherfield must be set, too */
+ g_return_if_fail (f->otherfield);
+ }
+ else
+ {
+ /* if thisfield is not set, it is an implicit list, and we must
+ create a shadow field in the otherclass */
+ geas_cd_field *shadow;
+
+ shadow = _create_field (f->otherclass->fields, f->otherclass,
+ f->module,
+ g_strconcat ("_(", f->thisclass->name_full,
+ ").", f->name, NULL),
+ GEAS_CD_DATATYPE_ID);
+ /* The shadow field db column starts with an underscore */
+ shadow->name_db = g_strconcat ("_", f->thisclass->name_db, "_",
+ f->name_db, NULL);
+ /* FIXME: The above is for compatibility; this would be correct:
+ shadow->name_db = g_strconcat ("_", f->thisclass->name_db, "__",
+ f->name_db, NULL); */
+
+ f->thisfield = geas_cd_class_find_field (f->thisclass, _geas_module,
+ "id");
+ f->otherfield = shadow;
+ }
+ }
+}
+
+/* ------------------------------------------------------------------------- *\
* Copy a single field into a class (called in g_hash_table_foreach)
\* ------------------------------------------------------------------------- */
static void
@@ -521,24 +611,22 @@
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 = _create_field (compound->fields, compound->thisclass, compound->module,
+ g_strconcat (compound->name, ".", original->name, NULL),
+ original->datatype);
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->otherclass = original->otherclass;
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);
}
+ _create_shadow_fields (f);
}
/* ------------------------------------------------------------------------- *\
@@ -546,9 +634,9 @@
* 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, geas_cd_type *type,
- geas_cd_class *reference, geas_cd_class *list)
+geas_cd_class_field_new (geas_cd_class *c, geas_cd_module *m, const char *name,
+ geas_cd_type *type, geas_cd_class *reference,
+ geas_cd_class *list)
{
geas_cd_field *f;
@@ -560,19 +648,13 @@
f = geas_cd_class_find_field (c, m, name);
if (!f)
{
- f = g_new0 (geas_cd_field, 1);
-
- f->parent = c->fields;
- f->name = g_strdup (name);
- f->name_full = g_strconcat (m->name, "::", name, NULL);
-
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;
+ f = _create_field (c->fields, c, m, g_strdup (name), type->datatype);
+ f->name_db = g_strconcat (m->name, "__", name, NULL);
+ f->type = type;
+ f->format = type->format;
+ f->otherclass = type->otherclass;
if (type->fields)
{
@@ -583,20 +665,23 @@
}
else if (reference)
{
- f->datatype = GEAS_CD_DATATYPE_REFERENCE;
- f->refclass = reference;
+ f = _create_field (c->fields, c, m, g_strdup (name),
+ GEAS_CD_DATATYPE_REFERENCE);
+ f->name_db = g_strconcat (m->name, "__", name, NULL);
+ f->otherclass = reference;
}
else if (list)
{
- f->datatype = GEAS_CD_DATATYPE_LIST;
- f->refclass = list;
+ f = _create_field (c->fields, c, m, g_strdup (name),
+ GEAS_CD_DATATYPE_LIST);
+ f->name_db = g_strconcat (m->name, "__", name, NULL);
+ f->otherclass = list;
}
else
{
g_assert_not_reached ();
}
-
- g_hash_table_insert (c->fields, f->name, f);
+ _create_shadow_fields (f);
}
return (f);
@@ -752,20 +837,20 @@
if (type)
{
- f->type = type;
- f->datatype = type->datatype;
- f->format = type->format;
- f->refclass = type->refclass;
+ f->type = type;
+ f->datatype = type->datatype;
+ f->format = type->format;
+ f->otherclass = type->otherclass;
}
else if (reference)
{
- f->datatype = GEAS_CD_DATATYPE_REFERENCE;
- f->refclass = reference;
+ f->datatype = GEAS_CD_DATATYPE_REFERENCE;
+ f->otherclass = reference;
}
else if (list)
{
- f->datatype = GEAS_CD_DATATYPE_LIST;
- f->refclass = list;
+ f->datatype = GEAS_CD_DATATYPE_LIST;
+ f->otherclass = list;
}
else
{
@@ -935,6 +1020,26 @@
}
/* ------------------------------------------------------------------------- *\
+ * Get the name of the column in the database belonging to this field
+\* ------------------------------------------------------------------------- */
+const char *
+geas_cd_field_get_name_db (const geas_cd_field *f)
+{
+ g_return_val_if_fail (f, NULL);
+
+ if ((f->datatype == GEAS_CD_DATATYPE_REFERENCE)
+ || (f->datatype == GEAS_CD_DATATYPE_LIST)
+ || (f->datatype == GEAS_CD_DATATYPE_COMPOUND))
+ {
+ return ("");
+ }
+ else
+ {
+ return (f->name_db);
+ }
+}
+
+/* ------------------------------------------------------------------------- *\
* Get the datatype of a field
\* ------------------------------------------------------------------------- */
geas_cd_datatype
@@ -956,15 +1061,48 @@
return (f->format);
}
+/* ------------------------------------------------------------------------- *\
+ * Get the class that contains a given field
+\* ------------------------------------------------------------------------- */
+geas_cd_class *
+geas_cd_field_get_thisclass (const geas_cd_field *f)
+{
+ g_return_val_if_fail (f, NULL);
+
+ return (f->thisclass);
+}
+
+/* ------------------------------------------------------------------------- *\
+ * Get the own field that implements a reference or a list
+\* ------------------------------------------------------------------------- */
+geas_cd_field *
+geas_cd_field_get_thisfield (const geas_cd_field *f)
+{
+ g_return_val_if_fail (f, NULL);
+
+ return (f->thisfield);
+}
+
/* ------------------------------------------------------------------------- *\
- * Get the class a field references, or NULL if it is not a reference or list
+ * Get the foreign class for a reference or a list field
\* ------------------------------------------------------------------------- */
geas_cd_class *
-geas_cd_field_get_refclass (const geas_cd_field *f)
+geas_cd_field_get_otherclass (const geas_cd_field *f)
+{
+ g_return_val_if_fail (f, NULL);
+
+ return (f->otherclass);
+}
+
+/* ------------------------------------------------------------------------- *\
+ * Get the foreign field that implements a reference or a list
+\* ------------------------------------------------------------------------- */
+geas_cd_field *
+geas_cd_field_get_otherfield (const geas_cd_field *f)
{
g_return_val_if_fail (f, NULL);
- return (f->refclass);
+ return (f->otherfield);
}
/* ------------------------------------------------------------------------- *\
Index: gnue/geas/src/classdef/classdef.h
diff -u gnue/geas/src/classdef/classdef.h:1.16
gnue/geas/src/classdef/classdef.h:1.17
--- gnue/geas/src/classdef/classdef.h:1.16 Fri Oct 12 16:14:18 2001
+++ gnue/geas/src/classdef/classdef.h Sat Oct 13 17:46:33 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.16 2001/10/12 20:14:18 reinhard Exp $
+ $Id: classdef.h,v 1.17 2001/10/13 21:46:33 reinhard Exp $
*/
/* ------------------------------------------------------------------------- *\
@@ -102,8 +102,7 @@
const char *geas_cd_class_get_name_full (const geas_cd_class *c);
const char *geas_cd_class_get_name_db (const geas_cd_class *c);
const char *geas_cd_class_get_filename (const geas_cd_class *c);
-geas_cd_field *geas_cd_class_field_new (geas_cd_class *c,
- const geas_cd_module *m,
+geas_cd_field *geas_cd_class_field_new (geas_cd_class *c, geas_cd_module *m,
const char *name,
geas_cd_type *type,
geas_cd_class *reference,
@@ -150,7 +149,11 @@
void geas_cd_field_set_format (geas_cd_field *f, int format);
const char *geas_cd_field_get_name (const geas_cd_field *f);
const char *geas_cd_field_get_name_full (const geas_cd_field *f);
+const char *geas_cd_field_get_name_db (const geas_cd_field *f);
geas_cd_datatype geas_cd_field_get_datatype (const geas_cd_field *f);
int geas_cd_field_get_format (const geas_cd_field *f);
-geas_cd_class *geas_cd_field_get_refclass (const geas_cd_field *f);
+geas_cd_class *geas_cd_field_get_thisclass (const geas_cd_field *f);
+geas_cd_field *geas_cd_field_get_thisfield (const geas_cd_field *f);
+geas_cd_class *geas_cd_field_get_otherclass (const geas_cd_field *f);
+geas_cd_field *geas_cd_field_get_otherfield (const geas_cd_field *f);
void geas_cd_field_free (geas_cd_field *f);
Index: gnue/geas/src/classdef/gcdinfo.c
diff -u gnue/geas/src/classdef/gcdinfo.c:1.7
gnue/geas/src/classdef/gcdinfo.c:1.8
--- gnue/geas/src/classdef/gcdinfo.c:1.7 Fri Oct 12 16:14:18 2001
+++ gnue/geas/src/classdef/gcdinfo.c Sat Oct 13 17:46:33 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: gcdinfo.c,v 1.7 2001/10/12 20:14:18 reinhard Exp $
+ $Id: gcdinfo.c,v 1.8 2001/10/13 21:46:33 reinhard Exp $
*/
#include <stdio.h>
@@ -92,11 +92,11 @@
break;
case GEAS_CD_DATATYPE_REFERENCE:
printf ("ref. to %-32s",
- geas_cd_class_get_name_full (geas_cd_field_get_refclass (f)));
+ geas_cd_class_get_name_full (geas_cd_field_get_otherclass
(f)));
break;
case GEAS_CD_DATATYPE_LIST:
printf ("list of %-32s",
- geas_cd_class_get_name_full (geas_cd_field_get_refclass (f)));
+ geas_cd_class_get_name_full (geas_cd_field_get_otherclass
(f)));
break;
case GEAS_CD_DATATYPE_COMPOUND:
printf ("compound field ");