mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-06-03 16:18:51 -04:00
sm/tipc: minor cleanup
This commit is contained in:
parent
124a1a1ea0
commit
0189c5f1e6
15 changed files with 394 additions and 599 deletions
|
@ -20,147 +20,72 @@
|
|||
|
||||
namespace ams::tipc {
|
||||
|
||||
namespace impl {
|
||||
|
||||
struct InHandleTag{};
|
||||
struct OutHandleTag{};
|
||||
|
||||
template<u32 Attribute>
|
||||
struct InHandle : public InHandleTag {
|
||||
os::NativeHandle handle;
|
||||
|
||||
constexpr InHandle() : handle(os::InvalidNativeHandle) { /* ... */ }
|
||||
constexpr InHandle(os::NativeHandle h) : handle(h) { /* ... */ }
|
||||
constexpr InHandle(const InHandle &o) : handle(o.handle) { /* ... */ }
|
||||
|
||||
constexpr void operator=(const os::NativeHandle &h) { this->handle = h; }
|
||||
constexpr void operator=(const InHandle &o) { this->handle = o.handle; }
|
||||
|
||||
constexpr /* TODO: explicit? */ operator os::NativeHandle() const { return this->handle; }
|
||||
constexpr os::NativeHandle GetValue() const { return this->handle; }
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class OutHandleImpl : public OutHandleTag {
|
||||
static_assert(std::is_base_of<InHandleTag, T>::value, "OutHandleImpl requires InHandle base");
|
||||
private:
|
||||
T *m_ptr;
|
||||
public:
|
||||
constexpr OutHandleImpl(T *p) : m_ptr(p) { /* ... */ }
|
||||
|
||||
constexpr void SetValue(const os::NativeHandle &value) {
|
||||
*m_ptr = value;
|
||||
}
|
||||
|
||||
constexpr void SetValue(const T &value) {
|
||||
*m_ptr = value;
|
||||
}
|
||||
|
||||
constexpr const T &GetValue() const {
|
||||
return *m_ptr;
|
||||
}
|
||||
|
||||
constexpr T *GetPointer() const {
|
||||
return m_ptr;
|
||||
}
|
||||
|
||||
constexpr os::NativeHandle *GetHandlePointer() const {
|
||||
return &m_ptr->handle;
|
||||
}
|
||||
|
||||
constexpr T &operator *() const {
|
||||
return *m_ptr;
|
||||
}
|
||||
|
||||
constexpr T *operator ->() const {
|
||||
return m_ptr;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
using MoveHandle = typename impl::InHandle<SfOutHandleAttr_HipcMove>;
|
||||
using CopyHandle = typename impl::InHandle<SfOutHandleAttr_HipcCopy>;
|
||||
|
||||
static_assert(sizeof(MoveHandle) == sizeof(os::NativeHandle), "sizeof(MoveHandle)");
|
||||
static_assert(sizeof(CopyHandle) == sizeof(os::NativeHandle), "sizeof(CopyHandle)");
|
||||
|
||||
template<>
|
||||
class IsOutForceEnabled<MoveHandle> : public std::true_type{};
|
||||
template<>
|
||||
class IsOutForceEnabled<CopyHandle> : public std::true_type{};
|
||||
|
||||
template<>
|
||||
class Out<MoveHandle> : public impl::OutHandleImpl<MoveHandle> {
|
||||
/* TODO: How do InHandles work in tipc? No examples to work off of. */
|
||||
class CopyHandle {
|
||||
private:
|
||||
using T = MoveHandle;
|
||||
using Base = impl::OutHandleImpl<T>;
|
||||
CopyHandle();
|
||||
};
|
||||
|
||||
class MoveHandle {
|
||||
private:
|
||||
MoveHandle();
|
||||
};
|
||||
|
||||
template<>
|
||||
class Out<CopyHandle> {
|
||||
private:
|
||||
os::NativeHandle * const m_ptr;
|
||||
public:
|
||||
constexpr Out<T>(T *p) : Base(p) { /* ... */ }
|
||||
ALWAYS_INLINE Out(os::NativeHandle *p) : m_ptr(p) { /* ... */ }
|
||||
|
||||
constexpr void SetValue(const os::NativeHandle &value) {
|
||||
Base::SetValue(value);
|
||||
ALWAYS_INLINE void SetValue(os::NativeHandle v) const {
|
||||
*m_ptr = v;
|
||||
}
|
||||
|
||||
constexpr void SetValue(const T &value) {
|
||||
Base::SetValue(value);
|
||||
ALWAYS_INLINE const os::NativeHandle &GetValue() const {
|
||||
return *m_ptr;
|
||||
}
|
||||
|
||||
constexpr const T &GetValue() const {
|
||||
return Base::GetValue();
|
||||
ALWAYS_INLINE os::NativeHandle *GetPointer() const {
|
||||
return m_ptr;
|
||||
}
|
||||
|
||||
constexpr T *GetPointer() const {
|
||||
return Base::GetPointer();
|
||||
/* Convenience operators. */
|
||||
ALWAYS_INLINE os::NativeHandle &operator*() const {
|
||||
return *m_ptr;
|
||||
}
|
||||
|
||||
constexpr os::NativeHandle *GetHandlePointer() const {
|
||||
return Base::GetHandlePointer();
|
||||
}
|
||||
|
||||
constexpr T &operator *() const {
|
||||
return Base::operator*();
|
||||
}
|
||||
|
||||
constexpr T *operator ->() const {
|
||||
return Base::operator->();
|
||||
ALWAYS_INLINE os::NativeHandle *operator->() const {
|
||||
return m_ptr;
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
class Out<CopyHandle> : public impl::OutHandleImpl<CopyHandle> {
|
||||
class Out<MoveHandle> {
|
||||
private:
|
||||
using T = CopyHandle;
|
||||
using Base = impl::OutHandleImpl<T>;
|
||||
os::NativeHandle * const m_ptr;
|
||||
public:
|
||||
constexpr Out<T>(T *p) : Base(p) { /* ... */ }
|
||||
ALWAYS_INLINE Out(os::NativeHandle *p) : m_ptr(p) { /* ... */ }
|
||||
|
||||
constexpr void SetValue(const os::NativeHandle &value) {
|
||||
Base::SetValue(value);
|
||||
ALWAYS_INLINE void SetValue(os::NativeHandle v) const {
|
||||
*m_ptr = v;
|
||||
}
|
||||
|
||||
constexpr void SetValue(const T &value) {
|
||||
Base::SetValue(value);
|
||||
ALWAYS_INLINE const os::NativeHandle &GetValue() const {
|
||||
return *m_ptr;
|
||||
}
|
||||
|
||||
constexpr const T &GetValue() const {
|
||||
return Base::GetValue();
|
||||
ALWAYS_INLINE os::NativeHandle *GetPointer() const {
|
||||
return m_ptr;
|
||||
}
|
||||
|
||||
constexpr T *GetPointer() const {
|
||||
return Base::GetPointer();
|
||||
/* Convenience operators. */
|
||||
ALWAYS_INLINE os::NativeHandle &operator*() const {
|
||||
return *m_ptr;
|
||||
}
|
||||
|
||||
constexpr os::NativeHandle *GetHandlePointer() const {
|
||||
return Base::GetHandlePointer();
|
||||
}
|
||||
|
||||
constexpr T &operator *() const {
|
||||
return Base::operator*();
|
||||
}
|
||||
|
||||
constexpr T *operator ->() const {
|
||||
return Base::operator->();
|
||||
ALWAYS_INLINE os::NativeHandle *operator->() const {
|
||||
return m_ptr;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue