Skip to content

Commit

Permalink
Added more function to low level API's. WIP TokyoCabinet API.
Browse files Browse the repository at this point in the history
  • Loading branch information
jvelilla committed May 29, 2010
1 parent 154bdca commit 39de8e3
Show file tree
Hide file tree
Showing 5 changed files with 625 additions and 4 deletions.
171 changes: 169 additions & 2 deletions library/adb_api.e
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ note
class
ADB_API
inherit
DBM

TC_ADB_API

create
Expand All @@ -23,6 +21,170 @@ feature {NONE} -- Initialization
is_open := False
has_error := False
end

feature -- Access

is_open: BOOLEAN
-- is the database open?


is_open_mode_reader : BOOLEAN
-- is the database open in a reader mode?
require
is_database_open : is_open
do
Result := is_open_mode_reader_implementation
end

is_open_mode_writer : BOOLEAN
-- is the database open in a writer mode?
require
is_database_open : is_open
do
Result := not is_open_mode_reader
end

error_description: STRING
-- Textual description of error
require
has_error: has_error
do
Result := full_message_implementation
ensure
result_exists: Result /= Void
result_not_empty: not Result.is_empty
end

get_string (a_key: STRING): STRING
-- Retrieve a string record by `a_key'
require
is_open_database: is_open
is_valid_key: a_key /= Void and (not a_key.is_empty)
local
c_key: C_STRING
r: POINTER
do
create c_key.make (a_key)
r := get_string_implementation (c_key.item)
if r /= default_pointer then
create Result.make_from_c (r)
end
end

records_number: NATURAL_64
--Get the number of records.
require
is_open_database: is_open
do
Result := records_number_implementation
end

file_size: NATURAL_64
-- Get the size of the database file.
require
is_open_database: is_open
do
Result := file_size_implementation
end


feature -- Change Element

put_string (a_key: STRING; a_value: STRING)
-- Is used in order to store a string record into a database object.
require
is_open_database_writer: is_open_mode_writer
is_valid_key: a_key /= Void and (not a_key.is_empty)
is_valid_value: a_value /= Void and (not a_value.is_empty)
local
c_key: C_STRING
c_value: C_STRING
l_b: BOOLEAN
do
create c_key.make (a_key)
create c_value.make (a_value)
l_b := put_string_implementation (c_key.item, c_value.item)
if not l_b then
has_error := True
end
end

put_keep_string (a_key: STRING; a_value: STRING)
-- Is used in order to store a new string record into a database object.
-- If a record with the same key exists in the database, this function has no effect.
require
is_open_database_writer: is_open_mode_writer
is_valid_key: a_key /= Void and (not a_key.is_empty)
is_valid_value: a_value /= Void and (not a_value.is_empty)
local
c_key: C_STRING
c_value: C_STRING
l_b: BOOLEAN
do
create c_key.make (a_key)
create c_value.make (a_value)
l_b := put_keep_string_implementation (c_key.item, c_value.item)
if not l_b then
has_error := True
end
end

out_string (a_key: STRING)
-- remove a record by a key `a_key'
require
is_open_database_writer: is_open_mode_writer
is_valid_key: a_key /= Void and (not a_key.is_empty)
local
c_key: C_STRING
l_b: BOOLEAN
do
create c_key.make (a_key)
l_b := out_string_implementation (c_key.item)
end

feature -- Iterator

iterator_init
-- Initialize the iterator
require
is_open_database: is_open
local
l_b: BOOLEAN
do
l_b := iterator_init_implementation
if not l_b then
has_error := True
end
end

iterator_next_string: STRING
-- get the next key of the iterator
require
is_open_database: is_open
local
r: POINTER
do
r := iterator_next_string_implementation
if r /= default_pointer then
create Result.make_from_c (r)
end
end

feature -- Status Report

has_error: BOOLEAN
-- Did an error occur?

feature -- Status Settings

clean_error is
-- Reset the last error.
do
has_error := False
ensure
no_error: not has_error
end

feature -- Open Database

open (a_name : STRING)
Expand Down Expand Up @@ -187,4 +349,9 @@ feature {NONE} -- Implementation

invariant
abstract_database_created: adb /= default_pointer
non_empty_description: has_error implies (error_description /= Void and (not error_description.is_empty))
not_open_as_reader_and_writer : is_open implies (not (is_open_mode_reader and is_open_mode_writer))
open_as_reader : (is_open and then is_open_mode_reader) implies (not is_open_mode_writer)
open_as_writer : (is_open and then is_open_mode_writer) implies (not is_open_mode_reader)

end
2 changes: 1 addition & 1 deletion library/tdb_api.e
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ feature -- Close and Delete

feature -- Database Control

copy_db (a_path : STRING)
db_copy (a_path : STRING)
-- Copy the database file of a table database object.
-- `path' specifies the path of the destination file. If it begins with `@', the trailing
-- substring is executed as a command line.
Expand Down
1 change: 0 additions & 1 deletion library/tokyocabinet/tc_adb_api.e
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ note

deferred class
TC_ADB_API
inherit ANY undefine is_equal, copy end

feature {} -- Create an Abstract Database Object

Expand Down
95 changes: 95 additions & 0 deletions library/tokyocabinet/tc_bdb_api.e
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,101 @@ feature -- Retrieve Records
end



