/*
* matdb: generic materials database information.
Copyright (C) 2008 Joseph Pingenot
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
*/
#include
#include
#include
static void print_property(gpointer key, gpointer value, gpointer user_data) {
fprintf(stderr, "\t\t%s=%g:\n", (char*)key, *(double*)value);
}
static void print_inner_bowing(gpointer key, gpointer value, gpointer user_data) {
struct matdb_bowing *bowing = (struct matdb_bowing*)value;
fprintf(stderr, "\tbowing %s:%s[%s:%s]:\n", bowing->from->str, bowing->to->str, (char*)user_data, (char*)key);
g_hash_table_foreach(bowing->properties, &print_property, NULL);
}
static void print_material(gpointer key, gpointer value, gpointer user_data) {
struct matdb_material *mat = (struct matdb_material*)value;
fprintf(stderr, "\tmaterial %s(%s):\n", mat->name->str, (char*)key);
g_hash_table_foreach(mat->properties, &print_property, NULL);
}
static void print_bowing(gpointer key, gpointer value, gpointer user_data) {
GHashTable *ht = value;
g_hash_table_foreach(ht, &print_inner_bowing, key);
}
void print_matdb(const struct matdb *mdb) {
fprintf(stderr, "matdb:\n");
g_hash_table_foreach(mdb->materials, &print_material, NULL);
g_hash_table_foreach(mdb->bowings, &print_bowing, NULL);
}
void destroy_material_gpointer(gpointer data) {
destroy_material((struct matdb_material *)data);
}
void destroy_bowing_gpointer(gpointer data) {
destroy_bowing((struct matdb_bowing *)data);
}
void destroy_material(struct matdb_material *mat) {
#ifdef DEBUG
fprintf(stderr, "destroy_material\n");
#endif
g_string_free(mat->name, TRUE);
g_hash_table_unref(mat->properties);
free(mat);
}
void destroy_bowing(struct matdb_bowing *bow) {
#ifdef DEBUG
fprintf(stderr, "destroy_bowing\n");
#endif
g_string_free(bow->from, TRUE);
g_string_free(bow->to, TRUE);
g_hash_table_unref(bow->properties);
free(bow);
}