From b4cdf8d98767ddd575c0ea1a0398f3508ea5a89a Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 27 Jun 2020 15:46:43 -0400 Subject: [PATCH] Separates runtime TypeInfo into its own header. --- Reflection/Struct.cpp | 52 +-------------------------------- Reflection/TypeInfo.hpp | 64 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 51 deletions(-) create mode 100644 Reflection/TypeInfo.hpp diff --git a/Reflection/Struct.cpp b/Reflection/Struct.cpp index 72cdf895b..17ce28406 100644 --- a/Reflection/Struct.cpp +++ b/Reflection/Struct.cpp @@ -7,6 +7,7 @@ // #include "Struct.hpp" +#include "TypeInfo.hpp" #include #include @@ -15,57 +16,6 @@ #include #include -#define ForAllInts(x) \ - x(uint8_t); \ - x(int8_t); \ - x(uint16_t); \ - x(int16_t); \ - x(uint32_t); \ - x(int32_t); \ - x(uint64_t); \ - x(int64_t); - -#define ForAllFloats(x) \ - x(float); \ - x(double); - -namespace TypeInfo { - -static bool is_integral(const std::type_info *type) { - return - *type == typeid(uint8_t) || *type == typeid(int8_t) || - *type == typeid(uint16_t) || *type == typeid(int16_t) || - *type == typeid(uint32_t) || *type == typeid(int32_t) || - *type == typeid(uint64_t) || *type == typeid(int64_t); -} - -static bool is_floating_point(const std::type_info *type) { - return *type == typeid(float) || *type == typeid(double); -} - -static bool is_signed(const std::type_info *type) { - return - *type == typeid(int8_t) || - *type == typeid(int16_t) || - *type == typeid(int32_t) || - *type == typeid(int64_t) || - *type == typeid(double) || - *type == typeid(float); -} - -static size_t size(const std::type_info *type) { -#define TestType(x) if(*type == typeid(x)) return sizeof(x); - ForAllInts(TestType); - ForAllFloats(TestType); - TestType(char *); -#undef TestType - - // This is some sort of struct or object type. - return 0; -} - -} - // MARK: - Setters template <> bool Reflection::set(Struct &target, const std::string &name, float value, size_t offset) { diff --git a/Reflection/TypeInfo.hpp b/Reflection/TypeInfo.hpp new file mode 100644 index 000000000..926354642 --- /dev/null +++ b/Reflection/TypeInfo.hpp @@ -0,0 +1,64 @@ +// +// TypeInfo.hpp +// Clock Signal +// +// Created by Thomas Harte on 27/06/2020. +// Copyright © 2020 Thomas Harte. All rights reserved. +// + +#ifndef TypeInfo_hpp +#define TypeInfo_hpp + +#define ForAllInts(x) \ + x(uint8_t); \ + x(int8_t); \ + x(uint16_t); \ + x(int16_t); \ + x(uint32_t); \ + x(int32_t); \ + x(uint64_t); \ + x(int64_t); + +#define ForAllFloats(x) \ + x(float); \ + x(double); + +namespace TypeInfo { + +inline bool is_integral(const std::type_info *type) { + return + *type == typeid(uint8_t) || *type == typeid(int8_t) || + *type == typeid(uint16_t) || *type == typeid(int16_t) || + *type == typeid(uint32_t) || *type == typeid(int32_t) || + *type == typeid(uint64_t) || *type == typeid(int64_t); +} + +inline bool is_floating_point(const std::type_info *type) { + return *type == typeid(float) || *type == typeid(double); +} + +inline bool is_signed(const std::type_info *type) { + return + *type == typeid(int8_t) || + *type == typeid(int16_t) || + *type == typeid(int32_t) || + *type == typeid(int64_t) || + *type == typeid(double) || + *type == typeid(float); +} + +inline size_t size(const std::type_info *type) { +#define TestType(x) if(*type == typeid(x)) return sizeof(x); + ForAllInts(TestType); + ForAllFloats(TestType); + TestType(char *); +#undef TestType + + // This is some sort of struct or object type. + return 0; +} + +} + + +#endif /* TypeInfo_hpp */