summaryrefslogtreecommitdiffstats
path: root/common/storage_lmdb.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2014-12-24 02:15:41 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2014-12-24 02:15:41 +0100
commitc83c2ef64b5a1e4b1dc0102df36687caebb96ff0 (patch)
tree7d0567996c02e9a1ea5909abbab5f68401fd4771 /common/storage_lmdb.cpp
parentd80ff84c28c0be626c1df4528741cddf5a55f547 (diff)
downloadsink-c83c2ef64b5a1e4b1dc0102df36687caebb96ff0.tar.gz
sink-c83c2ef64b5a1e4b1dc0102df36687caebb96ff0.zip
unifying buffer, and a better way to implement domain object adapters.
Diffstat (limited to 'common/storage_lmdb.cpp')
-rw-r--r--common/storage_lmdb.cpp25
1 files changed, 15 insertions, 10 deletions
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()
194 d->transaction = 0; 194 d->transaction = 0;
195} 195}
196 196
197bool Storage::write(const char *key, size_t keySize, const char *value, size_t valueSize) 197bool Storage::write(void const *keyPtr, size_t keySize, void const *valuePtr, size_t valueSize)
198{
199 return write(std::string(key, keySize), std::string(value, valueSize));
200}
201
202bool Storage::write(const std::string &sKey, const std::string &sValue)
203{ 198{
204 if (!d->env) { 199 if (!d->env) {
205 return false; 200 return false;
206 } 201 }
207 202
203 if (d->mode == ReadOnly) {
204 std::cerr << "tried to write in read-only mode." << std::endl;
205 return false;
206 }
207
208 const bool implicitTransaction = !d->transaction || d->readTransaction; 208 const bool implicitTransaction = !d->transaction || d->readTransaction;
209 if (implicitTransaction) { 209 if (implicitTransaction) {
210 // TODO: if this fails, still try the write below? 210 // TODO: if this fails, still try the write below?
@@ -215,10 +215,10 @@ bool Storage::write(const std::string &sKey, const std::string &sValue)
215 215
216 int rc; 216 int rc;
217 MDB_val key, data; 217 MDB_val key, data;
218 key.mv_size = sKey.size(); 218 key.mv_size = keySize;
219 key.mv_data = (void*)sKey.data(); 219 key.mv_data = const_cast<void*>(keyPtr);
220 data.mv_size = sValue.size(); 220 data.mv_size = valueSize;
221 data.mv_data = (void*)sValue.data(); 221 data.mv_data = const_cast<void*>(valuePtr);
222 rc = mdb_put(d->transaction, d->dbi, &key, &data, 0); 222 rc = mdb_put(d->transaction, d->dbi, &key, &data, 0);
223 223
224 if (rc) { 224 if (rc) {
@@ -236,6 +236,11 @@ bool Storage::write(const std::string &sKey, const std::string &sValue)
236 return !rc; 236 return !rc;
237} 237}
238 238
239bool Storage::write(const std::string &sKey, const std::string &sValue)
240{
241 return write(const_cast<char*>(sKey.data()), sKey.size(), const_cast<char*>(sValue.data()), sValue.size());
242}
243
239void Storage::read(const std::string &sKey, 244void Storage::read(const std::string &sKey,
240 const std::function<bool(const std::string &value)> &resultHandler, 245 const std::function<bool(const std::string &value)> &resultHandler,
241 const std::function<void(const Storage::Error &error)> &errorHandler) 246 const std::function<void(const Storage::Error &error)> &errorHandler)