-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParseUtil.hpp
More file actions
96 lines (79 loc) · 3.31 KB
/
Copy pathParseUtil.hpp
File metadata and controls
96 lines (79 loc) · 3.31 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
#ifndef RUNCPP2_PARSE_UTIL_HPP
#define RUNCPP2_PARSE_UTIL_HPP
#include "runcpp2/YamlLib.hpp"
#include "runcpp2/Data/ParseCommon.hpp"
#include "ssLogger/ssLog.hpp"
#include <vector>
#include <unordered_map>
namespace runcpp2
{
struct NodeRequirement
{
std::string Name;
YAML::NodeType NodeType;
bool Required;
bool Nullable;
NodeRequirement();
NodeRequirement(const std::string& name,
YAML::NodeType nodeType,
bool required,
bool nullable);
};
bool CheckNodeRequirement( YAML::ConstNodePtr parentNode,
const std::string childName,
YAML::NodeType childType,
bool required,
bool nullable);
bool CheckNodeRequirements( YAML::ConstNodePtr node,
const std::vector<NodeRequirement>& requirements);
bool GetParsableInfo(const std::string& contentToParse, std::string& outParsableInfo);
bool MergeYAML_NodeChildren(YAML::NodePtr nodeToMergeFrom,
YAML::NodePtr nodeToMergeTo,
YAML::ResourceHandle& yamlResouce);
bool ExistAndHasChild( YAML::ConstNodePtr node,
const std::string& childName,
bool nullable = false);
std::string GetEscapedYAMLString(const std::string& input);
bool ParseIncludes(const std::string& line, std::string& outIncludePath);
template<typename T>
bool ParsePlatformProfileMap( YAML::ConstNodePtr node,
const std::string& key,
std::unordered_map<PlatformName, T>& result,
const std::string& errorMessage)
{
if(ExistAndHasChild(node, key))
{
YAML::ConstNodePtr mapNode = node->GetMapValueNode(key);
//If we skip platform profile
T defaultValue;
if(defaultValue.IsYAML_NodeParsableAsDefault(mapNode))
{
if(defaultValue.ParseYAML_NodeWithProfile(mapNode, "DefaultProfile"))
result["DefaultPlatform"] = defaultValue;
else
return false;
}
else
{
if(!CheckNodeRequirement(node, key, YAML::NodeType::Map, false, true))
return false;
for(int i = 0; i < mapNode->GetChildrenCount(); ++i)
{
PlatformName platform =
mapNode ->GetMapKeyScalarAt<std::string>(i)
.DS_TRY_ACT(ssLOG_ERROR(DS_TMP_ERROR.ToString()); return false);
T value;
YAML::ConstNodePtr currentNode = mapNode->GetMapValueNodeAt(i);
if(!value.ParseYAML_Node(currentNode))
{
ssLOG_ERROR("ScriptInfo: Failed to parse " << errorMessage);
return false;
}
result[platform] = value;
}
}
}
return true;
}
}
#endif