-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwsjcpp_package_manager_author.cpp
More file actions
86 lines (66 loc) · 2.8 KB
/
Copy pathwsjcpp_package_manager_author.cpp
File metadata and controls
86 lines (66 loc) · 2.8 KB
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
#include "wsjcpp_package_manager_author.h"
#include <wsjcpp_core.h>
// ---------------------------------------------------------------------
// WsjcppPackageManagerAuthor
WsjcppPackageManagerAuthor::WsjcppPackageManagerAuthor() {
TAG = "WsjcppPackageManagerAuthor";
m_sName = "";
m_sEmail = "";
m_pYamlAuthor = nullptr;
}
// ---------------------------------------------------------------------
WsjcppPackageManagerAuthor::WsjcppPackageManagerAuthor(const std::string &sName, const std::string &sEmail) {
TAG = "WsjcppPackageManagerAuthor";
m_sName = sName;
m_sEmail = sEmail;
m_pYamlAuthor = nullptr;
}
// ---------------------------------------------------------------------
std::string WsjcppPackageManagerAuthor::getName() {
return m_sName;
}
// ---------------------------------------------------------------------
std::string WsjcppPackageManagerAuthor::getEmail() {
return m_sEmail;
}
// ---------------------------------------------------------------------
std::string WsjcppPackageManagerAuthor::getWebSite() {
return m_sWebSite;
}
// ---------------------------------------------------------------------
std::string WsjcppPackageManagerAuthor::getFullAuthor() {
return m_sName + " <" + m_sEmail + ">";
}
// ---------------------------------------------------------------------
WsjcppYamlNode *WsjcppPackageManagerAuthor::toYAML() {
m_pYamlAuthor->getElement("name")->setValue(m_sName, WSJCPP_YAML_QUOTES_NONE);
m_pYamlAuthor->getElement("email")->setValue(m_sEmail, WSJCPP_YAML_QUOTES_NONE);
m_pYamlAuthor->getElement("web-site")->setValue(m_sWebSite, WSJCPP_YAML_QUOTES_NONE);
return m_pYamlAuthor;
}
// ---------------------------------------------------------------------
bool WsjcppPackageManagerAuthor::fromYAML(WsjcppYamlNode *pYamlAuthor) {
m_pYamlAuthor = pYamlAuthor;
if (!m_pYamlAuthor->hasElement("name")) {
WsjcppLog::err(TAG, "Missing required field 'name' in " + pYamlAuthor->getForLogFormat());
return false;
}
if (!m_pYamlAuthor->hasElement("email")) {
WsjcppLog::err(TAG, "Missing required field 'email' in " + pYamlAuthor->getForLogFormat());
return false;
}
std::vector<std::string> vKeys = m_pYamlAuthor->getKeys();
for (int i = 0; i < vKeys.size(); i++) {
std::string sKey = vKeys[i];
if (sKey == "name") {
m_sName = m_pYamlAuthor->getElement("name")->getValue();
} else if (sKey == "email") {
m_sEmail = m_pYamlAuthor->getElement("email")->getValue();
} else if (sKey == "web-site") {
m_sWebSite = m_pYamlAuthor->getElement("web-site")->getValue();
} else {
WsjcppLog::warn(TAG, "Excess field '" + sKey + "' in " + pYamlAuthor->getElement(sKey)->getForLogFormat());
}
}
return true;
}