diff --git a/cxx/Makefile b/cxx/Makefile index fba14e46798..eafb5037334 100644 --- a/cxx/Makefile +++ b/cxx/Makefile @@ -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) diff --git a/cxx/db.cpp b/cxx/db.cpp index e242703fd89..5bb4cf47d6a 100644 --- a/cxx/db.cpp +++ b/cxx/db.cpp @@ -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; +} diff --git a/cxx/db_cxx.h b/cxx/db_cxx.h index 026162a0ef5..9bcd8db2d51 100644 --- a/cxx/db_cxx.h +++ b/cxx/db_cxx.h @@ -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; }; diff --git a/cxx/dbc.cpp b/cxx/dbc.cpp new file mode 100644 index 00000000000..f49db31c9f5 --- /dev/null +++ b/cxx/dbc.cpp @@ -0,0 +1,13 @@ +#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; +} diff --git a/cxx/dbenv.cpp b/cxx/dbenv.cpp new file mode 100644 index 00000000000..eb7a5fc56c3 --- /dev/null +++ b/cxx/dbenv.cpp @@ -0,0 +1,49 @@ +#include +#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; +} diff --git a/cxx/dbtxn.cpp b/cxx/dbtxn.cpp new file mode 100644 index 00000000000..894b05ee767 --- /dev/null +++ b/cxx/dbtxn.cpp @@ -0,0 +1,7 @@ +#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; +} diff --git a/cxx/test1.cpp b/cxx/tests/test1.cpp similarity index 100% rename from cxx/test1.cpp rename to cxx/tests/test1.cpp diff --git a/cxx/txn.cpp b/cxx/txn.cpp new file mode 100644 index 00000000000..8ce192e3fc5 --- /dev/null +++ b/cxx/txn.cpp @@ -0,0 +1,9 @@ +#include +#include "db_cxx.h" + +DbTxn::DbTxn(DB_TXN *txn) + : the_txn(txn) +{ + txn->api_internal = this; +} + diff --git a/db-benchmark-test-cxx/Makefile b/db-benchmark-test-cxx/Makefile index 73250559998..17a62e932f7 100644 --- a/db-benchmark-test-cxx/Makefile +++ b/db-benchmark-test-cxx/Makefile @@ -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