namespace cleanup, reennable support for c++2011

This commit is contained in:
bert hubert 2018-12-10 22:08:49 +01:00
parent 34f8c2188c
commit 3dd2f703db
9 changed files with 29 additions and 27 deletions

View File

@ -3,10 +3,11 @@
#INCLUDES=-Ilmdb-LMDB_0.9.22/libraries/liblmdb
LIBS=-llmdb
CXXFLAGS:=-std=gnu++17 -Wall -O2 -MMD -MP -ggdb -pthread $(INCLUDES) # -fsanitize=address -fno-omit-frame-pointer
CXXVERSIONFLAG= -std=gnu++11
CXXFLAGS:= $(CXXVERSIONFLAG) -Wall -O2 -MMD -MP -ggdb -pthread $(INCLUDES) # -fsanitize=address -fno-omit-frame-pointer
CFLAGS:= -Wall -O2 -MMD -MP -ggdb
CXXVERSIONFLAG= -std=gnu++17
PROGRAMS = lmdb-test basic-example scale-example multi-example rel-example \
resize-example

View File

@ -1,7 +1,6 @@
# lmdb-safe
A safe modern & performant C++ wrapper of LMDB. For now briefly only
available for C++17, will support C++ 11 again soon. MIT licensed.
A safe modern & performant C++ wrapper of LMDB.
Requires C++17, or C++11 + Boost.
[LMDB](http://www.lmdb.tech/doc/index.html) is an outrageously fast
key/value store with semantics that make it highly interesting for many
applications. Of specific note, besides speed, is the full support for

View File

@ -1,4 +1,5 @@
#include "lmdb-safe.hh"
using namespace std;
void checkLMDB(MDBEnv* env, MDBDbi dbi)
{

View File

@ -6,6 +6,8 @@
#include <string.h>
#include <map>
using namespace std;
static string MDBError(int rc)
{
return mdb_strerror(rc);

View File

@ -1,3 +1,4 @@
#pragma once
#include <lmdb.h>
#include <iostream>
#include <fstream>
@ -9,7 +10,13 @@
#include <string.h>
#include <mutex>
using namespace std;
#if __cplusplus < 201703L
#include <boost/utility/string_view.hpp>
using boost::string_view;
#else
using std::string_view;
#endif
/* open issues:
*
@ -49,15 +56,6 @@ public:
~MDBEnv()
{
for(auto& a : d_RWtransactionsOut) {
if(a.second)
cout << "thread " <<a.first<<" had "<<a.second<<" RW transactions open"<<endl;
}
for(auto& a : d_ROtransactionsOut) {
if(a.second)
cout << "thread " <<a.first<<" had "<<a.second<<" RO transactions open"<<endl;
}
// Only a single thread may call this function. All transactions, databases, and cursors must already be closed before calling this function
mdb_env_close(d_env);
// but, elsewhere, docs say database handles do not need to be closed?
@ -105,7 +103,7 @@ struct MDBOutVal
{
T ret;
if(d_mdbval.mv_size != sizeof(T))
throw runtime_error("MDB data has wrong length for type");
throw std::runtime_error("MDB data has wrong length for type");
memcpy(&ret, d_mdbval.mv_data, sizeof(T));
return ret;
@ -120,7 +118,7 @@ struct MDBOutVal
{
T ret;
if(d_mdbval.mv_size != sizeof(T))
throw runtime_error("MDB data has wrong length for type");
throw std::runtime_error("MDB data has wrong length for type");
memcpy(&ret, d_mdbval.mv_data, sizeof(T));
return ret;
@ -134,9 +132,9 @@ template<> inline std::string MDBOutVal::get<std::string>()
return std::string((char*)d_mdbval.mv_data, d_mdbval.mv_size);
}
template<> inline std::string_view MDBOutVal::get<std::string_view>()
template<> inline string_view MDBOutVal::get<string_view>()
{
return std::string_view((char*)d_mdbval.mv_data, d_mdbval.mv_size);
return string_view((char*)d_mdbval.mv_data, d_mdbval.mv_size);
}
class MDBInVal
@ -169,7 +167,7 @@ public:
d_mdbval.mv_data = (void*)&v[0];
}
MDBInVal(const string& v)
MDBInVal(const std::string& v)
{
d_mdbval.mv_size = v.size();
d_mdbval.mv_data = (void*)&v[0];
@ -249,7 +247,7 @@ public:
MDBOutVal out;
int rc = get(dbi, key, out);
if(!rc)
val = out.get<std::string_view>();
val = out.get<string_view>();
return rc;
}
@ -429,7 +427,7 @@ public:
MDBOutVal out;
int rc = get(dbi, key, out);
if(!rc)
val = out.get<std::string_view>();
val = out.get<string_view>();
return rc;
}
@ -483,7 +481,6 @@ public:
}
MDBRWCursor(MDBRWCursor&& rhs)
{
cout<<"Got move constructed, this was: "<<(void*)&rhs<<", now: "<<(void*)this<<endl;
d_parent = rhs.d_parent;
d_cursor = rhs.d_cursor;
rhs.d_cursor=0;
@ -508,7 +505,7 @@ public:
{
int rc = mdb_cursor_get(d_cursor, &key.d_mdbval, &data.d_mdbval, op);
if(rc && rc != MDB_NOTFOUND)
throw std::runtime_error("mdb_cursor_get: " + string(mdb_strerror(rc)));
throw std::runtime_error("mdb_cursor_get: " + std::string(mdb_strerror(rc)));
return rc;
}

View File

@ -5,6 +5,7 @@
#include <unistd.h>
#include <thread>
#include <vector>
using namespace std;
static void closeTest()
{

View File

@ -1,4 +1,5 @@
#include "lmdb-safe.hh"
using namespace std;
int main()
{
@ -15,7 +16,7 @@ int main()
txn.put(dbi, "lmdb", "c");
txn.put(dbi, "mdb", "old name");
std::string_view v1;
string_view v1;
if(!txn.get(dbi, "mdb", v1)) {
cout<<v1<<endl;
}

View File

@ -2,7 +2,7 @@
#include <sstream>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
using namespace std;
struct Record
{

View File

@ -1,5 +1,5 @@
#include "lmdb-safe.hh"
using namespace std;
struct MDBVal
{