-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathField.h
More file actions
68 lines (50 loc) · 1.39 KB
/
Field.h
File metadata and controls
68 lines (50 loc) · 1.39 KB
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
67
68
#ifndef DATAMAPPERCPP_FIELD_H__
#define DATAMAPPERCPP_FIELD_H__
#include <string>
#include <sstream>
#include <utilcpp/release_assert.h>
namespace dm
{
template <typename T>
struct Field
{
const std::string& label;
const std::string& options;
Field(const std::string& l,
const std::string& o = std::string()) :
label(l), options(o)
{ }
std::string typeDefinition() const
{
std::ostringstream ret;
ret << getType();
if (!options.empty())
ret << " " << options;
return ret.str();
}
private:
std::string getType() const
{
UTILCPP_RELEASE_ASSERT(false, "Unknown field type");
return ""; // unreachable
}
};
// TODO: note that this is specific for the SQL aspect
// Also, types are SQLite-specific.
template <>
std::string Field<int>::getType() const { return "INT"; }
template <>
std::string Field<__int64>::getType() const { return "INT"; }
// TODO: add CHECK( in { 0, 1 } )
template <>
std::string Field<bool>::getType() const { return "INT"; }
template <>
std::string Field<double>::getType() const { return "REAL"; }
template <>
std::string Field<const char*>::getType() const { return "TEXT"; }
template <>
std::string Field<std::string>::getType() const { return "TEXT"; }
template <>
std::string Field<std::wstring>::getType() const { return "TEXT"; }
}
#endif /* DATAMAPPERCPP_FIELD_H */