-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStorage.h
53 lines (46 loc) · 1.59 KB
/
Storage.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
#ifndef AGENDA_STORAGE_H
#define AGENDA_STORAGE_H
#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
TypeName(const TypeName&); \
void operator=(const TypeName&)
#include <list>
#include <string>
#include <functional>
#include "User.h"
#include "Meeting.h"
class Storage {
private:
static Storage *instance_;
DISALLOW_COPY_AND_ASSIGN(Storage);
Storage();
// storage structure, or you have better structures
// e.g. balanced tree
std::list<User> userList_;
std::list<Meeting> meetingList_;
// File IO
bool readFromFile(const char *fpath);
bool writeToFile(const char *fpath);
public:
// singleton
static Storage *getInstance(void);
~Storage();
// CRUD for User & Meeting
// using C++11 Function Template and Lambda Expressions
void createUser(const User&);
std::list<User> queryUser(std::function<bool(const User&)> filter);
// return found users
int updateUser(std::function<bool(const User&)> filter, std::function<void(User&)> switcher);
// return the number of updated users
int deleteUser(std::function<bool(const User&)> filter);
// return the number of deleted users
void createMeeting(const Meeting&);
std::list<Meeting> queryMeeting(std::function<bool(const Meeting&)> filter);
// return found meetings
int updateMeeting(std::function<bool(const Meeting&)> filter, std::function<void(Meeting&)> switcher);
// return the number of updated meetings
int deleteMeeting(std::function<bool(const Meeting&)> filter);
// return the number of deleted meetings
// File IO
bool sync(void);
};
#endif