Skip to content

Commit 5b4f9f7

Browse files
Adding helper functions for getting values from platform map
1 parent 99082f7 commit 5b4f9f7

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

Include/runcpp2/PlatformUtil.hpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,45 @@
11
#ifndef RUNCPP2_PLATFORM_UTIL_HPP
22
#define RUNCPP2_PLATFORM_UTIL_HPP
33

4+
#include "runcpp2/Data/ParseCommon.hpp"
45
#include <cstdint>
56
#include <string>
7+
#include <unordered_map>
68
#include <vector>
79

810
namespace runcpp2
911
{
1012
std::string ProcessPath(const std::string& path);
1113

1214
std::vector<std::string> GetPlatformNames();
15+
16+
template <typename T>
17+
inline bool HasValueFromPlatformMap(const std::unordered_map<PlatformName, T>& map)
18+
{
19+
std::vector<std::string> platformNames = runcpp2::GetPlatformNames();
20+
21+
for(int i = platformNames.size() - 1; i >= 0; --i)
22+
{
23+
if(map.find(platformNames.at(i)) != map.end())
24+
return true;
25+
}
26+
27+
return false;
28+
}
29+
30+
template <typename T>
31+
inline const T* GetValueFromPlatformMap(const std::unordered_map<PlatformName, T>& map)
32+
{
33+
std::vector<std::string> platformNames = runcpp2::GetPlatformNames();
34+
35+
for(int i = platformNames.size() - 1; i >= 0; --i)
36+
{
37+
if(map.find(platformNames.at(i)) != map.end())
38+
return &map.at(platformNames[i]);
39+
}
40+
41+
return nullptr;
42+
}
1343
}
1444

1545
#endif

0 commit comments

Comments
 (0)