forked from cheyuanl/json_query_cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_storage.cpp
40 lines (34 loc) · 882 Bytes
/
list_storage.cpp
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
#include "list_storage.hpp"
#include <sstream>
#include "util.hpp"
bool ListStorage::add(const string &s) {
Json::Value root = to_json(s);
if (!root) {
return false;
}
storage.push_back(pair<Json::Value, string>(to_json(s), string(s)));
return true;
}
vector<string> ListStorage::get(const string &s) {
Json::Value query = to_json(s);
if (!query) {
return vector<string>();
}
vector<string> output;
for (const pair<Json::Value, string> &p : storage) {
if (match(p.first, query)) {
output.push_back(p.second);
}
}
return output;
}
bool ListStorage::del(const string &s) {
Json::Value query = to_json(s);
if (!query) {
return false;
}
storage.remove_if([query, this](pair<Json::Value, string> p) {
return match(p.first, query);
});
return true;
}