-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProfilesDefines.cpp
More file actions
137 lines (114 loc) · 3.84 KB
/
Copy pathProfilesDefines.cpp
File metadata and controls
137 lines (114 loc) · 3.84 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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include "runcpp2/Data/ProfilesDefines.hpp"
#include "runcpp2/ParseUtil.hpp"
#include "ssLogger/ssLog.hpp"
#include <string>
bool runcpp2::Data::ProfilesDefines::ParseYAML_Node(ryml::ConstNodeRef node)
{
ssLOG_FUNC_DEBUG();
INTERNAL_RUNCPP2_SAFE_START();
if(!node.is_map())
{
ssLOG_ERROR("ProfilesDefines: Not a map type");
return false;
}
for(int i = 0; i < node.num_children(); ++i)
{
ryml::ConstNodeRef currentProfileDefinesNode = node[i];
ProfileName profile = GetKey(currentProfileDefinesNode);
if(!ParseYAML_NodeWithProfile(currentProfileDefinesNode, profile))
return false;
}
return true;
INTERNAL_RUNCPP2_SAFE_CATCH_RETURN(false);
}
bool runcpp2::Data::ProfilesDefines::ParseYAML_NodeWithProfile( ryml::ConstNodeRef node,
ProfileName profile)
{
ssLOG_FUNC_DEBUG();
INTERNAL_RUNCPP2_SAFE_START();
if(!INTERNAL_RUNCPP2_BIT_CONTANTS(node.type().type, ryml::NodeType_e::SEQ))
{
ssLOG_ERROR("ProfilesDefines: Paths type requires a list");
return false;
}
for(int i = 0; i < node.num_children(); ++i)
{
std::string defineStr = GetValue(node[i]);
Define define;
size_t equalPos = defineStr.find('=');
if(equalPos != std::string::npos)
{
define.Name = defineStr.substr(0, equalPos);
define.Value = defineStr.substr(equalPos + 1);
define.HasValue = true;
}
else
{
define.Name = defineStr;
define.Value = "";
define.HasValue = false;
}
Defines[profile].push_back(define);
}
return true;
INTERNAL_RUNCPP2_SAFE_CATCH_RETURN(false);
}
bool runcpp2::Data::ProfilesDefines::IsYAML_NodeParsableAsDefault(ryml::ConstNodeRef node) const
{
ssLOG_FUNC_DEBUG();
INTERNAL_RUNCPP2_SAFE_START();
if(!INTERNAL_RUNCPP2_BIT_CONTANTS(node.type().type, ryml::NodeType_e::SEQ))
return false;
return true;
INTERNAL_RUNCPP2_SAFE_CATCH_RETURN(false);
}
std::string runcpp2::Data::ProfilesDefines::ToString(std::string indentation) const
{
std::string result;
if(Defines.empty())
return result;
for(auto it = Defines.begin(); it != Defines.end(); ++it)
{
if(it->second.empty())
result += indentation + it->first + ": []\n";
else
{
result += indentation + it->first + ":\n";
for(int j = 0; j < it->second.size(); ++j)
{
const Define& define = it->second.at(j);
result += indentation + "- ";
if(define.Value.empty())
result += GetEscapedYAMLString(define.Name) + "\n";
else
result += GetEscapedYAMLString(define.Name + "=" + define.Value) + "\n";
}
}
}
return result;
}
bool runcpp2::Data::ProfilesDefines::Equals(const ProfilesDefines& other) const
{
if(Defines.size() != other.Defines.size())
return false;
for(const auto& it : Defines)
{
if(other.Defines.count(it.first) == 0)
return false;
const std::vector<Define>& otherDefines = other.Defines.at(it.first);
if(it.second.size() != otherDefines.size())
return false;
for(size_t i = 0; i < it.second.size(); ++i)
{
const Define& define = it.second[i];
const Define& otherDefine = otherDefines[i];
if( define.Name != otherDefine.Name ||
define.Value != otherDefine.Value ||
define.HasValue != otherDefine.HasValue)
{
return false;
}
}
}
return true;
}