-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParseUtil.hpp
More file actions
97 lines (80 loc) · 3.32 KB
/
Copy pathParseUtil.hpp
File metadata and controls
97 lines (80 loc) · 3.32 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
#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;
ryml::NodeType NodeType;
bool Required;
bool Nullable;
NodeRequirement();
NodeRequirement(const std::string& name,
ryml::NodeType nodeType,
bool required,
bool nullable);
};
bool CheckNodeRequirement( ryml::ConstNodeRef node,
const std::string name,
ryml::NodeType nodeType,
bool required,
bool nullable);
bool CheckNodeRequirements( ryml::ConstNodeRef node,
const std::vector<NodeRequirement>& requirements);
bool GetParsableInfo(const std::string& contentToParse, std::string& outParsableInfo);
bool ResolveYAML_Stream(ryml::Tree& rootTree,
ryml::NodeRef& outRootNode);
//NOTE: Tree of both nodeToMergeTo and nodeToMergeFrom needs to be alive to be valid
bool MergeYAML_NodeChildren(ryml::NodeRef nodeToMergeFrom, ryml::NodeRef nodeToMergeTo);
bool ExistAndHasChild( ryml::ConstNodeRef node,
const std::string& childName,
bool nullable = false);
std::string GetValue(ryml::ConstNodeRef node);
std::string GetKey(ryml::ConstNodeRef node);
std::string GetEscapedYAMLString(const std::string& input);
bool ParseIncludes(const std::string& line, std::string& outIncludePath);
template<typename T>
bool ParsePlatformProfileMap( ryml::ConstNodeRef node,
const std::string& key,
std::unordered_map<PlatformName, T>& result,
const std::string& errorMessage)
{
if(ExistAndHasChild(node, key))
{
ryml::ConstNodeRef mapNode = node[key.c_str()];
//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(mapNode, key, ryml::NodeType_e::MAP, false, true))
return false;
for(int i = 0; i < mapNode.num_children(); ++i)
{
PlatformName platform = GetKey(mapNode[i]);
T value;
ryml::ConstNodeRef currentNode = mapNode[i];
if(!value.ParseYAML_Node(currentNode))
{
ssLOG_ERROR("ScriptInfo: Failed to parse " << errorMessage);
return false;
}
result[platform] = value;
}
}
}
return true;
}
}
#endif