-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathShow.h
97 lines (76 loc) · 1.79 KB
/
Show.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#ifndef SHOW_H
#define SHOW_H
#include <iostream>
#include <string>
#include "soci/soci/src/core/soci.h"
enum showtype{
COMMENTARY,
EPISODE,
MOVIE,
SPECIAL
};
class Show {
public:
std::string file,
name;
showtype type;
Show(std::string f = std::string(), std::string n = std::string(),
showtype t = EPISODE, unsigned int w = 0) :
file(f), name(n), type(t), watched(w) {
}
Show(const Show& other);
Show(Show& other);
std::string print();
void printdetail(std::ostream& o);
void watch();
void unwatch();
const unsigned int getwatched();
static showtype gettype(const std::string& t);
private:
unsigned int watched;
template<class Show> friend struct soci::type_conversion;
};
/**
* SOCI type conversion code for database access ease
*/
namespace soci {
template<>
struct type_conversion<Show> {
typedef values base_type;
static void from_base(const values& v, indicator /* ind */, Show s) {
s.name = v.get<std::string>("NAME");
s.file = v.get<std::string>("FILE");
s.watched = v.get<int>("WATCHED");
std::string t = v.get<std::string>("TYPE");
if(t == "EPISODE")
s.type = EPISODE;
else if(t == "MOVIE")
s.type = MOVIE;
else if(t == "SPECIAL")
s.type = SPECIAL;
else if(t == "COMMENTARY")
s.type = COMMENTARY;
}
static void to_base(const Show& s, values& v, indicator& ind) {
v.set("NAME", s.name);
v.set("FILE", s.file);
v.set("WATCHED", s.watched);
switch(s.type) {
case COMMENTARY:
v.set("TYPE", std::string("COMMENTARY"));
break;
case EPISODE:
v.set("TYPE", std::string("EPISODE"));
break;
case MOVIE:
v.set("TYPE", std::string("MOVIE"));
break;
case SPECIAL:
v.set("TYPE", std::string("SPECIAL"));
break;
}
ind = i_ok;
}
};
}
#endif