#ifndef __PSHAG_TYPES_HPP__ #define __PSHAG_TYPES_HPP__ #include #include #include #include "GCNTypes.hpp" #include "rstl.hpp" #include "DataSpec/DNACommon/DNACommon.hpp" namespace pshag { using FourCC = HECL::FourCC; using TResId = u32; struct SObjectTag { FourCC type; TResId id = -1; bool operator!=(const SObjectTag& other) const {return id != other.id;} bool operator==(const SObjectTag& other) const {return id == other.id;} }; /** * @brief singleton static-allocator */ template class TOneStatic { static u8 m_allocspace[sizeof(T)]; static u32 m_refCount; public: static T* GetAllocSpace() {return (T*)m_allocspace;} static u32& ReferenceCount() {return m_refCount;} T* operator->() const {return (T*)m_allocspace;} T& operator*() const {return *(T*)m_allocspace;} void* operator new(size_t) = delete; void operator delete(void*) = delete; template TOneStatic(typename std::enable_if::value>::type* = 0) {++m_refCount;} template TOneStatic(typename std::enable_if::value>::type* = 0) {++m_refCount; new (m_allocspace) T();} template TOneStatic(Args&&... args) {++m_refCount; new (m_allocspace) T(std::forward(args)...);} ~TOneStatic() {--m_refCount;} template void reset(Args&&... args) {new (m_allocspace) T(std::forward(args)...);} }; template u8 TOneStatic::m_allocspace[sizeof(T)]; template u32 TOneStatic::m_refCount; using TUniqueId = u16; using TEditorId = u32; using TAreaId = u32; #define kInvalidEditorId TEditorId(-1) #define kInvalidUniqueId TUniqueId(-1) #define kInvalidAreaId TAreaId(-1) } namespace std { template<> struct hash { inline size_t operator()(const pshag::SObjectTag& tag) const {return tag.id;} }; } #endif // __PSHAG_TYPES_HPP__