Skip to content

Commit f8f2adb

Browse files
Adding ParsePlatformProfileMap and refactored code to use it
1 parent a9839f3 commit f8f2adb

File tree

5 files changed

+122
-348
lines changed

5 files changed

+122
-348
lines changed

Include/runcpp2/Data/ProfilesFlagsOverride.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ namespace runcpp2
1616
std::unordered_map<ProfileName, FlagsOverrideInfo> FlagsOverrides;
1717

1818
bool ParseYAML_Node(ryml::ConstNodeRef node);
19+
bool ParseYAML_NodeWithProfile(ryml::ConstNodeRef node, ProfileName profile);
20+
bool IsYAML_NodeParsableAsDefault(ryml::ConstNodeRef node) const;
1921
std::string ToString(std::string indentation) const;
2022
bool Equals(const ProfilesFlagsOverride& other) const;
2123
};

Include/runcpp2/ParseUtil.hpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
#define RUNCPP2_PARSE_UTIL_HPP
33

44
#include "runcpp2/YamlLib.hpp"
5+
#include "runcpp2/Data/ParseCommon.hpp"
6+
#include "ssLogger/ssLog.hpp"
57

68
#include <vector>
9+
#include <unordered_map>
710

811
namespace runcpp2
912
{
@@ -44,6 +47,48 @@ namespace runcpp2
4447
std::string GetEscapedYAMLString(const std::string& input);
4548

4649
bool ParseIncludes(const std::string& line, std::string& outIncludePath);
50+
51+
template<typename T>
52+
bool ParsePlatformProfileMap( ryml::ConstNodeRef node,
53+
const std::string& key,
54+
std::unordered_map<PlatformName, T>& result,
55+
const std::string& errorMessage)
56+
{
57+
if(ExistAndHasChild(node, key))
58+
{
59+
ryml::ConstNodeRef mapNode = node[key.c_str()];
60+
61+
//If we skip platform profile
62+
T defaultValue;
63+
if(defaultValue.IsYAML_NodeParsableAsDefault(mapNode))
64+
{
65+
if(defaultValue.ParseYAML_NodeWithProfile(mapNode, "DefaultProfile"))
66+
result["DefaultPlatform"] = defaultValue;
67+
else
68+
return false;
69+
}
70+
else
71+
{
72+
if(!CheckNodeRequirement(mapNode, key, ryml::NodeType_e::MAP, false, true))
73+
return false;
74+
75+
for(int i = 0; i < mapNode.num_children(); ++i)
76+
{
77+
PlatformName platform = GetKey(mapNode[i]);
78+
T value;
79+
ryml::ConstNodeRef currentNode = mapNode[i];
80+
81+
if(!value.ParseYAML_Node(currentNode))
82+
{
83+
ssLOG_ERROR("ScriptInfo: Failed to parse " << errorMessage);
84+
return false;
85+
}
86+
result[platform] = value;
87+
}
88+
}
89+
}
90+
return true;
91+
}
4792
}
4893

4994
#endif

Src/runcpp2/Data/ProfilesFlagsOverride.cpp

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,54 @@ bool runcpp2::Data::ProfilesFlagsOverride::ParseYAML_Node(ryml::ConstNodeRef nod
1515

1616
for(int i = 0; i < node.num_children(); ++i)
1717
{
18-
if(!INTERNAL_RUNCPP2_BIT_CONTANTS(node[i].type().type, ryml::NodeType_e::MAP))
19-
{
20-
ssLOG_ERROR("ProfilesFlagsOverrides: FlagsOverrideInfo type requires a map");
21-
return false;
22-
}
23-
2418
ProfileName profile = GetKey(node[i]);
25-
FlagsOverrideInfo flags;
26-
27-
ryml::ConstNodeRef flagsOverrideNode = node[i];
28-
29-
if(!flags.ParseYAML_Node(flagsOverrideNode))
30-
{
31-
ssLOG_ERROR("ProfilesFlagsOverrides: Unable to parse FlagsOverride.");
19+
if(!ParseYAML_NodeWithProfile(node[i], profile))
3220
return false;
33-
}
34-
35-
FlagsOverrides[profile] = flags;
3621
}
3722

3823
return true;
3924

4025
INTERNAL_RUNCPP2_SAFE_CATCH_RETURN(false);
4126
}
4227

28+
bool runcpp2::Data::ProfilesFlagsOverride::ParseYAML_NodeWithProfile( ryml::ConstNodeRef node,
29+
ProfileName profile)
30+
{
31+
ssLOG_FUNC_DEBUG();
32+
INTERNAL_RUNCPP2_SAFE_START();
33+
34+
if(!INTERNAL_RUNCPP2_BIT_CONTANTS(node.type().type, ryml::NodeType_e::MAP))
35+
{
36+
ssLOG_ERROR("ProfilesFlagsOverrides: FlagsOverrideInfo type requires a map");
37+
return false;
38+
}
39+
40+
FlagsOverrideInfo flags;
41+
ryml::ConstNodeRef flagsOverrideNode = node;
42+
43+
if(!flags.ParseYAML_Node(flagsOverrideNode))
44+
{
45+
ssLOG_ERROR("ProfilesFlagsOverrides: Unable to parse FlagsOverride.");
46+
return false;
47+
}
48+
49+
FlagsOverrides[profile] = flags;
50+
51+
return true;
52+
INTERNAL_RUNCPP2_SAFE_CATCH_RETURN(false);
53+
}
54+
55+
bool runcpp2::Data::ProfilesFlagsOverride::IsYAML_NodeParsableAsDefault(ryml::ConstNodeRef node) const
56+
{
57+
ssLOG_FUNC_DEBUG();
58+
INTERNAL_RUNCPP2_SAFE_START();
59+
60+
FlagsOverrideInfo flags;
61+
return flags.IsYAML_NodeParsableAsDefault(node);
62+
63+
INTERNAL_RUNCPP2_SAFE_CATCH_RETURN(false);
64+
}
65+
4366
std::string runcpp2::Data::ProfilesFlagsOverride::ToString(std::string indentation) const
4467
{
4568
std::string out;

0 commit comments

Comments
 (0)