00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "H5Ipublic.h"
00016 #include "h5Attribute.h"
00017 #include "h5Dataset.h"
00018 #include "h5File.h"
00019 #include "h5Group.h"
00020 #include <assert.h>
00021 #include <stdio.h>
00022
00023
00024
00025 void H5Attribute_dtor(H5Attribute* a)
00026 {
00027 assert(a);
00028
00029 if (a->name)
00030 {
00031 free (a->name);
00032 a->name = NULL;
00033 }
00034
00035 if (a->obj_path)
00036 {
00037 free (a->obj_path);
00038 a->obj_path = NULL;
00039 }
00040
00041 if (a->value)
00042 H5Dataset_freeBuffer(a->value, a->space, a->type, a->nvalue);
00043
00044 H5Datatype_dtor(&(a->type));
00045 }
00046
00047 void H5Dataset_dtor(H5Dataset* d)
00048 {
00049 int i;
00050
00051 assert(d);
00052
00053 if (d->fullpath)
00054 {
00055 free (d->fullpath);
00056 d->fullpath = NULL;
00057 }
00058
00059 if (d->value)
00060 H5Dataset_freeBuffer(d->value, d->space, d->type, d->nvalue);
00061
00062 if (d->attributes)
00063 {
00064 for (i=0; i<d->nattributes; i++)
00065 H5Attribute_dtor(&d->attributes[i]);
00066 free(d->attributes);
00067 d->attributes = NULL;
00068 }
00069
00070
00071 H5Datatype_dtor(&(d->type));
00072 }
00073
00074 void H5File_dtor(H5File* f)
00075 {
00076 assert(f);
00077
00078 if (f->filename)
00079 {
00080 free(f->filename);
00081 f->filename = NULL;
00082 }
00083
00084 if (f->root)
00085 {
00086 H5Group_dtor(f->root);
00087 free (f->root);
00088 }
00089 }
00090
00091 void H5Group_dtor(H5Group* g)
00092 {
00093 int i;
00094 H5Group *member_g;
00095 H5Dataset *member_d;
00096
00097 assert(g);
00098
00099 if (g->fullpath)
00100 {
00101 free (g->fullpath);
00102 g->fullpath = NULL;
00103 }
00104
00105 if (g->attributes)
00106 {
00107 for (i=0; i<g->nattributes; i++)
00108 H5Attribute_dtor(&g->attributes[i]);
00109 free(g->attributes);
00110 g->attributes = NULL;
00111 }
00112
00113 if (g->groups)
00114 {
00115 for (i=0; i<g->ngroups; i++)
00116 {
00117 member_g = &g->groups[i];
00118 if (member_g)
00119 {
00120 H5Group_dtor(member_g);
00121
00122 }
00123 }
00124 free (g->groups);
00125 }
00126
00127 if (g->datasets)
00128 {
00129 for (i=0; i<g->ndatasets; i++)
00130 {
00131 member_d = &g->datasets[i];
00132 if (member_d)
00133 {
00134 H5Dataset_dtor(member_d);
00135
00136 }
00137 }
00138 free (g->datasets);
00139 }
00140 }
00141
00142 void H5Datatype_dtor(H5Datatype* t)
00143 {
00144 int i=0;
00145
00146 assert(t);
00147
00148 if (t->mtypes)
00149 {
00150 free (t->mtypes);
00151 t->mtypes = NULL;
00152 }
00153
00154 if (t->mnames)
00155 {
00156 for (i=0; i<t->nmembers; i++)
00157 {
00158 if (t->mnames[i])
00159 {
00160 free (t->mnames[i]);
00161 t->mnames[i] = NULL;
00162 }
00163 }
00164
00165 free (t->mnames);
00166 t->mnames = NULL;
00167 }
00168 }
00169
00170 void H5Dataset_freeBuffer(void *value, H5Dataspace space, H5Datatype type,
00171 int nvalue)
00172 {
00173 int i=0;
00174 char ** strs=0;
00175
00176 if (value)
00177 {
00178 if ( ( H5DATATYPE_VLEN == type.tclass )
00179 || ( H5DATATYPE_COMPOUND == type.tclass )
00180 || ( H5DATATYPE_STRING == type.tclass )
00181 )
00182 {
00183 strs = (char **)value;
00184 for (i=0; i<nvalue; i++)
00185 {
00186 if (strs[i]) free(strs[i]);
00187 }
00188 }
00189
00190 free (value);
00191 }
00192 }
00193
00194