TmpMenu/src/script_global.hpp

40 lines
733 B
C++
Raw Normal View History

2019-03-21 20:18:31 +01:00
#pragma once
#include "common.hpp"
namespace big
{
class script_global
{
public:
constexpr script_global(std::size_t index) :
m_index(index)
{
}
2019-03-21 20:18:31 +01: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
template<typename T>
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());
}
template<typename T>
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());
}
2019-03-21 20:18:31 +01:00
private:
void* get() const;
2019-03-21 20:18:31 +01:00
std::size_t m_index;
};
}