light/modules/base/public/base.hpp

92 lines
1.7 KiB
C++
Raw Normal View History

2021-07-29 17:12:13 +04:30
#pragma once
#include <memory>
2025-07-11 00:05:48 +03:30
namespace lt {
2021-07-29 17:12:13 +04:30
2022-03-07 21:57:00 +03:30
// Ref (Ref)
template<typename t>
using Ref = std::shared_ptr<t>;
2022-03-07 21:57:00 +03:30
template<typename t, typename... Args>
constexpr Ref<t> create_ref(Args &&...args)
2022-03-07 21:57:00 +03:30
{
return std::make_shared<t>(std::forward<Args>(args)...);
2022-03-07 21:57:00 +03:30
}
2021-07-29 17:12:13 +04:30
template<typename t>
constexpr Ref<t> make_ref(t *rawPointer)
2022-03-07 21:57:00 +03:30
{
return std::shared_ptr<t>(rawPointer);
2022-03-07 21:57:00 +03:30
}
2021-07-29 17:12:13 +04:30
2022-03-07 21:57:00 +03:30
// Scope (std::unique_ptr)
template<typename t>
using Scope = std::unique_ptr<t>;
2021-07-29 17:12:13 +04:30
template<typename t, typename... Args>
constexpr std::unique_ptr<t> create_scope(Args &&...args)
2022-03-07 21:57:00 +03:30
{
return std::make_unique<t>(std::forward<Args>(args)...);
2022-03-07 21:57:00 +03:30
}
2021-07-29 17:12:13 +04:30
template<typename t>
constexpr std::unique_ptr<t> make_scope(t *rawPointer)
2022-03-07 21:57:00 +03:30
{
return std::unique_ptr<t>(rawPointer);
2021-07-29 17:12:13 +04:30
}
2025-07-11 00:05:48 +03:30
} // namespace lt
2022-03-07 21:57:00 +03:30
#define lt_win(x) // windows
#define lt_lin(x) // linux
#define lt_mac(x) // mac
2021-07-29 17:12:13 +04:30
2025-07-06 16:30:38 +03:30
enum class Platform : uint8_t
{
windows,
/** Named like so because "linux" is a built-in identifier. */
gnu,
mac,
};
namespace constants {
2021-07-29 17:12:13 +04:30
#if defined(LIGHT_PLATFORM_WINDOWS)
#define lt_win(x)
2025-07-06 16:30:38 +03:30
constexpr auto platform = Platform::windows;
constexpr auto platform_name = "windows";
2022-03-07 21:57:00 +03:30
2025-07-12 19:24:11 +03:30
#undef LIGHT_PLATFORM_WINDOWS
2021-07-29 17:12:13 +04:30
#elif defined(LIGHT_PLATFORM_LINUX)
2025-07-06 16:30:38 +03:30
#define lt_lin(x) x
constexpr auto platform = Platform::gnu;
constexpr auto platform_name = "linux";
2022-03-07 21:57:00 +03:30
2021-07-29 17:12:13 +04:30
#elif defined(LIGHT_PLATFORM_MAC)
#define lt_mac(x) x
2025-07-06 16:30:38 +03:30
constexpr auto platform = Platform::mac;
constexpr auto platform_name = "mac";
2022-03-07 21:57:00 +03:30
2021-07-29 17:12:13 +04:30
#else
2022-05-26 10:52:16 +04:30
#error "Unsupported platform: Unknown"
2025-07-06 16:30:38 +03:30
2021-07-29 17:12:13 +04:30
#endif
2025-07-06 16:30:38 +03:30
} // namespace constants
2021-07-29 17:12:13 +04:30
/* bit-wise */
2025-07-06 16:30:38 +03:30
constexpr auto bit(auto x)
{
return 1 << x;
}
2021-07-29 17:12:13 +04:30
/* token */
#define lt_pair_token_value_to_name(token) { token, #token }
#define lt_pair_token_name_to_value(token) { #token, token }
#define lt_token_name(token) #token