HamsterDB_Ada is a library project which provides Ada bindings for the HamsterDB project.
How do I download it?
git clone git://github.com/anthony-arnold/HamsterDB_Ada
How do I build it?
make install. This should build a library based off of
the provided Ada interface and copy the relevant files to your system.
The installed library has the same version number as the HamsterDB
it's generated from.
How is it used?
In an Ada project, you will have access to the
HamsterDB package. This
provides all of the functions and most of the types, typedefs and macros
For the most part, the Ada interface is the same as the C interface.
However, empty structures have not been converted. This means that those functions
which take an opaque pointer in C, take a
System.Address in Ada.
Also, all functions have had the
ham_ prefix removed, with one notable
ham_new. Ada simply won't support a function named
ham_new is left as-is.
Here's an example, lifted from the HamsterDB tutorial and converted to Ada:
with HamsterDB; with Ada.Text_IO; use Ada.Text_IO; with System; with Interfaces.C; use Interfaces.C; with Interfaces.C.Strings; use Interfaces.C.Strings; procedure HDM is db : System.Address := System.Null_Address; st : HamsterDB.status_t; name : chars_ptr := New_String("test.db"); begin st := HamsterDB.Ham_New(db'Address); if st /= HamsterDB.HAM_SUCCESS then Put_Line("ham_new failed: " & Value(HamsterDB.StrError(st))); else st := HamsterDB.Create_Ex(db, name, 0, 0664, null); if st /= HamsterDB.HAM_SUCCESS then Put_Line("ham_create_ex failed: " & Value(HamsterDB.StrError(st))); end if; st := HamsterDB.Delete(db); if st /= HamsterDB.HAM_SUCCESS then Put_Line("ham_delete failed: " & Value(HamsterDB.StrError(st))); end if; end if; Free(name); end HDM;
To compile, you need to link to both
What's left to do?
A few things:
- Refactor the transformation script. It's a bit spagetti at the moment.
- Provide documentation; it's not really necessary, but would be nice to have.
- Make the build/install system more portable.
If you want to generate your own Ada interface for HamsterDB for whatever reason, (e.g. linking to a different version of HamsterDB), then there's a pretty easy way.
- CHECK THE GENERATED FILE IN
- Alter the version number in
It's really, really important that you check the generated Ada spec.
Generating it from a different version of HamsterDB than the one provided
can result in some weird and incorrect code. You may have to alter the
transform.sh script, which is responsible for taking the raw output from
and making it "better".