implement IkarusPropertySource and switch to cppbase::overloaded
Signed-off-by: Folling <mail@folling.io>
This commit is contained in:
parent
700d9a92f9
commit
8fa56decd0
10 changed files with 90 additions and 50 deletions
|
|
@ -3,9 +3,10 @@
|
|||
#include <string>
|
||||
|
||||
#include <boost/container/small_vector.hpp>
|
||||
#include <boost/functional/overloaded_function.hpp>
|
||||
|
||||
// required for header-only inclusion
|
||||
#include "cppbase/templates.hpp"
|
||||
|
||||
#include <boost/json/src.hpp>
|
||||
|
||||
#include <ikarus/objects/properties/property_type.h>
|
||||
|
|
@ -43,7 +44,7 @@ cppbase::Result<IkarusValue *, IkarusValue::FromJsonError> IkarusValue::from_jso
|
|||
ret->data = boost::variant2::monostate{};
|
||||
} else {
|
||||
auto res = boost::json::try_value_to<
|
||||
boost::container::small_vector<typename T::data_type, IkarusValue::SMALL_VEC_VALUE_SIZE>>(*data);
|
||||
boost::container::small_vector<typename T::DataType, IkarusValue::SMALL_VEC_VALUE_SIZE>>(*data);
|
||||
|
||||
if (res.has_error()) {
|
||||
return cppbase::err(FromJsonError{});
|
||||
|
|
@ -75,21 +76,21 @@ cppbase::Result<IkarusValue *, IkarusValue::FromJsonError> IkarusValue::from_jso
|
|||
|
||||
boost::json::value IkarusValue::to_json() const {
|
||||
auto type = boost::variant2::visit(
|
||||
boost::make_overloaded_function(
|
||||
cppbase::overloaded{
|
||||
[]([[maybe_unused]] IkarusToggleValue const * value) { return IkarusPropertyType_Toggle; },
|
||||
[]([[maybe_unused]] IkarusNumberValue const * value) { return IkarusPropertyType_Number; },
|
||||
[]([[maybe_unused]] IkarusTextValue const * value) { return IkarusPropertyType_Text; }
|
||||
),
|
||||
},
|
||||
data
|
||||
);
|
||||
|
||||
auto data_json = boost::variant2::visit(
|
||||
[]<typename T>(T const * value) -> boost::json::value {
|
||||
return boost::variant2::visit(
|
||||
boost::make_overloaded_function(
|
||||
cppbase::overloaded{
|
||||
[]([[maybe_unused]] boost::variant2::monostate const& data) -> boost::json::value { return nullptr; },
|
||||
[](auto const& data) -> boost::json::value { return boost::json::value_from(data); }
|
||||
),
|
||||
},
|
||||
value->data
|
||||
);
|
||||
},
|
||||
|
|
@ -110,11 +111,11 @@ void ikarus_value_visit(
|
|||
void * data
|
||||
) {
|
||||
boost::variant2::visit(
|
||||
boost::make_overloaded_function(
|
||||
cppbase::overloaded{
|
||||
[toggle_visitor, data](IkarusToggleValue * toggle_value) { toggle_visitor(toggle_value, data); },
|
||||
[number_visitor, data](IkarusNumberValue * number_value) { number_visitor(number_value, data); },
|
||||
[text_visitor, data](IkarusTextValue * text_value) { text_visitor(text_value, data); }
|
||||
),
|
||||
},
|
||||
value->data
|
||||
);
|
||||
}
|
||||
|
|
@ -127,11 +128,11 @@ void ikarus_value_visit_const(
|
|||
void * data
|
||||
) {
|
||||
boost::variant2::visit(
|
||||
boost::make_overloaded_function(
|
||||
cppbase::overloaded{
|
||||
[toggle_visitor, data](IkarusToggleValue const * toggle_value) { toggle_visitor(toggle_value, data); },
|
||||
[number_visitor, data](IkarusNumberValue const * number_value) { number_visitor(number_value, data); },
|
||||
[text_visitor, data](IkarusTextValue const * text_value) { text_visitor(text_value, data); }
|
||||
),
|
||||
},
|
||||
value->data
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue