git » nmdb » commit a20c796

Implement incr in D bindings.

author Alberto Bertogli
2007-09-01 23:42:13 UTC
committer Alberto Bertogli
2007-09-01 23:42:13 UTC
parent 4bc4501c0be8bd7a781191fdf62084862a76650c

Implement incr in D bindings.

Signed-off-by: Alberto Bertogli <albertito@gmail.com>

bindings/d/nmdb.d +31 -0
bindings/d/nmdb_ll.d +5 -0

diff --git a/bindings/d/nmdb.d b/bindings/d/nmdb.d
index 5915197..9c96062 100644
--- a/bindings/d/nmdb.d
+++ b/bindings/d/nmdb.d
@@ -165,6 +165,21 @@ class DB
 		return res;
 	}
 
+	private int do_incr(char[] key, long increment, int mode)
+	{
+		ubyte* k = cast(ubyte *) key.ptr;
+		int res = 0;
+
+		if (mode == MODE_NORMAL || mode == MODE_SYNC) {
+			res = nmdb_incr(db, k, key.length, increment);
+		} else if (mode == MODE_CACHE) {
+			res = nmdb_cache_incr(db, k, key.length, increment);
+		} else {
+			throw new Exception("Invalid mode");
+		}
+		return res;
+	}
+
 
 	char[] get(char[] key)
 	{
@@ -240,6 +255,22 @@ class DB
 	}
 
 
+	int incr(char[] key, long increment)
+	{
+		return do_incr(key, increment, mode);
+	}
+
+	int incr_normal(char[] key, long increment)
+	{
+		return do_incr(key, increment, MODE_NORMAL);
+	}
+
+	int cache_incr(char[] key, long increment)
+	{
+		return do_incr(key, increment, MODE_CACHE);
+	}
+
+
 	char[] opIndex(char[] key)
 	{
 		return get(key);
diff --git a/bindings/d/nmdb_ll.d b/bindings/d/nmdb_ll.d
index da1fcc9..beb28d3 100644
--- a/bindings/d/nmdb_ll.d
+++ b/bindings/d/nmdb_ll.d
@@ -64,3 +64,8 @@ extern (C) int nmdb_cas(nmdb_t *db, ubyte *key, size_t ksize,
 extern (C) int nmdb_cache_cas(nmdb_t *db, ubyte *key, size_t ksize,
 		ubyte *oldval, size_t ovsize, ubyte *newval, size_t nvsize);
 
+extern (C) int nmdb_incr(nmdb_t *db, ubyte *key, size_t ksize,
+		long increment);
+extern (C) int nmdb_cache_incr(nmdb_t *db, ubyte *key, size_t ksize,
+		long increment);
+