#ifndef XNA_CSHARP_TYPE_HPP #define XNA_CSHARP_TYPE_HPP #include "../default.hpp" #include "object.hpp" #include #include #include namespace xna { class Type : public Object { public: constexpr String FullName() const { return fullName; } constexpr bool IsClass() const { return isClass; } constexpr bool IsEnum() const { return isEnum; } constexpr bool IsValueType() const { return isValueType; } constexpr bool IsPrimitive() const { return isPrimitive; } constexpr bool IsPointer() const { return isPointer; } virtual size_t GetHashCode() const; constexpr bool operator==(const Type& other) const { return fullName == other.fullName && isClass == other.isClass && isEnum == other.isEnum && isValueType == other.isValueType && isPointer == other.isPointer && isPrimitive == other.isPrimitive; } bool operator()(Type const& t1, Type const& t2) const { return t1.GetHashCode() < t2.GetHashCode(); } template friend sptr typeof(); public: inline static auto NameOfRegisteredTypes = std::map>(); private: String fullName; bool isClass{ false }; bool isEnum{ false }; bool isValueType{ false }; bool isPrimitive{ false }; bool isPointer { false }; }; template inline sptr typeof() { if (std::is_arithmetic::value) { auto primitiveType = New(); primitiveType->fullName = typeid(T).name(); primitiveType->isPrimitive = true; primitiveType->isValueType = true; return primitiveType; } if (std::is_enum::value) { auto enumType = New(); enumType->fullName = typeid(T).name(); enumType->isValueType = true; enumType->isEnum = true; return enumType; } if (std::is_pointer::value) { auto pointerType = New(); pointerType->fullName = typeid(T).name(); pointerType->isPointer = true; return pointerType; } if (std::is_class::value) { auto classType = New(); classType->fullName = typeid(T).name(); classType->isClass = true; return classType; } return nullptr; } template inline sptr typeof(T const* object) { return typeof(); } template inline sptr typeof(T const& object) { return typeof(); } } #endif