* making progress.
[scdataviz] / matdb.c
diff --git a/matdb.c b/matdb.c
new file mode 100644 (file)
index 0000000..891bec5
--- /dev/null
+++ b/matdb.c
@@ -0,0 +1,63 @@
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+
+*/
+
+#include <matdb.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+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_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) {
+  struct matdb_bowing *bowing = (struct matdb_bowing*)value;
+  fprintf(stderr, "\tbowing %s:%s(%s):\n", bowing->from->str, bowing->to->str, (char*)key);
+  g_hash_table_foreach(bowing->properties, print_property, NULL);
+}
+
+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) {
+  free(mat->name);
+  g_hash_table_unref(mat->properties);
+  free(mat);
+}
+void destroy_bowing(struct matdb_bowing *bow) {
+  free(bow->from);
+  free(bow->to);
+  g_hash_table_unref(bow->properties);
+  free(bow);
+}