tcbdbrange (bdb : POINTER; a_bkbuf : POINTER; a_bksiz : INTEGER; a_binc : BOOLEAN; an_ekbuf : POINTER; an_eksiz : INTEGER; an_einc : INTEGER; a_max : INTEGER) : POINTER
--/* Get keys of ranged records in a B+ tree database object.
-- `bdb' specifies the B+ tree database object.
-- `bkbuf' specifies the pointer to the region of the key of the beginning border. If it is
-- `NULL', the first record is specified.
-- `bksiz' specifies the size of the region of the beginning key.
-- `binc' specifies whether the beginning border is inclusive or not.
-- `ekbuf' specifies the pointer to the region of the key of the ending border. If it is `NULL',
-- the last record is specified.
-- `eksiz' specifies the size of the region of the ending key.
-- `einc' specifies whether the ending border is inclusive or not.
-- `max' specifies the maximum number of keys to be fetched. If it is negative, no limit is
-- specified.
-- The return value is a list object of the keys of the corresponding records. This function
-- does never fail. It returns an empty list even if no record corresponds.
-- Because the object of the return value is created with the function `tclistnew', it should
-- be deleted with the function `tclistdel' when it is no longer in use. */
--TCLIST *tcbdbrange(TCBDB *bdb, const void *bkbuf, int bksiz, bool binc,
-- const void *ekbuf, int eksiz, bool einc, int max);
external
"C inline use <tcbdb.h>"
alias
"{
tcbdbrange((TCBDB *)$bdb, (const void *)$a_bkbuf, (int) $a_bksiz, (bool) $a_binc,
(const void *)$an_ekbuf, (int) $an_eksiz, (bool) $an_einc, (int) $a_max)
}"
end


tcbdbrange2 (bdb : POINTER; a_bkstr : POINTER; a_binc : BOOLEAN; an_ekstr : POINTER; an_einc : INTEGER; a_max : INTEGER) : POINTER
--/* Get string keys of ranged records in a B+ tree database object.
-- `bdb' specifies the B+ tree database object.
-- `bkstr' specifies the string of the key of the beginning border. If it is `NULL', the first
-- record is specified.
-- `binc' specifies whether the beginning border is inclusive or not.
-- `ekstr' specifies the string of the key of the ending border. If it is `NULL', the last
-- record is specified.
-- `einc' specifies whether the ending border is inclusive or not.
-- `max' specifies the maximum number of keys to be fetched. If it is negative, no limit is
-- specified.
-- The return value is a list object of the keys of the corresponding records. This function
-- does never fail. It returns an empty list even if no record corresponds.
-- Because the object of the return value is created with the function `tclistnew', it should
-- be deleted with the function `tclistdel' when it is no longer in use. */
--TCLIST *tcbdbrange2(TCBDB *bdb, const char *bkstr, bool binc,
-- const char *ekstr, bool einc, int max);
external
"C inline use <tcbdb.h>"
alias
"{
tcbdbrange2((TCBDB *)$bdb, (const char *)$a_bkstr, (bool) $a_binc,
(const char *)$an_ekstr, (bool) $an_einc, (int) $a_max)
}"
end


tcbdbfwmkeys (bdb : POINTER; a_pbuf : POINTER; a_psiz : INTEGER; a_max : INTEGER) : POINTER
--/* Get forward matching keys in a B+ tree database object.
-- `bdb' specifies the B+ tree database object.
-- `pbuf' specifies the pointer to the region of the prefix.
-- `psiz' specifies the size of the region of the prefix.
-- `max' specifies the maximum number of keys to be fetched. If it is negative, no limit is
-- specified.
-- The return value is a list object of the corresponding keys. This function does never fail.
-- It returns an empty list even if no key corresponds.
-- Because the object of the return value is created with the function `tclistnew', it should be
-- deleted with the function `tclistdel' when it is no longer in use. */
--TCLIST *tcbdbfwmkeys(TCBDB *bdb, const void *pbuf, int psiz, int max);
external
"C inline use <tcbdb.h>"
alias
"{
tcbdbfwmkeys((TCBDB *)$bdb, (const void *)$a_pbuf, (int) $a_psiz, (int) $a_max)
}"
end

tcbdbfwmkeys2 (bdb : POINTER; a_pstr : POINTER; a_max : INTEGER)
--/* Get forward matching string keys in a B+ tree database object.
-- `bdb' specifies the B+ tree database object.
-- `pstr' specifies the string of the prefix.
-- `max' specifies the maximum number of keys to be fetched. If it is negative, no limit is
-- specified.
-- The return value is a list object of the corresponding keys. This function does never fail.
-- It returns an empty list even if no key corresponds.
-- Because the object of the return value is created with the function `tclistnew', it should be
-- deleted with the function `tclistdel' when it is no longer in use. */
--TCLIST *tcbdbfwmkeys2(TCBDB *bdb, const char *pstr, int max);
external
"C inline use <tcbdb.h>"
alias
"{
tcbdbfwmkeys2((TCBDB *)$bdb, (const char *)$a_pstr, (int) $a_max)
}"
end
feature -- Error Messages

tcbdberrmsg (an_ecode : INTEGER) : POINTER
Expand Down
Loading

0 comments on commit 39de8e3

Please sign in to comment.