Refactor platform enums

This commit is contained in:
2020-11-19 21:25:19 +01:00
parent 8dd9bbd75f
commit ef80e8918f
6 changed files with 95 additions and 38 deletions

View File

@@ -6,50 +6,108 @@
#pragma once
#include <magic_enum.hpp>
#include <string>
namespace openVulkanoCpp
{
namespace RenderAPI
class RenderAPI
{
public:
enum RenderApi
{
VULKAN = 0,
Vulkan = 0,
//OpenGL,
//DirectX11,
//DirectX12,
//Metal,
MAX_VALUE
};
inline std::string ToString(RenderApi api)
{
switch (api)
{
case VULKAN: return "Vulkan";
}
return "Invalid";
}
}
constexpr RenderAPI(RenderApi api) : api(api) {}
namespace Platform
[[nodiscard]] constexpr std::string_view ToString() const
{
return magic_enum::enum_name(api);
}
[[nodiscard]] constexpr static RenderAPI GetFromName(std::string_view name)
{
return magic_enum::enum_cast<RenderApi>(name).value_or(Vulkan);
}
constexpr operator std::string_view() const { return ToString(); }
constexpr operator RenderApi() const { return api; }
constexpr bool operator==(const RenderAPI other)
{
return other.api == api;
}
constexpr bool operator==(const RenderApi other)
{
return other == api;
}
constexpr bool operator!=(const RenderAPI other)
{
return !(*this == other);
}
constexpr bool operator!=(const RenderApi other)
{
return !(*this == other);
}
private:
RenderApi api;
};
class Platform
{
enum Platform
public:
enum OS
{
Windows = 0, MacOS, Linux, Android, iOS, MAX_VALUE
Windows = 0, MacOS, Linux, Android, iOS, Unknown
};
inline std::string ToString(Platform os)
constexpr Platform(OS os) : os(os) {}
[[nodiscard]] constexpr std::string_view ToString() const
{
switch (os)
{
case Windows: return "Windows";
case MacOS: return "MacOS";
case Linux: return "Linux";
case Android: return "Android";
case iOS: return "iOS";
}
return "Invalid";
return magic_enum::enum_name(os);
}
}
[[nodiscard]] constexpr static Platform GetFromName(std::string_view name)
{
return magic_enum::enum_cast<OS>(name).value_or(Unknown);
}
constexpr operator std::string_view() const { return ToString(); }
constexpr operator OS() const { return os; }
constexpr bool operator==(const Platform other)
{
return other.os == os;
}
constexpr bool operator==(const OS other)
{
return other == os;
}
constexpr bool operator!=(const Platform other)
{
return !(*this == other);
}
constexpr bool operator!=(const OS other)
{
return !(*this == other);
}
private:
OS os;
};
}