1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-25 16:31:42 +00:00

Separates runtime TypeInfo into its own header.

This commit is contained in:
Thomas Harte 2020-06-27 15:46:43 -04:00
parent 6925a04088
commit b4cdf8d987
2 changed files with 65 additions and 51 deletions

View File

@ -7,6 +7,7 @@
//
#include "Struct.hpp"
#include "TypeInfo.hpp"
#include <algorithm>
#include <cmath>
@ -15,57 +16,6 @@
#include <sstream>
#include <type_traits>
#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) {

64
Reflection/TypeInfo.hpp Normal file
View File

@ -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 */