From c83c2ef64b5a1e4b1dc0102df36687caebb96ff0 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 24 Dec 2014 02:15:41 +0100 Subject: unifying buffer, and a better way to implement domain object adapters. --- common/storage_lmdb.cpp | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'common/storage_lmdb.cpp') diff --git a/common/storage_lmdb.cpp b/common/storage_lmdb.cpp index eeb0045..42e3d33 100644 --- a/common/storage_lmdb.cpp +++ b/common/storage_lmdb.cpp @@ -194,17 +194,17 @@ void Storage::abortTransaction() d->transaction = 0; } -bool Storage::write(const char *key, size_t keySize, const char *value, size_t valueSize) -{ - return write(std::string(key, keySize), std::string(value, valueSize)); -} - -bool Storage::write(const std::string &sKey, const std::string &sValue) +bool Storage::write(void const *keyPtr, size_t keySize, void const *valuePtr, size_t valueSize) { if (!d->env) { return false; } + if (d->mode == ReadOnly) { + std::cerr << "tried to write in read-only mode." << std::endl; + return false; + } + const bool implicitTransaction = !d->transaction || d->readTransaction; if (implicitTransaction) { // TODO: if this fails, still try the write below? @@ -215,10 +215,10 @@ bool Storage::write(const std::string &sKey, const std::string &sValue) int rc; MDB_val key, data; - key.mv_size = sKey.size(); - key.mv_data = (void*)sKey.data(); - data.mv_size = sValue.size(); - data.mv_data = (void*)sValue.data(); + key.mv_size = keySize; + key.mv_data = const_cast(keyPtr); + data.mv_size = valueSize; + data.mv_data = const_cast(valuePtr); rc = mdb_put(d->transaction, d->dbi, &key, &data, 0); if (rc) { @@ -236,6 +236,11 @@ bool Storage::write(const std::string &sKey, const std::string &sValue) return !rc; } +bool Storage::write(const std::string &sKey, const std::string &sValue) +{ + return write(const_cast(sKey.data()), sKey.size(), const_cast(sValue.data()), sValue.size()); +} + void Storage::read(const std::string &sKey, const std::function &resultHandler, const std::function &errorHandler) -- cgit v1.2.3