2019-03-21 20:18:31 +01:00
|
|
|
#pragma once
|
|
|
|
#include "common.hpp"
|
|
|
|
|
|
|
|
namespace big
|
|
|
|
{
|
|
|
|
class script_global
|
|
|
|
{
|
|
|
|
public:
|
2023-07-15 00:55:09 +02:00
|
|
|
constexpr script_global(std::size_t index) :
|
2023-11-30 04:47:39 -05:00
|
|
|
m_index(index)
|
2023-07-15 00:55:09 +02:00
|
|
|
{
|
|
|
|
}
|
2019-03-21 20:18:31 +01:00
|
|
|
|
2023-07-15 00:55:09 +02:00
|
|
|
constexpr script_global at(std::ptrdiff_t index) const
|
|
|
|
{
|
|
|
|
return m_index + index;
|
|
|
|
}
|
|
|
|
constexpr script_global at(std::ptrdiff_t index, std::size_t size) const
|
|
|
|
{
|
|
|
|
return m_index + 1 + (index * size);
|
|
|
|
}
|
2019-03-21 20:18:31 +01:00
|
|
|
|
2023-03-01 21:27:15 +00:00
|
|
|
template<typename T>
|
2023-07-15 00:55:09 +02:00
|
|
|
std::enable_if_t<std::is_pointer_v<T>, T> as() const
|
2019-03-21 20:18:31 +01:00
|
|
|
{
|
|
|
|
return static_cast<T>(get());
|
|
|
|
}
|
|
|
|
|
2023-03-01 21:27:15 +00:00
|
|
|
template<typename T>
|
2023-07-15 00:55:09 +02:00
|
|
|
std::enable_if_t<std::is_lvalue_reference_v<T>, T> as() const
|
2019-03-21 20:18:31 +01:00
|
|
|
{
|
|
|
|
return *static_cast<std::add_pointer_t<std::remove_reference_t<T>>>(get());
|
|
|
|
}
|
2023-03-01 21:27:15 +00:00
|
|
|
|
2019-03-21 20:18:31 +01:00
|
|
|
private:
|
2023-07-15 00:55:09 +02:00
|
|
|
void* get() const;
|
2019-03-21 20:18:31 +01:00
|
|
|
std::size_t m_index;
|
|
|
|
};
|
|
|
|
}
|