-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProfilesProcessPaths.hpp
More file actions
118 lines (96 loc) · 3.34 KB
/
Copy pathProfilesProcessPaths.hpp
File metadata and controls
118 lines (96 loc) · 3.34 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
#ifndef RUNCPP2_DATA_PROFILES_PROCESS_PATHS_HPP
#define RUNCPP2_DATA_PROFILES_PROCESS_PATHS_HPP
#include "runcpp2/Data/ParseCommon.hpp"
#include "runcpp2/ParseUtil.hpp"
#include "runcpp2/LibYAML_Wrapper.hpp"
#include "ssLogger/ssLog.hpp"
#if !defined(NOMINMAX)
#define NOMINMAX 1
#endif
#include "ghc/filesystem.hpp"
#include "DSResult/DSResult.hpp"
#include <unordered_map>
#include <string>
#include <utility>
#include <vector>
namespace runcpp2
{
namespace Data
{
struct ProfilesProcessPaths
{
std::unordered_map<ProfileName, std::vector<ghc::filesystem::path>> Paths;
inline bool ParseYAML_Node(YAML::ConstNodePtr node)
{
ssLOG_FUNC_DEBUG();
if(!node->IsMap())
{
ssLOG_ERROR("ProfilesProcessPaths: Not a map type");
return false;
}
for(int i = 0; i < node->GetChildrenCount(); ++i)
{
YAML::ConstNodePtr currentProfilePathsNode = node->GetMapValueNodeAt(i);
ProfileName profile = node->GetMapKeyScalarAt<ProfileName>(i).DS_TRY_ACT(return false);
if(!ParseYAML_NodeWithProfile(currentProfilePathsNode, profile))
return false;
}
return true;
}
inline bool ParseYAML_NodeWithProfile(YAML::ConstNodePtr node, ProfileName profile)
{
ssLOG_FUNC_DEBUG();
if(!node->IsSequence())
{
ssLOG_ERROR("ProfilesProcessPaths: Paths type requires a list");
return false;
}
for(int i = 0; i < node->GetChildrenCount(); ++i)
{
std::string path = node ->GetSequenceChildScalar<std::string>(i)
.DS_TRY_ACT(return false);
Paths[profile].push_back(path);
}
return true;
}
inline bool IsYAML_NodeParsableAsDefault(YAML::ConstNodePtr node) const
{
ssLOG_FUNC_DEBUG();
return node->IsSequence();
}
inline std::string ToString(std::string indentation) const
{
std::string out;
if(Paths.empty())
return out;
for(auto it = Paths.begin(); it != Paths.end(); ++it)
{
if(it->second.empty())
out += indentation + it->first + ": []\n";
else
{
out += indentation + it->first + ":\n";
for(int i = 0; i < it->second.size(); ++i)
{
out += indentation + "- " +
GetEscapedYAMLString(it->second.at(i).string()) + "\n";
}
}
}
return out;
}
inline bool Equals(const ProfilesProcessPaths& other) const
{
if(Paths.size() != other.Paths.size())
return false;
for(const auto& it : Paths)
{
if(other.Paths.count(it.first) == 0 || other.Paths.at(it.first) != it.second)
return false;
}
return true;
}
};
}
}
#endif