summaryrefslogtreecommitdiff
path: root/plugins/Dbx_mdb/src/commonheaders.h
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2015-01-14 14:29:52 +0000
committerGeorge Hazan <george.hazan@gmail.com>2015-01-14 14:29:52 +0000
commite37f12dec252a78cdf94d31ccc87ce37c1436a1f (patch)
tree09d50f93a1f260e054908c775264819e82a0db48 /plugins/Dbx_mdb/src/commonheaders.h
parent5f4a6f00c20468e6adc3a7bf691eccef55d2324c (diff)
txn_ptr & cursor_ptr classes
git-svn-id: http://svn.miranda-ng.org/main/trunk@11853 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Dbx_mdb/src/commonheaders.h')
-rw-r--r--plugins/Dbx_mdb/src/commonheaders.h48
1 files changed, 33 insertions, 15 deletions
diff --git a/plugins/Dbx_mdb/src/commonheaders.h b/plugins/Dbx_mdb/src/commonheaders.h
index 7b0c0bc0ad..3daf109bef 100644
--- a/plugins/Dbx_mdb/src/commonheaders.h
+++ b/plugins/Dbx_mdb/src/commonheaders.h
@@ -56,38 +56,56 @@ extern "C"
extern HINSTANCE g_hInst;
extern LIST<CDbxMdb> g_Dbs;
-class txn_lock
+class txn_ptr
{
- MDB_txn *txn;
- MDB_env *env;
+ MDB_txn *m_txn;
public:
- __forceinline txn_lock(MDB_env *pEnv) :
- env(pEnv)
- {
- mdb_txn_begin(pEnv, NULL, 0, &txn);
+ __forceinline txn_ptr(MDB_env *pEnv, bool bReadOnly = false)
+ {
+ mdb_txn_begin(pEnv, NULL, (bReadOnly) ? MDB_RDONLY : 0, &m_txn);
}
- __forceinline ~txn_lock()
+ __forceinline ~txn_ptr()
{
- if (txn)
- mdb_txn_abort(txn);
+ if (m_txn)
+ mdb_txn_abort(m_txn);
}
- __forceinline operator MDB_txn*() const { return txn; }
+ __forceinline operator MDB_txn*() const { return m_txn; }
__forceinline bool commit()
{
- bool bRes = (mdb_txn_commit(txn) != MDB_MAP_FULL);
- txn = NULL;
+ bool bRes = (mdb_txn_commit(m_txn) != MDB_MAP_FULL);
+ m_txn = NULL;
return bRes;
}
__forceinline void abort()
{
- mdb_txn_abort(txn);
- txn = NULL;
+ mdb_txn_abort(m_txn);
+ m_txn = NULL;
+ }
+};
+
+class cursor_ptr
+{
+ MDB_cursor *m_cursor;
+
+public:
+ __forceinline cursor_ptr(const txn_ptr &_txn, MDB_dbi _dbi)
+ {
+ if (mdb_cursor_open(_txn, _dbi, &m_cursor) != MDB_SUCCESS)
+ m_cursor = NULL;
+ }
+
+ __forceinline ~cursor_ptr()
+ {
+ if (m_cursor)
+ mdb_cursor_close(m_cursor);
}
+
+ __forceinline operator MDB_cursor*() const { return m_cursor; }
};
#ifdef __GNUC__