forked from mheily/rooms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
repoParser.hpp
60 lines (50 loc) · 1.11 KB
/
repoParser.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
#pragma once
#include <string>
#include <string>
#include "json.hpp"
// A room in the repository
class RepoRoom {
public:
RepoRoom(const std::string& name, const nlohmann::json& json) {
this->name = name;
if (json.find("parent") != json.end()) {
parent = json["parent"];
} else {
parent = "";
}
summary = json["summary"];
}
const std::string getName() const
{
return name;
}
const std::string getSummary() const
{
return summary;
}
const std::string getParent() const
{
return parent;
}
private:
std::string name;
std::string parent;
std::string summary;
};
// TODO: should be RepoManager instead
class RepoParser {
public:
RepoParser();
void parse(const std::string& path);
RepoRoom* getRoom(const std::string& name) {
return rooms[name];
}
void installRoom(const std::string& name);
void printSearchResult(const std::string& pattern);
private:
// the base_uri when downloading rooms
std::string baseUri;
std::map<std::string, RepoRoom*> rooms;
std::string repoJsonPath; // path to JSON repository metadata
void parseJSON(nlohmann::json& result);
};