Merge remote-tracking branch 'origin/v0.8.0' into tfk-rocksdb-storage

This commit is contained in:
Thomas Krijnen
2025-08-26 10:17:57 +02:00
1179 changed files with 47255 additions and 16166 deletions
+25 -5
View File
@@ -119,7 +119,7 @@ public:
using TypesTuple = ::impl::MapTypes_t<Types...>;
VariantArray(size_t size)
: size_and_indices_(new uint8_t[size + 1])
: size_and_indices_(size ? new uint8_t[size + 1] : nullptr)
, storage_(size ? new StorageType[size] : nullptr)
{
if (size) {
@@ -161,7 +161,7 @@ public:
void set(std::size_t index, T&& value) {
using U = std::decay_t<T>;
static_assert(::impl::TypeIndex_v<U, Types...> < sizeof...(Types), "Type not supported by variant");
if (index >= size_and_indices_[0]) {
if (index >= size()) {
throw std::out_of_range("Index out of range");
}
@@ -181,12 +181,22 @@ public:
free_();
}
std::size_t index(std::size_t index) const noexcept {
std::size_t index(std::size_t index) const {
if (index >= size()) {
throw IfcParse::IfcException(
"Index " + std::to_string(index) + " is out of range for variant of size " + std::to_string(size())
);
}
return size_and_indices_[index + 1];
}
template<typename T>
T& get(std::size_t index) {
if (index >= size()) {
throw IfcParse::IfcException(
"Index " + std::to_string(index) + " is out of range for variant of size " + std::to_string(size())
);
}
if (!has<T>(index)) {
throw std::bad_cast();
}
@@ -200,11 +210,16 @@ public:
template<typename T>
bool has(std::size_t index) const {
return size_and_indices_[index + 1] == ::impl::TypeIndex<T, Types...>::value;
return index < size() && size_and_indices_[index + 1] == ::impl::TypeIndex<T, Types...>::value;
}
template<typename T>
const T& get(std::size_t index) const {
if (index >= size()) {
throw IfcParse::IfcException(
"Index " + std::to_string(index) + " is out of range for variant of size " + std::to_string(size())
);
}
if (size_and_indices_[index + 1] != ::impl::TypeIndex<T, Types...>::value) {
// @todo this IfcException is silly. Figure out what
// to do, but at the moment it is specifically caught
@@ -224,6 +239,11 @@ public:
template<typename Visitor>
auto apply_visitor(Visitor&& visitor, std::size_t index) const {
if (index >= size()) {
throw IfcParse::IfcException(
"Index " + std::to_string(index) + " is out of range for variant of size " + std::to_string(size())
);
}
return apply_visitor_impl(std::forward<Visitor>(visitor), index, std::integral_constant<std::size_t, sizeof...(Types)>{});
}
@@ -305,4 +325,4 @@ private:
}
};
#endif
#endif