implement IkarusPropertySource and switch to cppbase::overloaded
Signed-off-by: Folling <mail@folling.io>
This commit is contained in:
parent
ab250c00ae
commit
7be1675180
10 changed files with 90 additions and 50 deletions
|
|
@ -1,16 +1,15 @@
|
|||
#pragma once
|
||||
|
||||
#include <concepts>
|
||||
#include <ranges>
|
||||
|
||||
#include <boost/bind/bind.hpp>
|
||||
#include <cppbase/templates.hpp>
|
||||
|
||||
#include <boost/container/small_vector.hpp>
|
||||
#include <boost/functional/overloaded_function.hpp>
|
||||
|
||||
template<typename V>
|
||||
typename V::data_type const * ikarus_value_base_get(V * value, size_t idx) {
|
||||
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::data_type, IkarusValue::SMALL_VEC_VALUE_SIZE>>(
|
||||
boost::variant2::get_if<boost::container::small_vector<typename V::DataType, IkarusValue::SMALL_VEC_VALUE_SIZE>>(
|
||||
&value->data
|
||||
);
|
||||
data != nullptr) {
|
||||
|
|
@ -23,7 +22,7 @@ typename V::data_type const * ikarus_value_base_get(V * value, size_t idx) {
|
|||
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::data_type, IkarusValue::SMALL_VEC_VALUE_SIZE>>(
|
||||
boost::variant2::get_if<boost::container::small_vector<typename V::DataType, IkarusValue::SMALL_VEC_VALUE_SIZE>>(
|
||||
&value->data
|
||||
);
|
||||
data != nullptr) {
|
||||
|
|
@ -34,9 +33,9 @@ size_t ikarus_value_base_get_size(V const * value) {
|
|||
}
|
||||
|
||||
template<typename V>
|
||||
void ikarus_value_base_set(V * value, size_t idx, typename V::data_type new_data) {
|
||||
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::data_type, IkarusValue::SMALL_VEC_VALUE_SIZE>>(
|
||||
boost::variant2::get_if<boost::container::small_vector<typename V::DataType, IkarusValue::SMALL_VEC_VALUE_SIZE>>(
|
||||
&value->data
|
||||
);
|
||||
data != nullptr) {
|
||||
|
|
@ -47,7 +46,7 @@ void ikarus_value_base_set(V * value, size_t idx, typename V::data_type 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::data_type, IkarusValue::SMALL_VEC_VALUE_SIZE>>(
|
||||
boost::variant2::get_if<boost::container::small_vector<typename V::DataType, IkarusValue::SMALL_VEC_VALUE_SIZE>>(
|
||||
&value->data
|
||||
);
|
||||
data != nullptr) {
|
||||
|
|
@ -56,9 +55,9 @@ void ikarus_value_base_remove(V * value, size_t idx) {
|
|||
}
|
||||
|
||||
template<typename V>
|
||||
void ikarus_value_base_insert(V * value, size_t idx, typename V::data_type new_data) {
|
||||
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::data_type, IkarusValue::SMALL_VEC_VALUE_SIZE>>(
|
||||
boost::variant2::get_if<boost::container::small_vector<typename V::DataType, IkarusValue::SMALL_VEC_VALUE_SIZE>>(
|
||||
&value->data
|
||||
);
|
||||
data != nullptr) {
|
||||
|
|
@ -69,7 +68,7 @@ void ikarus_value_base_insert(V * value, size_t idx, typename V::data_type new_d
|
|||
template<typename V>
|
||||
void ikarus_value_base_clear(V * value) {
|
||||
if (auto * data =
|
||||
boost::variant2::get_if<boost::container::small_vector<typename V::data_type, IkarusValue::SMALL_VEC_VALUE_SIZE>>(
|
||||
boost::variant2::get_if<boost::container::small_vector<typename V::DataType, IkarusValue::SMALL_VEC_VALUE_SIZE>>(
|
||||
&value->data
|
||||
);
|
||||
data != nullptr) {
|
||||
|
|
@ -87,16 +86,16 @@ 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::data_type, IkarusValue::SMALL_VEC_VALUE_SIZE>{};
|
||||
value->data = boost::container::small_vector<typename V::DataType, IkarusValue::SMALL_VEC_VALUE_SIZE>{};
|
||||
}
|
||||
}
|
||||
|
||||
template<typename V, std::invocable<typename V::data_type> F>
|
||||
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(
|
||||
boost::make_overloaded_function(
|
||||
cppbase::overloaded {
|
||||
[](boost::variant2::monostate const&) -> char const * { return nullptr; },
|
||||
[&transformer](boost::container::small_vector<typename V::data_type, IkarusValue::SMALL_VEC_VALUE_SIZE> const& data
|
||||
[&transformer](auto const& data
|
||||
) -> char const * {
|
||||
auto buffer = fmt::memory_buffer{};
|
||||
|
||||
|
|
@ -108,7 +107,7 @@ char const * ikarus_value_base_to_string(V const * value, F transformer) {
|
|||
|
||||
return buffer.data();
|
||||
}
|
||||
),
|
||||
},
|
||||
value->data
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue