Skip to content

Commit

Permalink
I regret this
Browse files Browse the repository at this point in the history
  • Loading branch information
PredatorCZ committed Aug 29, 2024
1 parent c57d4ac commit ac96aee
Show file tree
Hide file tree
Showing 14 changed files with 1,802 additions and 1,746 deletions.
6 changes: 4 additions & 2 deletions include/spike/reflect/array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
#include "reflector_fwd.hpp"
#include <array>

template <typename T, size_t N>
struct is_inline_array<std::array<T, N>> : std::true_type {};

template <class C, size_t _Size>
struct _getType<std::array<C, _Size>> : reflTypeDefault_ {
static constexpr REFType TYPE = REFType::Array;
static constexpr REFType TYPE = _getType<C>::TYPE;
static constexpr JenHash Hash() { return _getType<C>::Hash(); }
static constexpr size_t SIZE = sizeof(std::array<C, _Size>);
static constexpr size_t SUBSIZE = sizeof(C);
static constexpr REFType SUBTYPE = _getType<C>::TYPE;
static constexpr uint16 NUMITEMS = _Size;
using child_type = C;
};
321 changes: 32 additions & 289 deletions include/spike/reflect/detail/reflector.inl
Original file line number Diff line number Diff line change
Expand Up @@ -3,211 +3,52 @@ inline ReflectedInstance Reflector::GetReflectedInstance() {
return const_cast<const Reflector *>(this)->GetReflectedInstance();
}

inline const ReflType *Reflector::GetReflectedType(size_t ID) const {
const reflectorStatic *inst = GetReflectedInstance().rfStatic;

if (ID >= inst->nTypes)
return nullptr;

return inst->types + ID;
}

inline Reflector::ErrorType
Reflector::SetReflectedValue(JenHash hash, std::string_view value) {
const ReflType *reflValue = GetReflectedType(hash);

if (!reflValue)
return Reflector::ErrorType::InvalidDestination;

return SetReflectedValue(*reflValue, value);
}

inline Reflector::ErrorType
Reflector::SetReflectedValue(size_t id, std::string_view value) {
const ReflType *reflValue = GetReflectedType(id);

if (!reflValue)
return Reflector::ErrorType::InvalidDestination;

return SetReflectedValue(*reflValue, value);
}

inline Reflector::ErrorType Reflector::SetReflectedValue(JenHash hash,
std::string_view value,
size_t subID) {
const ReflType *reflValue = GetReflectedType(hash);

if (!reflValue)
return Reflector::ErrorType::InvalidDestination;

switch (reflValue->type) {
case REFType::Array:
case REFType::Vector:
case REFType::ArrayClass:
case REFType::EnumFlags:
return SetReflectedValue(*reflValue, value, subID);
default:
return ErrorType::InvalidDestination;
}
}

inline Reflector::ErrorType
Reflector::SetReflectedValue(size_t id, std::string_view value, size_t subID) {
const ReflType *reflValue = GetReflectedType(id);

if (!reflValue)
return Reflector::ErrorType::InvalidDestination;

switch (reflValue->type) {
case REFType::Array:
case REFType::Vector:
case REFType::ArrayClass:
case REFType::EnumFlags:
return SetReflectedValue(*reflValue, value, subID);
default:
return ErrorType::InvalidDestination;
}
}

inline Reflector::ErrorType Reflector::SetReflectedValue(JenHash hash,
std::string_view value,
size_t subID,
size_t element) {
const ReflType *reflValue = GetReflectedType(hash);

if (!reflValue || !IsArray(hash))
return Reflector::ErrorType::InvalidDestination;

return SetReflectedValue(*reflValue, value, subID, element);
}

inline Reflector::ErrorType Reflector::SetReflectedValue(size_t id,
std::string_view value,
size_t subID,
size_t element) {
const ReflType *reflValue = GetReflectedType(id);

if (!reflValue || !IsArray(id))
return Reflector::ErrorType::InvalidDestination;

return SetReflectedValue(*reflValue, value, subID, element);
}

