-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCol.h
66 lines (53 loc) · 1.43 KB
/
Col.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
63
64
65
66
#pragma once
#include "ColSchema.h"
#include "TypeMapping.h"
template<typename T>
struct Col : public ColSchema
{
Col(const string& colname, T& colvalue, const string& coldef)
:ColSchema(colname, coldef),ColValue(colvalue)
{
}
Col(const string& colname, T& colvalue)
:ColSchema(colname, TypeMapping::coltype(colvalue), false,false,false),ColValue(colvalue)
{
}
Col(const string& colname, T& colvalue,bool notnull, bool pk, bool autoinc)
:ColSchema(colname, TypeMapping::coltype(colvalue), notnull, pk, autoinc),ColValue(colvalue)
{
}
T& ColValue;
};
template<typename T> inline
bool ColIsNull(Col<T>& col)
{
return false;
}
template<> inline
bool ColIsNull(Col<string>& col)
{
return col.ColValue.empty();
}
template<class T> inline
Col<T> make_col(const char * name, T & t, const char* def)
{
return Col<T>(name, t, def);
}
template<class T> inline
Col<T> make_col(const char * name, T & t)
{
return Col<T>(name, t);
}
template<class T> inline
Col<T> make_col(const char * name, T & t, bool nonull, bool pk, bool ainc)
{
return Col<T>(name, t, nonull, pk, ainc);
}
#define ORM_COL(name) \
make_col(#name, name)
#define ORM_COLDEF(name, def) \
make_col(#name, name, def)
#define ORM_AINCPK(name)\
make_col(#name, name, true, true, true)
#define ORM_PK(name)\
make_col(#name, name, true, true, false)