2 * matdb: generic materials database information.
6 Copyright (C) 2008 Joseph Pingenot
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU Affero General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Affero General Public License for more details.
18 You should have received a copy of the GNU Affero General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
27 static void print_property(gpointer key, gpointer value, gpointer user_data) {
28 fprintf(stderr, "\t\t%s=%g:\n", (char*)key, *(double*)value);
30 static void print_inner_bowing(gpointer key, gpointer value, gpointer user_data) {
31 struct matdb_bowing *bowing = (struct matdb_bowing*)value;
32 fprintf(stderr, "\tbowing %s:%s[%s:%s]:\n", bowing->from->str, bowing->to->str, (char*)user_data, (char*)key);
33 g_hash_table_foreach(bowing->properties, &print_property, NULL);
35 static void print_material(gpointer key, gpointer value, gpointer user_data) {
36 struct matdb_material *mat = (struct matdb_material*)value;
37 fprintf(stderr, "\tmaterial %s(%s):\n", mat->name->str, (char*)key);
38 g_hash_table_foreach(mat->properties, &print_property, NULL);
40 static void print_bowing(gpointer key, gpointer value, gpointer user_data) {
41 GHashTable *ht = value;
42 g_hash_table_foreach(ht, &print_inner_bowing, key);
45 void print_matdb(const struct matdb *mdb) {
46 fprintf(stderr, "matdb:\n");
47 g_hash_table_foreach(mdb->materials, &print_material, NULL);
48 g_hash_table_foreach(mdb->bowings, &print_bowing, NULL);
51 void destroy_material_gpointer(gpointer data) {
52 destroy_material((struct matdb_material *)data);
54 void destroy_bowing_gpointer(gpointer data) {
55 destroy_bowing((struct matdb_bowing *)data);
57 void destroy_material(struct matdb_material *mat) {
59 fprintf(stderr, "destroy_material\n");
61 g_string_free(mat->name, TRUE);
62 g_hash_table_unref(mat->properties);
65 void destroy_bowing(struct matdb_bowing *bow) {
67 fprintf(stderr, "destroy_bowing\n");
69 g_string_free(bow->from, TRUE);
70 g_string_free(bow->to, TRUE);
71 g_hash_table_unref(bow->properties);