Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Ada bindings for HamsterDB

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 ali
Octocat-spinner-32 include
Octocat-spinner-32 lib
Octocat-spinner-32 obj
Octocat-spinner-32 support
Octocat-spinner-32 .gitignore
Octocat-spinner-32 LICENSE
Octocat-spinner-32 Makefile
Octocat-spinner-32 README.md
Octocat-spinner-32 hamsterdb_ada.gpr
Octocat-spinner-32 transform.sh
README.md

HamsterDB_Ada is a library project which provides Ada bindings for the HamsterDB project.

How do I download it?

Use git: git clone git://github.com/anthony-arnold/HamsterDB_Ada

How do I build it?

Simply make, then 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 available in ham/hamsterdb.h and ham/types.h.

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 exception: ham_new. Ada simply won't support a function named new, so 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 libhamsterdb and libhamsterdb_ada.

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.

Advanced Stuff

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.

  • make include
  • CHECK THE GENERATED FILE IN include
  • Alter the version number in support/hamsterdb_ada.gpr.in
  • make
  • make install

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 g++ and making it "better".

Something went wrong with that request. Please try again.