1 /* gAlan - Graphical Audio Language
2 * Copyright (C) 1999 Tony Garnock-Jones
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #define OBJECTSTORE_CURRENT_VERSION 1
24 typedef struct ObjectStore ObjectStore
; /* entire document */
25 typedef struct ObjectStoreItem ObjectStoreItem
; /* record */
26 typedef struct ObjectStoreItemField ObjectStoreItemField
; /* field in record */
27 typedef struct ObjectStoreDatum ObjectStoreDatum
; /* datum in field or array */
29 typedef gint32 ObjectStoreKey
;
30 typedef gpointer (*objectstore_unpickler_t
)(ObjectStoreItem
*item
);
31 typedef ObjectStoreItem
*(*objectstore_pickler_t
)(gpointer data
, ObjectStore
*db
);
33 typedef enum ObjectStoreDatumKind
{
42 } ObjectStoreItemKind
;
45 GHashTable
*object_table
; /* key -> ObjectStoreItem */
46 GHashTable
*key_table
; /* object -> key */
47 ObjectStoreKey nextkey
;
48 ObjectStoreKey rootkey
;
51 struct ObjectStoreItem
{
60 struct ObjectStoreItemField
{
62 ObjectStoreDatum
*value
;
65 struct ObjectStoreDatum
{
66 ObjectStoreItemKind kind
;
72 ObjectStoreKey object_key
;
75 ObjectStoreDatum
**elts
;
84 /* Module setup/shutdown */
85 extern void init_objectstore(void);
86 extern void done_objectstore(void);
88 /* Methods on entire ObjectStores */
89 extern ObjectStore
*objectstore_new_objectstore(void);
90 extern void objectstore_kill_objectstore(ObjectStore
*db
);
91 extern gboolean
objectstore_write(FILE *f
, ObjectStore
*db
);
92 extern gboolean
objectstore_read(FILE *f
, ObjectStore
*db
);
93 extern void objectstore_set_root(ObjectStore
*db
, ObjectStoreItem
*root
);
94 extern ObjectStoreItem
*objectstore_get_root(ObjectStore
*db
);
96 /* Map between in-core objects and ObjectStoreItems */
97 extern ObjectStoreItem
*objectstore_get_item(ObjectStore
*db
, gpointer object
);
98 extern ObjectStoreItem
*objectstore_get_item_by_key(ObjectStore
*db
, ObjectStoreKey key
);
99 extern ObjectStoreItem
*objectstore_new_item(ObjectStore
*db
, char *tag
, gpointer object
);
100 extern gpointer
objectstore_get_object(ObjectStoreItem
*item
);
101 extern void objectstore_set_object(ObjectStoreItem
*item
, gpointer object
);
103 /* Specific getter-methods on ObjectStoreItems */
104 extern gint32
objectstore_item_get_integer(ObjectStoreItem
*item
, char *name
, gint32 deft
);
105 extern gdouble
objectstore_item_get_double(ObjectStoreItem
*item
, char *name
, gdouble deft
);
106 extern char *objectstore_item_get_string(ObjectStoreItem
*item
, char *name
, char *deft
);
107 extern ObjectStoreItem
*objectstore_item_get_object(ObjectStoreItem
*item
, char *name
);
108 extern gint32
objectstore_item_get_binary(ObjectStoreItem
*item
, char *name
, void **dataptr
);
109 /* Specific setter-methods on ObjectStoreItems */
110 #define objectstore_item_set_integer(item, name, value) \
111 objectstore_item_set(item, name, objectstore_datum_new_integer(value))
112 #define objectstore_item_set_double(item, name, value) \
113 objectstore_item_set(item, name, objectstore_datum_new_double(value))
114 #define objectstore_item_set_string(item, name, value) \
115 objectstore_item_set(item, name, objectstore_datum_new_string(value))
116 #define objectstore_item_set_object(item, name, value) \
117 objectstore_item_set(item, name, objectstore_datum_new_object(value))
118 /* General methods on ObjectStoreItems */
119 extern ObjectStoreDatum
*objectstore_item_get(ObjectStoreItem
*item
, char *name
);
120 extern void objectstore_item_set(ObjectStoreItem
*item
, char *name
, ObjectStoreDatum
*value
);
122 /* Methods on ObjectStoreDatums */
123 extern ObjectStoreDatum
*objectstore_datum_new_integer(gint32 value
);
124 extern ObjectStoreDatum
*objectstore_datum_new_double(gdouble value
);
125 extern ObjectStoreDatum
*objectstore_datum_new_string(char *value
);
126 extern ObjectStoreDatum
*objectstore_datum_new_object(ObjectStoreItem
*value
);
127 extern ObjectStoreDatum
*objectstore_datum_new_array(int length
);
128 extern ObjectStoreDatum
*objectstore_datum_new_binary(int length
, void *data
);
130 /* Methods on specific kinds of ObjectStoreDatums */
131 extern gint32
objectstore_datum_integer_value(ObjectStoreDatum
*datum
);
132 extern gdouble
objectstore_datum_double_value(ObjectStoreDatum
*datum
);
133 extern char *objectstore_datum_string_value(ObjectStoreDatum
*datum
);
134 extern ObjectStoreKey
objectstore_datum_object_key(ObjectStoreDatum
*obj
);
135 extern int objectstore_datum_array_length(ObjectStoreDatum
*array
);
136 extern ObjectStoreDatum
*objectstore_datum_array_get(ObjectStoreDatum
*array
, int index
);
137 extern void objectstore_datum_array_set(ObjectStoreDatum
*array
, int index
,
138 ObjectStoreDatum
*value
);
140 /* Special utility routines */
141 extern GList
*objectstore_extract_list_of_items(ObjectStoreDatum
*array
, ObjectStore
*db
,
142 objectstore_unpickler_t unpickler
);
143 extern ObjectStoreDatum
*objectstore_create_list_of_items(GList
*list
, ObjectStore
*db
,
144 objectstore_pickler_t pickler
);