inline Reflector::ErrorType
Reflector::SetReflectedValueInt(JenHash hash, int64 value, size_t subID) {
const ReflType *reflValue = GetReflectedType(hash);

if (!reflValue)
return Reflector::ErrorType::InvalidDestination;

return SetReflectedValueInt(*reflValue, value, subID);
}

inline Reflector::ErrorType
Reflector::SetReflectedValueInt(size_t id, int64 value, size_t subID) {
const ReflType *reflValue = GetReflectedType(id);

if (!reflValue)
return Reflector::ErrorType::InvalidDestination;

return SetReflectedValueInt(*reflValue, value, subID);
}

inline Reflector::ErrorType
Reflector::SetReflectedValueUInt(JenHash hash, uint64 value, size_t subID) {
const ReflType *reflValue = GetReflectedType(hash);

if (!reflValue)
return Reflector::ErrorType::InvalidDestination;

return SetReflectedValueUInt(*reflValue, value, subID);
}

inline Reflector::ErrorType
Reflector::SetReflectedValueUInt(size_t id, uint64 value, size_t subID) {
const ReflType *reflValue = GetReflectedType(id);

if (!reflValue)
return Reflector::ErrorType::InvalidDestination;

return SetReflectedValueUInt(*reflValue, value, subID);
}

inline Reflector::ErrorType
Reflector::SetReflectedValueFloat(JenHash hash, double value, size_t subID) {
const ReflType *reflValue = GetReflectedType(hash);

if (!reflValue)
return Reflector::ErrorType::InvalidDestination;

return SetReflectedValueFloat(*reflValue, value, subID);
}

inline Reflector::ErrorType
Reflector::SetReflectedValueFloat(size_t id, double value, size_t subID) {
const ReflType *reflValue = GetReflectedType(id);

if (!reflValue)
return Reflector::ErrorType::InvalidDestination;

return SetReflectedValueFloat(*reflValue, value, subID);
}

