HDF5 Extras
0.0.1
Convenience Functions for using HDF5 Better
|
The library is implemented in several layers, as described in the previous chapter. The base library is used by all the others, containing functions to deal with the following major functions:
These are described in the following sections.
Strings are notorious for causing trouble in C code. Instead of using them, we choose to use a library that implements a safer string. This library is called the Better String Library, and is written by Paul Hsieh. It is available from: http://bstring.sourceforge.net. The basic idea is to have the string and metadata about the string in a struct
, and the struct
is used in the code, not the string, as shown in the code fragment below:
Note that the string part of this struct
is named data
, while the length of the valid data in the string is stored in slen
, and the number of bytes allocated to data is stored in mlen
. As needed, the string part of this struct is allocated, reallocated and deallocated, so that there are fewer errors by the programmer. Note that a bstring
must be initialized before most of the bstring
functions can operate on it sensibly. The typical usage of this new datatype is supported by many functions, a few of which are shown below:
bstring str1
bstring str1 = bfromcstr("")
bdata(bstring b)
bassigncstr(b, "")
bassignformat(b, "format", variables, ...)
bchar(b, index)
name = bstrcpy(filename)
bdestroy(b)
blength(b)
bassign(a,b)
binstr(b, pos, c)
bconcat(b, c)
bsstatic("blah")
We have an implementation of malloc/free called GMalloc/GFree that is used everywhere in our library. This currently is a thin layer on top of the C standard malloc/free. THe basic idea here is to not free null pointers, and to have stubs that can be rewritten later if needed, without having to rewrite all of our existing code.
Other things that are available in the base.h
file are: definitions for TRUE
and FALSE
, macros MIN
, MAX
, ABS
, bstring-comparisons: EQUAL
, and EQUALN
, block-copy macros: ByteCopy
and BstringCopy
, and a few other constants and typedefs.
next: HDF5 Abstraction Library