-
Notifications
You must be signed in to change notification settings - Fork 0
/
Storage.hpp
executable file
·121 lines (102 loc) · 2.62 KB
/
Storage.hpp
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#ifndef AGENDA_STORAGE_H
#define AGENDA_STORAGE_H
#include "Meeting.hpp"
#include "User.hpp"
#include <functional>
#include <list>
#include <memory>
#include <string>
class Storage {
private:
/**
* default constructor
*/
Storage();
/**
* disallow the copy constructor and assign operator
*/
Storage(const Storage & t_another) = delete;
void operator=(const Storage & t_another) = delete;
/**
* read file content into memory
* @return if success, true will be returned
*/
bool readFromFile(void);
/**
* write file content from memory
* @return if success, true will be returned
*/
bool writeToFile(void);
public:
/**
* get Instance of storage
* @return the pointer of the instance
*/
static std::shared_ptr<Storage> getInstance(void);
/**
* destructor
*/
~Storage();
// CRUD for User & Meeting
// using C++11 Function Template and Lambda Expressions
/**
* create a user
* @param a user object
*/
void createUser(const User & t_user);
/**
* query users
* @param a lambda function as the filter
* @return a list of fitted users
*/
std::list<User> queryUser(std::function<bool(const User &)> filter) const;
/**
* update users
* @param a lambda function as the filter
* @param a lambda function as the method to update the user
* @return the number of updated users
*/
int updateUser(std::function<bool(const User &)> filter,
std::function<void(User &)> switcher);
/**
* delete users
* @param a lambda function as the filter
* @return the number of deleted users
*/
int deleteUser(std::function<bool(const User &)> filter);
/**
* create a meeting
* @param a meeting object
*/
void createMeeting(const Meeting & t_meeting);
/**
* query meetings
* @param a lambda function as the filter
* @return a list of fitted meetings
*/
std::list<Meeting> queryMeeting(std::function<bool(const Meeting &)> filter) const;
/**
* update meetings
* @param a lambda function as the filter
* @param a lambda function as the method to update the meeting
* @return the number of updated meetings
*/
int updateMeeting(std::function<bool(const Meeting &)> filter,
std::function<void(Meeting &)> switcher);
/**
* delete meetings
* @param a lambda function as the filter
* @return the number of deleted meetings
*/
int deleteMeeting(std::function<bool(const Meeting &)> filter);
/**
* sync with the file
*/
bool sync(void);
private:
static std::shared_ptr<Storage> m_instance;
std::list<User> m_userList;
std::list<Meeting> m_meetingList;
bool m_dirty;
};
#endif