-
Notifications
You must be signed in to change notification settings - Fork 1
/
GenericDatabaseObject.h
62 lines (49 loc) · 1.46 KB
/
GenericDatabaseObject.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
* File: GenericDatabaseObject.h
* Author: nyoknvk1
*
* Created on 18. Februar 2014, 14:25
*/
#pragma once
#include <functional> // for reference_wrapper
#include <string> // for string
#include "SqliteDatabase.h" // for SqliteDatabase
#include "TabRow.h" // for TabRow
namespace SqliteOverlay
{
template<class DB_CLASS = SqliteDatabase>
class GenericDatabaseObject
{
public:
using DatabaseClass = DB_CLASS;
GenericDatabaseObject (const DB_CLASS& _db, const std::string& _tabName, int _id)
: db(_db), row(TabRow(_db, _tabName, _id))
{
static_assert (std::is_base_of_v<SqliteDatabase, DB_CLASS>, "DB classes must be derived from SqliteDatabase");
}
GenericDatabaseObject (const DB_CLASS& _db, const TabRow& _row)
:db(_db), row(_row)
{
static_assert (std::is_base_of_v<SqliteDatabase, DB_CLASS>, "DB classes must be derived from SqliteDatabase");
}
inline int getId () const
{
return row.id();
}
inline bool operator== (const GenericDatabaseObject& other) const
{
return (other.row == row);
}
inline bool operator!= (const GenericDatabaseObject& other) const
{
return (!(this->operator == (other)));
}
const DatabaseClass& getDatabaseHandle() const
{
return db.get();
}
protected:
std::reference_wrapper<const DB_CLASS> db;
TabRow row;
};
}