inline size_t Reflector::GetNumReflectedValues() const {
inline size_t Reflector::NumReflectedValues() const {
return GetReflectedInstance().rfStatic->nTypes;
}

inline std::string Reflector::GetReflectedValue(JenHash hash) const {
const ReflType *found = GetReflectedType(hash);

if (!found)
return "";

return GetReflectedValue(*found);
inline std::string_view Reflector::ClassName() const {
return GetReflectedInstance().rfStatic->className;
}

inline std::string Reflector::GetReflectedValue(JenHash hash,
size_t subID) const {
const ReflType *found = GetReflectedType(hash);
inline ReflectorMember Reflector::operator[](size_t ID) const {
ReflectedInstance inst = GetReflectedInstance();

if (!found)
return "";
if (ID >= inst.rfStatic->nTypes) {
throw std::out_of_range("Reflected member index is out of range");
}

return GetReflectedValue(*found, subID);
return {inst, ID};
}

inline std::string Reflector::GetReflectedValue(JenHash hash, size_t subID,
size_t element) const {
const ReflType *found = GetReflectedType(hash);

if (!found)
return "";
inline bool ReflectorMember::IsReflectedSubClass() const {
if (!data) {
return false;
}
const ReflType fl = data.rfStatic->types[id];

return GetReflectedValue(*found, subID, element);
return fl.type == REFType::Class || fl.type == REFType::BitFieldClass ||
(IsArray() && (fl.asArray.type == REFType::Class ||
fl.asArray.type == REFType::BitFieldClass));
}

inline ReflectedInstance Reflector::GetReflectedSubClass(JenHash hash,
size_t subID) const {
const ReflType *found = GetReflectedType(hash);

if (!found)
return {};

return GetReflectedSubClass(*found, subID);
}
inline bool ReflectorMember::IsArray() const {
if (!data) {
return false;
}
const ReflType fl = data.rfStatic->types[id];

inline ReflectedInstance Reflector::GetReflectedSubClass(JenHash hash,
size_t subID) {
return const_cast<const Reflector *>(this)->GetReflectedSubClass(hash, subID);
return !(fl.container == REFContainer::None ||
fl.container == REFContainer::Pointer);
}

inline Reflector::KVPair
Reflector::GetReflectedPair(size_t id, const KVPairFormat &settings) const {
if (id >= GetNumReflectedValues())
return {};

inline ReflectorMember::KVPair
ReflectorMember::ReflectedPair(KVPairFormat settings) const {
KVPair retval;
const auto refInt = GetReflectedInstance().rfStatic;
if (!data) {
return retval;
}
const auto refInt = data.rfStatic;

if (settings.aliasName && refInt->typeAliases && refInt->typeAliases[id]) {
retval.name = refInt->typeAliases[id];
Expand All @@ -216,113 +57,15 @@ Reflector::GetReflectedPair(size_t id, const KVPairFormat &settings) const {
}

if (settings.formatValue && refInt->typeDescs[id].part1) {
retval.value = refInt->typeDescs[id].part1 + (' ' + GetReflectedValue(id));
retval.value = refInt->typeDescs[id].part1 + (' ' + ReflectedValue());

if (refInt->typeDescs[id].part2) {
retval.value += ' ';
retval.value += refInt->typeDescs[id].part2;
}
} else {
retval.value = GetReflectedValue(id);
retval.value = ReflectedValue();
}

return retval;
}

inline Reflector::KVPair
Reflector::GetReflectedPair(JenHash hash, const KVPairFormat &settings) const {
const ReflType *found = GetReflectedType(hash);

if (!found)
return {};

return GetReflectedPair(found->index, settings);
}

inline std::string_view Reflector::GetClassName() const {
return GetReflectedInstance().rfStatic->className;
}

inline bool Reflector::IsReflectedSubClass(JenHash hash) const {
const ReflType *found = GetReflectedType(hash);

if (!found)
return false;

return IsReflectedSubClass(found->index);
}

inline bool Reflector::IsReflectedSubClass(size_t id) const {
if (id >= GetNumReflectedValues())
return false;

const ReflType fl = GetReflectedInstance().rfStatic->types[id];

return fl.type == REFType::Class || fl.type == REFType::BitFieldClass ||
(IsArray(fl.index) && (fl.asArray.type == REFType::Class ||
fl.asArray.type == REFType::BitFieldClass));
}

inline bool Reflector::IsArray(JenHash hash) const {
const ReflType *found = GetReflectedType(hash);

if (!found)
return false;

return found->type == REFType::Array || found->type == REFType::ArrayClass;
}

inline bool Reflector::IsArray(size_t id) const {
if (id >= GetNumReflectedValues())
return false;

const ReflType fl = GetReflectedInstance().rfStatic->types[id];

return fl.type == REFType::Array || fl.type == REFType::ArrayClass;
}

inline std::string Reflector::GetReflectedValue(size_t id) const {
if (id >= GetNumReflectedValues())
return "";

auto inst = GetReflectedInstance();
const ReflType &reflValue = inst.rfStatic->types[id];
return GetReflectedValue(reflValue);
}

inline std::string Reflector::GetReflectedValue(size_t id, size_t subID) const {
if (id >= GetNumReflectedValues())
return "";

auto inst = GetReflectedInstance();
const ReflType &reflValue = inst.rfStatic->types[id];
return GetReflectedValue(reflValue, subID);
}

inline std::string Reflector::GetReflectedValue(size_t id, size_t subID,
size_t element) const {
if (id >= GetNumReflectedValues() || !IsArray(id))
return "";

auto inst = GetReflectedInstance();
const ReflType &reflValue = inst.rfStatic->types[id];
return GetReflectedValue(reflValue, subID, element);
}

inline ReflectedInstance Reflector::GetReflectedSubClass(size_t id,
size_t subID) const {
if (id >= GetNumReflectedValues())
return {};

auto inst = GetReflectedInstance();
const ReflType &reflValue = inst.rfStatic->types[id];
return GetReflectedSubClass(reflValue, subID);
}

inline ReflectedInstance Reflector::GetReflectedSubClass(ReflType type, size_t subID) {
return const_cast<const Reflector *>(this)->GetReflectedSubClass(type, subID);
}

inline ReflectedInstance Reflector::GetReflectedSubClass(size_t id, size_t subID) {
return const_cast<const Reflector *>(this)->GetReflectedSubClass(id, subID);
}
Loading

0 comments on commit ac96aee

Please sign in to comment.