• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PredatorCZ / PreCore / 461

pending completion
461

push

github-actions-ci

PredatorCZ
update readme

3204 of 6096 relevant lines covered (52.56%)

354.05 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.71
/include/spike/reflect/reflector.hpp
1
/*  Contains macros/classes for reflection of classes/enums
2

3
    Copyright 2018-2023 Lukas Cone
4

5
    Licensed under the Apache License, Version 2.0 (the "License");
6
    you may not use this file except in compliance with the License.
7
    You may obtain a copy of the License at
8

9
        http://www.apache.org/licenses/LICENSE-2.0
10

11
    Unless required by applicable law or agreed to in writing, software
12
    distributed under the License is distributed on an "AS IS" BASIS,
13
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
    See the License for the specific language governing permissions and
15
    limitations under the License.
16
*/
17

18
#pragma once
19
#include "spike/util/macroLoop.hpp"
20
#include "spike/util/supercore.hpp"
21

22
#include "detail/reflector_class.hpp"
23
#include "detail/reflector_enum.hpp"
24
#include "detail/reflector_type.hpp"
25

26
class Reflector {
27
  friend class ReflectorFriend;
28

29
public:
30
  struct KVPairFormat {
31
    bool aliasName = false;
32
    bool formatValue = false;
33

34
    constexpr KVPairFormat() {}
152✔
35
  };
36

37
  struct KVPair {
583✔
38
    std::string_view name;
39
    std::string value;
40
  };
41

42
  enum class ErrorType {
43
    None,
44
    SignMismatch,       // A singed number is assigned to an unsigned.
45
    OutOfRange,         // A number greater than destination type can hold.
46
    InvalidFormat,      // Wrong format of input provided.
47
    InvalidDestination, // Destination not found.
48
    EmptyInput,         // Input string was empty.
49
    ShortInput,         // Input string have insufficient number of elements.
50
  };
51

52
  virtual ~Reflector() = default;
53

54
  size_t GetNumReflectedValues() const;
55
  std::string_view GetClassName() const;
56

57
  bool IsReflectedSubClass(JenHash hashName) const;
58
  bool IsReflectedSubClass(size_t id) const;
59

60
  bool IsArray(JenHash hashName) const;
61
  bool IsArray(size_t id) const;
62

63
  // clang-format off
64
  ErrorType SetReflectedValue(size_t id, std::string_view  value);
65
  ErrorType SetReflectedValue(JenHash hashName, std::string_view  value);
66

67
  ErrorType SetReflectedValue(size_t id, std::string_view  value, size_t subID);
68
  ErrorType SetReflectedValue(JenHash hashName, std::string_view  value, size_t subID);
69

70
  ErrorType SetReflectedValue(size_t id, std::string_view  value, size_t subID, size_t element);
71
  ErrorType SetReflectedValue(JenHash hashName, std::string_view  value, size_t subID, size_t element);
72

73
  ErrorType SetReflectedValueInt(JenHash hashName, int64 value, size_t subID = 0);
74
  ErrorType SetReflectedValueInt(size_t id, int64 value, size_t subID = 0);
75

76
  ErrorType SetReflectedValueUInt(JenHash hashName, uint64 value, size_t subID = 0);
77
  ErrorType SetReflectedValueUInt(size_t id, uint64 value, size_t subID = 0);
78

79
  ErrorType SetReflectedValueFloat(JenHash hashName, double value, size_t subID = 0);
80
  ErrorType SetReflectedValueFloat(size_t id, double value, size_t subID = 0);
81

82
  std::string PC_EXTERN GetReflectedValue(size_t id) const;
83
  std::string GetReflectedValue(JenHash hashName) const;
84

85
  std::string PC_EXTERN GetReflectedValue(size_t id, size_t subID) const;
86
  std::string GetReflectedValue(JenHash hashName, size_t subID) const;
87

88
  std::string PC_EXTERN GetReflectedValue(size_t id, size_t subID, size_t element) const;
89
  std::string GetReflectedValue(JenHash hashName, size_t subID, size_t element) const;
90

91
  ReflectedInstance GetReflectedSubClass(JenHash hashName, size_t subID = 0) const;
92
  ReflectedInstance PC_EXTERN GetReflectedSubClass(size_t id, size_t subID = 0) const;
93

94
  ReflectedInstance GetReflectedSubClass(JenHash hashName, size_t subID = 0);
95
  ReflectedInstance PC_EXTERN GetReflectedSubClass(size_t id, size_t subID = 0);
96

97
  KVPair GetReflectedPair(size_t id, const KVPairFormat &settings = {}) const;
98
  KVPair GetReflectedPair(JenHash hashName, const KVPairFormat &settings = {}) const;
99

100
protected:
101
  const ReflType PC_EXTERN *GetReflectedType(JenHash hashName) const;
102
  const ReflType *GetReflectedType(size_t ID) const;
103
  ErrorType PC_EXTERN SetReflectedValue(ReflType type, std::string_view  value);
104
  ErrorType PC_EXTERN SetReflectedValue(ReflType type, std::string_view  value, size_t subID);
105
  ErrorType PC_EXTERN SetReflectedValue(ReflType type, std::string_view  value, size_t subID, size_t element);
106
  ErrorType PC_EXTERN SetReflectedValueUInt(ReflType type, uint64 value, size_t subID = 0);
107
  ErrorType PC_EXTERN SetReflectedValueInt(ReflType type, int64 value, size_t subID = 0);
108
  ErrorType PC_EXTERN SetReflectedValueFloat(ReflType type, double value, size_t subID = 0);
109
  // clang-format on
110
private:
111
  virtual ReflectedInstance GetReflectedInstance() const = 0;
112
  ReflectedInstance GetReflectedInstance();
113
};
114

115
template <class C> class ReflectorWrap : public Reflector {
2✔
116
  ReflectedInstance GetReflectedInstance() const override {
61✔
117
    return {GetReflectedClass<std::decay_t<C>>(), &data};
61✔
118
  }
119

33✔
120
public:
33✔
121
  C &data;
122
  ReflectorWrap(C *_data) : data(*_data) {}
28✔
123
  ReflectorWrap(C &_data) : data(_data) {}
28✔
124
  ReflectorWrap() = delete;
125
};
×
126

×
127
class ReflectorPureWrap : public Reflector {
196✔
128
  ReflectedInstance GetReflectedInstance() const override { return data; }
1,120✔
129

2✔
130
public:
131
  ReflectedInstance &data;
132
  ReflectorPureWrap(ReflectedInstance *_data) : data(*_data) {}
133
  ReflectorPureWrap(ReflectedInstance &_data) : data(_data) {}
200✔
134
  ReflectorPureWrap() = delete;
112✔
135
};
×
136

137
template <class C> class ReflectorBase : public Reflector {
4✔
138
public:
139
  ReflectedInstance GetReflectedInstance() const override {
2,306✔
140
    return {GetReflectedClass<C>(), {static_cast<const C *>(this)}};
2,301✔
141
  }
142
};
143

3✔
144
#include "detail/reflector.inl"
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc