add src/ikarus subdir and make names unique for objects per scope

Signed-off-by: Folling <mail@folling.io>
This commit is contained in:
folling 2024-01-30 09:31:08 +01:00 committed by Folling
parent ced123b628
commit 9f943cc6a2
Signed by: folling
SSH key fingerprint: SHA256:S9qEx5WCFFLK49tE/LKnKuJYM5sw+++Dn6qJbbyxnCY
51 changed files with 590 additions and 735 deletions

View file

@ -1,120 +0,0 @@
#pragma once
#include <ranges>
#include <boost/container/small_vector.hpp>
#include <cppbase/templates.hpp>
template<typename V>
typename V::DataType const * ikarus_value_base_get(V * value, size_t idx) {
if (auto * data =
boost::variant2::get_if<boost::container::small_vector<typename V::DataType, IkarusValue::SMALL_VEC_VALUE_SIZE>>(&value->data);
data != nullptr) {
return &(*data)[idx];
}
return nullptr;
}
template<typename V>
size_t ikarus_value_base_get_size(V const * value) {
if (auto * data =
boost::variant2::get_if<boost::container::small_vector<typename V::DataType, IkarusValue::SMALL_VEC_VALUE_SIZE>>(&value->data);
data != nullptr) {
return data->size();
}
return 0;
}
template<typename V>
void ikarus_value_base_set(V * value, size_t idx, typename V::DataType new_data) {
if (auto * data =
boost::variant2::get_if<boost::container::small_vector<typename V::DataType, IkarusValue::SMALL_VEC_VALUE_SIZE>>(&value->data);
data != nullptr) {
(*data)[idx] = new_data;
}
}
template<typename V>
void ikarus_value_base_remove(V * value, size_t idx) {
if (auto * data =
boost::variant2::get_if<boost::container::small_vector<typename V::DataType, IkarusValue::SMALL_VEC_VALUE_SIZE>>(&value->data);
data != nullptr) {
data->erase(data->begin() + idx);
}
}
template<typename V>
void ikarus_value_base_insert(V * value, size_t idx, typename V::DataType new_data) {
if (auto * data =
boost::variant2::get_if<boost::container::small_vector<typename V::DataType, IkarusValue::SMALL_VEC_VALUE_SIZE>>(&value->data);
data != nullptr) {
data->insert(data->begin() + idx, new_data);
}
}
template<typename V>
void ikarus_value_base_clear(V * value) {
if (auto * data =
boost::variant2::get_if<boost::container::small_vector<typename V::DataType, IkarusValue::SMALL_VEC_VALUE_SIZE>>(&value->data);
data != nullptr) {
data->clear();
}
}
template<typename V>
bool ikarus_value_base_is_undefined(V const * value) {
return boost::variant2::holds_alternative<boost::variant2::monostate>(value->data);
}
template<typename V>
void ikarus_value_base_set_undefined(V * value, bool undefined) {
if (undefined) {
value->data = boost::variant2::monostate{};
} else {
value->data = boost::container::small_vector<typename V::DataType, IkarusValue::SMALL_VEC_VALUE_SIZE>{};
}
}
template<typename V, std::invocable<typename V::DataType> F>
char const * ikarus_value_base_to_string(V const * value, F transformer) {
return boost::variant2::visit(
cppbase::overloaded{
[](boost::variant2::monostate const &) -> char const * { return nullptr; },
[&transformer](auto const & data) -> char const * {
auto buffer = fmt::memory_buffer{};
fmt::format_to(
std::back_inserter(buffer),
"{}",
fmt::join(data | std::views::transform(std::forward<F>(transformer)), ", ")
);
return buffer.data();
}
},
value->data
);
}
template<typename V>
bool ikarus_value_base_is_equal(V const * lhs, V const * rhs) {
return lhs->data == rhs->data;
}
template<typename V>
V * ikarus_value_base_copy(V const * value) {
return new V{*value};
}
template<typename V>
struct IkarusValue * ikarus_value_base_to_value(V * value) {
return static_cast<IkarusValue *>(value);
}
template<typename V>
struct IkarusValue const * ikarus_value_base_to_value_const(V const * value) {
return static_cast<IkarusValue const *>(value);
}