Commit 8bb4423f authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul

We have a basic C++ interface. I'm going to call this finished, until we find...

We have a basic C++ interface.  I'm going to call this finished, until we find out that more is needed.  Fixes #197.

git-svn-id: file:///svn/tokudb@1214 c7de825b-a66e-492c-adef-691d508d4ae1
parent 7d67f3b6
......@@ -4,7 +4,15 @@ CC = c++
LDFLAGS = -lz
SRCS = $(wildcard *.cpp)
OBJS = $(patsubst %.cpp, %.o, $(SRCS))
default: $(OBJS)
LIBNAME = libtdb_cxx
default: install
install: $(LIBNAME).a
cp $< ../lib/
cp db_cxx.h ../include/
$(OBJS): db_cxx.h
test1: test1.o dbt.o db.o dbenv.o ../lib/libdb.a
$(LIBNAME).a: $(OBJS)
$(AR) rv $@ $(OBJS)
......@@ -58,4 +58,8 @@ int Db::cursor(DbTxn *txn, Dbc **cursorp, u_int32_t flags) {
int ret = the_db->cursor(the_db, txn->get_DB_TXN(), (DBC**)cursorp, flags);
return ret;
}
int Db::set_pagesize(u_int32_t size) {
int ret = the_db->set_pagesize(the_db, size);
return ret;
}
......@@ -59,7 +59,7 @@ class Db {
int put(DbTxn *, Dbt *, Dbt *, u_int32_t);
int get_flags(u_int32_t *);
int set_flags(u_int32_t);
int set_pagesize(u_int32_t);
private:
DB *the_db;
......@@ -79,6 +79,11 @@ class DbEnv {
/* C++ analogues of the C functions. */
int close(u_int32_t);
int open(const char *, u_int32_t, int);
int set_cachesize(u_int32_t, u_int32_t, int);
int set_lk_max(u_int32_t);
int txn_begin(DbTxn *, DbTxn **, u_int32_t);
private:
DB_ENV *the_env;
......@@ -89,11 +94,15 @@ class DbEnv {
class DbTxn {
public:
int commit (u_int32_t /*flags*/);
DB_TXN *get_DB_TXN()
{
if (this==0) return 0;
return the_txn;
}
DbTxn(DB_TXN*);
private:
DB_TXN *the_txn;
};
......
#include "db_cxx.h"
int Dbc::close (void) {
DBC *dbc = this;
int ret = dbc->c_close(dbc);
return ret;
}
int Dbc::get(Dbt* key, Dbt *data, u_int32_t flags) {
DBC *dbc = this;
int ret = dbc->c_get(dbc, key, data, flags);
return ret;
}
#include <assert.h>
#include "db_cxx.h"
DbEnv::DbEnv (u_int32_t flags) {
int ret = db_env_create(&the_env, flags & ~DB_CXX_NO_EXCEPTIONS);
assert(ret==0); // should do an error.
the_env->api1_internal = this;
}
DbEnv::DbEnv(DB_ENV *env, u_int32_t flags) {
the_env = env;
if (env == 0) {
DB_ENV *new_env;
int ret = db_env_create(&new_env, flags & ~DB_CXX_NO_EXCEPTIONS);
assert(ret==0); // should do an error.
the_env = new_env;
}
the_env->api1_internal = this;
}
int DbEnv::close(u_int32_t flags) {
int ret = the_env->close(the_env, flags);
the_env = 0; /* get rid of the env ref, so we don't touch it (even if we failed.) */
return ret;
}
int DbEnv::open(const char *home, u_int32_t flags, int mode) {
int ret = the_env->open(the_env, home, flags, mode);
return ret;
}
int DbEnv::set_cachesize(u_int32_t gbytes, u_int32_t bytes, int ncache) {
int ret = the_env->set_cachesize(the_env, gbytes, bytes, ncache);
return ret;
}
int DbEnv::set_lk_max(u_int32_t flags) {
int ret = the_env->set_lk_max(the_env, flags);
return ret;
}
int DbEnv::txn_begin(DbTxn *parenttxn, DbTxn **txnp, u_int32_t flags) {
DB_TXN *txn;
int ret = the_env->txn_begin(the_env, parenttxn->get_DB_TXN(), &txn, flags);
if (ret==0) {
*txnp = new DbTxn(txn);
}
return ret;
}
#include "db_cxx.h"
int DbTxn::commit (u_int32_t flags) {
DB_TXN *txn = get_DB_TXN();
int ret = txn->commit(txn, flags);
return ret;
}
#include <assert.h>
#include "db_cxx.h"
DbTxn::DbTxn(DB_TXN *txn)
: the_txn(txn)
{
txn->api_internal = this;
}
......@@ -26,7 +26,10 @@ default: $(TARGETS)
clean:
rm -rf $(TARGETS) $(BENCHDBS)
db-benchmark-test-tokudb: ../lib/libtdb_cxx.a
db-benchmark-test-tokudb: db-benchmark-test.cpp
$(CXX) $(CXXFLAGS) -I../include -L../lib -ldb -Wl,-rpath,$(PWD)/../lib $< -o $@ -DDIRSUF=tokudb
# $(CXX) $(CXXFLAGS) -I../include $< -o $@ -DDIRSUF=tokudb ../lib/libdb.a ../lib/libtdb_cxx.a -lz
$(CXX) $(CXXFLAGS) -I../include -L../lib -Wl,-rpath,$(PWD)/../lib $< -o $@ -ldb -ltdb_cxx -DDIRSUF=tokudb
db-benchmark-test-bdb: db-benchmark-test.cpp
$(CXX) $(CXXFLAGS) $(BDB_CPPFLAGS) $(BDB_LDFLAGS) $< -o $@ -DDIRSUF=bdb
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment