MCPcopy Create free account
hub / github.com/Norbyte/ositools / getInt

Method getInt

OsiInterface/PropertyMap.h:103–141  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

101 virtual void * toParent(void * obj) const = 0;
102
103 std::optional<int64_t> getInt(void * obj, std::string const & name, bool raw, bool throwError) const
104 {
105 auto prop = Properties.find(name);
106 if (prop == Properties.end()) {
107 if (Parent != nullptr) {
108 return Parent->getInt(toParent(obj), name, raw, throwError);
109 } else {
110 if (throwError) {
111 OsiError("Failed to get int '" << name << "': Property does not exist");
112 }
113 return {};
114 }
115 }
116
117 if (!raw && prop->second.GetInt) {
118 return prop->second.GetInt(obj);
119 }
120
121 if (!raw && !(prop->second.Flags & kPropRead)) {
122 OsiError("Failed to get int '" << name << "': Property not readable");
123 return {};
124 }
125
126 auto ptr = reinterpret_cast<std::uintptr_t>(obj) + prop->second.Offset;
127 switch (prop->second.Type) {
128 case PropertyType::kBool: return (int64_t)*reinterpret_cast<bool *>(ptr);
129 case PropertyType::kUInt8: return (int64_t)*reinterpret_cast<uint8_t *>(ptr);
130 case PropertyType::kInt16: return (int64_t)*reinterpret_cast<int16_t *>(ptr);
131 case PropertyType::kUInt16: return (int64_t)*reinterpret_cast<uint16_t *>(ptr);
132 case PropertyType::kInt32: return (int64_t)*reinterpret_cast<int32_t *>(ptr);
133 case PropertyType::kUInt32: return (int64_t)*reinterpret_cast<uint32_t *>(ptr);
134 case PropertyType::kInt64: return (int64_t)*reinterpret_cast<int64_t *>(ptr);
135 case PropertyType::kUInt64: return (int64_t)*reinterpret_cast<uint64_t *>(ptr);
136 case PropertyType::kFloat: return (int64_t)*reinterpret_cast<float *>(ptr);
137 default:
138 OsiError("Failed to get property '" << name << "': Property is not an int");
139 return {};
140 }
141 }
142
143 std::optional<float> getFloat(void * obj, std::string const & name, bool raw, bool throwError) const
144 {

Callers 2

OsirisPropertyMapGetRawFunction · 0.80
GetIntMethod · 0.80

Calls 1

GetIntMethod · 0.80

Tested by

no test coverage detected