vm::ref improved, bugfixes

This commit is contained in:
Nekotekina 2015-06-13 17:48:21 +03:00
parent 1256d648c1
commit 4d9add5e7c
3 changed files with 46 additions and 26 deletions

View file

@ -787,6 +787,7 @@ template<typename T> struct to_be<volatile T>
using type = volatile to_be_t<std::remove_volatile_t<T>>; using type = volatile to_be_t<std::remove_volatile_t<T>>;
}; };
template<> struct to_be<u128> { using type = u128; };
template<> struct to_be<void> { using type = void; }; template<> struct to_be<void> { using type = void; };
template<> struct to_be<bool> { using type = bool; }; template<> struct to_be<bool> { using type = bool; };
template<> struct to_be<char> { using type = char; }; template<> struct to_be<char> { using type = char; };
@ -907,6 +908,7 @@ template<typename T> struct to_le<volatile T>
using type = volatile to_le_t<std::remove_volatile_t<T>>; using type = volatile to_le_t<std::remove_volatile_t<T>>;
}; };
template<> struct to_le<u128> { using type = u128; };
template<> struct to_le<void> { using type = void; }; template<> struct to_le<void> { using type = void; };
template<> struct to_le<bool> { using type = bool; }; template<> struct to_le<bool> { using type = bool; };
template<> struct to_le<char> { using type = char; }; template<> struct to_le<char> { using type = char; };

View file

@ -5,49 +5,65 @@ namespace vm
template<typename T, typename AT = u32> template<typename T, typename AT = u32>
struct _ref_base struct _ref_base
{ {
const AT m_addr; AT m_addr;
using type = T;
static_assert(!std::is_pointer<T>::value, "vm::_ref_base<> error: invalid type (pointer)"); static_assert(!std::is_pointer<T>::value, "vm::_ref_base<> error: invalid type (pointer)");
static_assert(!std::is_reference<T>::value, "vm::_ref_base<> error: invalid type (reference)"); static_assert(!std::is_reference<T>::value, "vm::_ref_base<> error: invalid type (reference)");
//template<typename CT> operator std::enable_if_t<std::is_convertible<T, CT>::value, CT>()
//{
// return get_ref<T>(m_addr);
//}
// temporarily, because SFINAE doesn't work for some reason:
operator to_ne_t<T>() const
{
return get_ref<T>(m_addr);
}
operator T() const
{
return get_ref<T>(m_addr);
}
AT addr() const AT addr() const
{ {
return m_addr; return m_addr;
} }
static _ref_base make(const AT& addr) template<typename AT2 = AT> static _ref_base make(const AT2& addr)
{ {
return{ addr }; return{ convert_le_be<AT>(addr) };
} }
template<typename CT> const _ref_base& operator =(const _ref_base<T, CT>& right) const T& get_ref() const
{ {
get_ref<T>(m_addr) = right; return vm::get_ref<T>(vm::cast(m_addr));
}
T& priv_ref() const
{
return vm::priv_ref<T>(vm::cast(m_addr));
}
// conversion operator
//template<typename CT> operator std::enable_if_t<std::is_convertible<T, CT>::value, CT>()
//{
// return get_ref();
//}
// temporarily, because SFINAE doesn't work for some reason:
operator to_ne_t<T>() const
{
return get_ref();
}
operator T() const
{
return get_ref();
}
// copy assignment operator
_ref_base& operator =(const _ref_base& right)
{
get_ref() = right.get_ref();
return *this;
}
template<typename CT, typename AT2> std::enable_if_t<std::is_assignable<T&, CT>::value, const _ref_base&> operator =(const _ref_base<CT, AT2>& right) const
{
get_ref() = right.get_ref();
return *this; return *this;
} }
template<typename CT> std::enable_if_t<std::is_assignable<T&, CT>::value, const _ref_base&> operator =(const CT& right) const template<typename CT> std::enable_if_t<std::is_assignable<T&, CT>::value, const _ref_base&> operator =(const CT& right) const
{ {
get_ref<T>(m_addr) = right; get_ref() = right;
return *this; return *this;
} }
}; };
@ -90,7 +106,7 @@ namespace vm
//PS3 emulation is main now, so lets it be as default //PS3 emulation is main now, so lets it be as default
using namespace ps3; using namespace ps3;
}; }
// external specialization for is_be_t<> // external specialization for is_be_t<>

View file

@ -57,6 +57,8 @@ template<typename T> force_inline T align(const T addr, int align)
return (addr + (align - 1)) & ~(align - 1); return (addr + (align - 1)) & ~(align - 1);
} }
template<typename T> using func_def = T; // workaround for MSVC bug
#include "Utilities/BEType.h" #include "Utilities/BEType.h"
#include "Utilities/StrFmt.h" #include "Utilities/StrFmt.h"