make values capable of being a list & add boost
Signed-off-by: Folling <mail@folling.io>
This commit is contained in:
parent
43b53fd565
commit
2e41c36d84
16 changed files with 315 additions and 140 deletions
|
|
@ -87,24 +87,26 @@ IncludeCategories:
|
|||
Priority: 2
|
||||
- Regex: '^<[a-z0-9_]+>$'
|
||||
Priority: 3
|
||||
- Regex: '^<expected/.*>$'
|
||||
- Regex: '^<boost/.*>$'
|
||||
Priority: 4
|
||||
- Regex: '^<fmt/.*>$'
|
||||
- Regex: '^<expected/.*>$'
|
||||
Priority: 5
|
||||
- Regex: '^<nlohmann/.*>$'
|
||||
- Regex: '^<fmt/.*>$'
|
||||
Priority: 6
|
||||
- Regex: '^<range-v3/.*>$'
|
||||
- Regex: '^<nlohmann/.*>$'
|
||||
Priority: 7
|
||||
- Regex: '^<catch2/.*>$'
|
||||
- Regex: '^<range-v3/.*>$'
|
||||
Priority: 8
|
||||
- Regex: '^<unicode/.*>$'
|
||||
- Regex: '^<catch2/.*>$'
|
||||
Priority: 9
|
||||
- Regex: '^<cppbase/.*>$'
|
||||
- Regex: '^<unicode/.*>$'
|
||||
Priority: 10
|
||||
- Regex: '^<sqlitecpp/.*>$'
|
||||
- Regex: '^<cppbase/.*>$'
|
||||
Priority: 11
|
||||
- Regex: '^<ikarus/.*>$'
|
||||
- Regex: '^<sqlitecpp/.*>$'
|
||||
Priority: 12
|
||||
- Regex: '^<ikarus/.*>$'
|
||||
Priority: 13
|
||||
|
||||
IndentAccessModifiers: false
|
||||
IndentCaseBlocks: false
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ add_subdirectory(vendor)
|
|||
add_subdirectory(include)
|
||||
add_subdirectory(src)
|
||||
|
||||
find_package(Boost REQUIRED)
|
||||
|
||||
add_library(
|
||||
libikarus SHARED
|
||||
${INCLUDE_FILES}
|
||||
|
|
@ -34,6 +36,12 @@ target_link_libraries(
|
|||
libikarus PRIVATE
|
||||
cppbase
|
||||
sqlitecpp
|
||||
${Boost_LIBRARIES}
|
||||
)
|
||||
|
||||
target_include_directories(
|
||||
libikarus PRIVATE
|
||||
${Boost_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
if (LIBIKARUS_ENABLE_LINTS)
|
||||
|
|
|
|||
|
|
@ -78,6 +78,14 @@ IKA_API IkarusPropertyType ikarus_property_get_type(IkarusProperty const * prope
|
|||
/// \remark Must be freed using #ikarus_free.
|
||||
IKA_API struct IkarusPropertySource const * ikarus_property_get_source(IkarusProperty const * property);
|
||||
|
||||
/// \brief Gets the default value of a property.
|
||||
/// \param property The property to get the type info of.
|
||||
/// \pre \li Must not be null.
|
||||
/// \pre \li Must exist.
|
||||
/// \return The default value of the property or null if an error occurs.
|
||||
/// \remark Must be freed using #ikarus_free.
|
||||
IKA_API struct IkarusValue * ikarus_property_get_default_value(IkarusProperty const * property);
|
||||
|
||||
/// \brief Visits a property. Calling the appropriate function for the property's type.
|
||||
/// \param property The property to visit.
|
||||
/// \pre \li Must not be null.
|
||||
|
|
|
|||
|
|
@ -4,42 +4,57 @@
|
|||
/// \author Folling <folling@ikarus.world>
|
||||
|
||||
#include <ikarus/macros.h>
|
||||
#include <ikarus/stdtypes.h>
|
||||
|
||||
/// \addtogroup values Values
|
||||
/// @{
|
||||
|
||||
IKARUS_BEGIN_HEADER
|
||||
|
||||
/// \brief A true/false boolean-like value. For example "IsDead".
|
||||
/// \brief A true/false long doubleean-esque value. For example "Is Dead".
|
||||
struct IkarusNumberValue;
|
||||
|
||||
/// \brief Creates a number value from a long double.
|
||||
/// \param value The numeric value.
|
||||
/// \return The entity value.
|
||||
/// \brief Creates a number value from doubles.
|
||||
/// \param data The number data or null if you wish to clear the data.
|
||||
/// \details LibIkarus does not take ownership of this array.
|
||||
/// \param data_size The size of the data array or 0 if you wish to clear the data.
|
||||
/// \return The value.
|
||||
/// \remark Must be freed with #ikarus_free.
|
||||
IKA_API IkarusNumberValue * ikarus_number_value_create(long double value);
|
||||
IKA_API IkarusNumberValue * ikarus_number_value_create(long double * data, size_t data_size);
|
||||
|
||||
/// \brief Creates an indeterminate number value.
|
||||
/// \return The entity value.
|
||||
/// \return The value.
|
||||
/// \remark Must be freed with #ikarus_free.
|
||||
IKA_API IkarusNumberValue * ikarus_number_value_create_indeterminate();
|
||||
|
||||
/// \brief Fetches the underlying value of a number value.
|
||||
/// \param value The number value.
|
||||
/// \return The underlying value.
|
||||
/// \warning Undefined if the value is indeterminate.
|
||||
IKA_API long double ikarus_number_value_get(IkarusNumberValue const * value);
|
||||
|
||||
/// \brief Sets the value of a number value.
|
||||
/// \brief Fetches the underlying data of a number value.
|
||||
/// \details You may adjust the returned data as per your hearts desire.
|
||||
/// If you need to grow the data, use #ikarus_number_value_set with a new array.
|
||||
/// Just remember that IkarusValues are plain objects, so changing them won't affect any state.
|
||||
/// They will need to be submitted to other functions such as #ikarus_entity_set_value to have any effect.
|
||||
/// \param value The number value.
|
||||
/// \pre \li Must not be null.
|
||||
/// \param new_value The new value.
|
||||
IKA_API void ikarus_number_value_set(IkarusNumberValue * value, bool new_value);
|
||||
/// \param data_size_out An out-parameter for the size of the returned array.
|
||||
/// \remark Ignored if null.
|
||||
/// \return The underlying data. Owned by LibIkarus, most not be freed.
|
||||
/// \warning Undefined if the value is indeterminate.
|
||||
IKA_API long double * ikarus_number_value_get(IkarusNumberValue * value, size_t * data_size_out);
|
||||
|
||||
/// \see ikarus_number_value_get
|
||||
long double const * ikarus_number_value_get_const(IkarusNumberValue const * value, size_t * data_size_out);
|
||||
|
||||
/// \brief Sets the data of a number value.
|
||||
/// \param value The number value.
|
||||
/// \pre \li Must not be null.
|
||||
/// \param new_data The new data or null if you wish to clear the data.
|
||||
/// \details LibIkarus does not take ownership of this array.
|
||||
/// \param new_data_size The size of the new data array or 0 if you wish to clear the data.
|
||||
IKA_API void ikarus_number_value_set(IkarusNumberValue * value, long double * new_data, size_t new_data_size);
|
||||
|
||||
/// \brief Converts a number value to an entity value.
|
||||
/// \param number_value The number value to convert.
|
||||
/// \param value The number value to convert.
|
||||
/// \return The converted entity value.
|
||||
IKA_API struct IkarusValue * ikarus_number_value_to_value(IkarusNumberValue * number_value);
|
||||
IKA_API struct IkarusValue * ikarus_number_value_to_value(IkarusNumberValue * value);
|
||||
|
||||
IKARUS_END_HEADER
|
||||
|
||||
|
|
|
|||
|
|
@ -4,43 +4,57 @@
|
|||
/// \author Folling <folling@ikarus.world>
|
||||
|
||||
#include <ikarus/macros.h>
|
||||
#include <ikarus/stdtypes.h>
|
||||
|
||||
/// \addtogroup values Values
|
||||
/// @{
|
||||
|
||||
IKARUS_BEGIN_HEADER
|
||||
|
||||
/// \brief A true/false boolean-like value. For example "IsDead".
|
||||
/// \brief A true/false char const*ean-esque value. For example "Is Dead".
|
||||
struct IkarusTextValue;
|
||||
|
||||
/// \brief Creates a text value from a boolean.
|
||||
/// \param value The text value.
|
||||
/// \return The entity value.
|
||||
/// \brief Creates a text value from doubles.
|
||||
/// \param data The text data or null if you wish to clear the data.
|
||||
/// \details LibIkarus does not take ownership of this array.
|
||||
/// \param data_size The size of the data array or 0 if you wish to clear the data.
|
||||
/// \return The value.
|
||||
/// \remark Must be freed with #ikarus_free.
|
||||
IKA_API IkarusTextValue * ikarus_text_value_create(char const * value);
|
||||
IKA_API IkarusTextValue * ikarus_text_value_create(char const ** data, size_t data_size);
|
||||
|
||||
/// \brief Creates an indeterminate text value.
|
||||
/// \return The entity value.
|
||||
/// \return The value.
|
||||
/// \remark Must be freed with #ikarus_free.
|
||||
IKA_API IkarusTextValue * ikarus_text_value_create_indeterminate();
|
||||
|
||||
/// \brief Fetches the underlying value of a text value.
|
||||
/// \param value The text value.
|
||||
/// \return The underlying value.
|
||||
/// \warning Undefined if the value is indeterminate.
|
||||
/// \remark The value is owned by libikarus and must not be freed.
|
||||
IKA_API char const * ikarus_text_value_get_underlying(IkarusTextValue const * value);
|
||||
|
||||
/// \brief Sets the value of a text value.
|
||||
/// \brief Fetches the underlying data of a text value.
|
||||
/// \details You may adjust the returned data as per your hearts desire.
|
||||
/// If you need to grow the data, use #ikarus_text_value_set with a new array.
|
||||
/// Just remember that IkarusValues are plain objects, so changing them won't affect any state.
|
||||
/// They will need to be submitted to other functions such as #ikarus_entity_set_value to have any effect.
|
||||
/// \param value The text value.
|
||||
/// \pre \li Must not be null.
|
||||
/// \param new_value The new value.
|
||||
IKA_API void ikarus_text_value_set(IkarusTextValue * value, bool new_value);
|
||||
/// \param data_size_out An out-parameter for the size of the returned array.
|
||||
/// \remark Ignored if null.
|
||||
/// \return The underlying data. Owned by LibIkarus, most not be freed.
|
||||
/// \warning Undefined if the value is indeterminate.
|
||||
IKA_API char ** ikarus_text_value_get(IkarusTextValue * value, size_t * data_size_out);
|
||||
|
||||
/// \see ikarus_text_value_get
|
||||
char const * const * ikarus_text_value_get_const(IkarusTextValue const * value, size_t * data_size_out);
|
||||
|
||||
/// \brief Sets the data of a text value.
|
||||
/// \param value The text value.
|
||||
/// \pre \li Must not be null.
|
||||
/// \param new_data The new data or null if you wish to clear the data.
|
||||
/// \details LibIkarus does not take ownership of this array.
|
||||
/// \param new_data_size The size of the new data array or 0 if you wish to clear the data.
|
||||
IKA_API void ikarus_text_value_set(IkarusTextValue * value, char const ** new_data, size_t new_data_size);
|
||||
|
||||
/// \brief Converts a text value to an entity value.
|
||||
/// \param text_value The text value to convert.
|
||||
/// \param value The text value to convert.
|
||||
/// \return The converted entity value.
|
||||
IKA_API struct IkarusValue * ikarus_text_value_to_value(IkarusTextValue * text_value);
|
||||
IKA_API struct IkarusValue * ikarus_text_value_to_value(IkarusTextValue * value);
|
||||
|
||||
IKARUS_END_HEADER
|
||||
|
||||
|
|
|
|||
|
|
@ -4,42 +4,57 @@
|
|||
/// \author Folling <folling@ikarus.world>
|
||||
|
||||
#include <ikarus/macros.h>
|
||||
#include <ikarus/stdtypes.h>
|
||||
|
||||
/// \addtogroup values Values
|
||||
/// @{
|
||||
|
||||
IKARUS_BEGIN_HEADER
|
||||
|
||||
/// \brief A true/false boolean-like value. For example "IsDead".
|
||||
/// \brief A true/false boolean-esque value. For example "Is Dead".
|
||||
struct IkarusToggleValue;
|
||||
|
||||
/// \brief Creates a toggle value from a boolean.
|
||||
/// \param value The toggle value.
|
||||
/// \return The entity value.
|
||||
/// \brief Creates a toggle value from doubles.
|
||||
/// \param data The toggle data or null if you wish to clear the data.
|
||||
/// \details LibIkarus does not take ownership of this array.
|
||||
/// \param data_size The size of the data array or 0 if you wish to clear the data.
|
||||
/// \return The value.
|
||||
/// \remark Must be freed with #ikarus_free.
|
||||
IKA_API IkarusToggleValue * ikarus_toggle_value_create(bool value);
|
||||
IKA_API IkarusToggleValue * ikarus_toggle_value_create(bool * data, size_t data_size);
|
||||
|
||||
/// \brief Creates an indeterminate toggle value.
|
||||
/// \return The entity value.
|
||||
/// \return The value.
|
||||
/// \remark Must be freed with #ikarus_free.
|
||||
IKA_API IkarusToggleValue * ikarus_toggle_value_create_indeterminate();
|
||||
|
||||
/// \brief Fetches the underlying value of a toggle value.
|
||||
/// \param value The toggle value.
|
||||
/// \return The underlying value.
|
||||
/// \warning Undefined if the value is indeterminate.
|
||||
IKA_API bool ikarus_toggle_value_get(IkarusToggleValue const * value);
|
||||
|
||||
/// \brief Sets the value of a toggle value.
|
||||
/// \brief Fetches the underlying data of a toggle value.
|
||||
/// \details You may adjust the returned data as per your hearts desire.
|
||||
/// If you need to grow the data, use #ikarus_toggle_value_set with a new array.
|
||||
/// Just remember that IkarusValues are plain objects, so changing them won't affect any state.
|
||||
/// They will need to be submitted to other functions such as #ikarus_entity_set_value to have any effect.
|
||||
/// \param value The toggle value.
|
||||
/// \pre \li Must not be null.
|
||||
/// \param new_value The new value.
|
||||
IKA_API void ikarus_toggle_value_set(IkarusToggleValue * value, bool new_value);
|
||||
/// \param data_size_out An out-parameter for the size of the returned array.
|
||||
/// \remark Ignored if null.
|
||||
/// \return The underlying data. Owned by LibIkarus, most not be freed.
|
||||
/// \warning Undefined if the value is indeterminate.
|
||||
IKA_API bool * ikarus_toggle_value_get(IkarusToggleValue * value, size_t * data_size_out);
|
||||
|
||||
/// \see ikarus_toggle_value_get
|
||||
bool const * ikarus_toggle_value_get_const(IkarusToggleValue const * value, size_t * data_size_out);
|
||||
|
||||
/// \brief Sets the data of a toggle value.
|
||||
/// \param value The toggle value.
|
||||
/// \pre \li Must not be null.
|
||||
/// \param new_data The new data or null if you wish to clear the data.
|
||||
/// \details LibIkarus does not take ownership of this array.
|
||||
/// \param new_data_size The size of the new data array or 0 if you wish to clear the data.
|
||||
IKA_API void ikarus_toggle_value_set(IkarusToggleValue * value, bool * new_data, size_t new_data_size);
|
||||
|
||||
/// \brief Converts a toggle value to an entity value.
|
||||
/// \param toggle_value The toggle value to convert.
|
||||
/// \param value The toggle value to convert.
|
||||
/// \return The converted entity value.
|
||||
IKA_API struct IkarusValue * ikarus_toggle_value_to_value(IkarusToggleValue * toggle_value);
|
||||
IKA_API struct IkarusValue * ikarus_toggle_value_to_value(IkarusToggleValue * value);
|
||||
|
||||
IKARUS_END_HEADER
|
||||
|
||||
|
|
|
|||
|
|
@ -6,11 +6,14 @@
|
|||
#include <ikarus/macros.h>
|
||||
|
||||
/// \defgroup values Values
|
||||
/// \brief The values stored in entities.
|
||||
/// \brief The values of properties.
|
||||
/// \details Each entity has a value for each property it is associated with.
|
||||
/// The value is of the type specified by the property and constrained by the property's settings.
|
||||
/// A value may be indeterminate which means it is unknown or not specified.
|
||||
/// \see PropertyType PropertySettings
|
||||
/// These value classes represent plain objects. They are not associated with any entity.
|
||||
/// Each value may be indeterminate. \see IkarusProperty
|
||||
/// Values are stored as lists. If a property is "singular" then its value is a list of size 1.
|
||||
/// Values are typed, with types existing for each of the corresponding property types.
|
||||
/// When setting values for a property the type must match the property type and the value must be valid under the property's
|
||||
/// settings. \see PropertyType
|
||||
/// @{
|
||||
|
||||
IKARUS_BEGIN_HEADER
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
#include <persistence/function_context.hpp>
|
||||
#include <persistence/project.hpp>
|
||||
#include <sys/stat.h>
|
||||
#include <values/value.hpp>
|
||||
|
||||
IkarusProperty::IkarusProperty(IkarusProject * project, IkarusId id, Data data):
|
||||
IkarusObject{project, id},
|
||||
|
|
@ -121,6 +122,31 @@ IkarusPropertySource const * ikarus_property_get_source(IkarusProperty const * p
|
|||
}
|
||||
}
|
||||
|
||||
IkarusValue * ikarus_property_get_default_value(IkarusProperty const * property) {
|
||||
LOG_VERBOSE("fetching property default value");
|
||||
|
||||
LOG_VERBOSE("project={};property={}", property->get_project()->get_path().c_str(), property->get_id());
|
||||
|
||||
auto * ctx = property->get_project()->get_function_context();
|
||||
|
||||
VTRY(
|
||||
auto const value,
|
||||
property->get_project()
|
||||
->get_db()
|
||||
->query_one<int>("SELECT `default_value` FROM `properties` WHERE `id` = ?", property->get_id())
|
||||
.on_error([ctx](auto const& err) {
|
||||
ctx->set_error(
|
||||
fmt::format("failed to fetch property's default value: {}", err),
|
||||
true,
|
||||
IkarusErrorInfo_Source_SubSystem,
|
||||
IkarusErrorInfo_Type_SubSystem_Database
|
||||
);
|
||||
})
|
||||
);
|
||||
|
||||
return new IkarusValue(property->get_project(), value);
|
||||
}
|
||||
|
||||
void ikarus_property_visit(
|
||||
IkarusProperty * property,
|
||||
void (*toggle_property_visitor)(struct IkarusToggleProperty *, void *),
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
#include "toggle_property.hpp"
|
||||
|
||||
IkarusToggleProperty::IkarusToggleProperty(IkarusProject * project, IkarusId id):
|
||||
IkarusProperty{project, id, this} {
|
||||
IkarusProperty{project, id, this} {}
|
||||
|
||||
IkarusToggleProperty * ikarus_toggle_property_create(
|
||||
struct IkarusProject * project, char const * name, struct IkarusPropertySource * property_source
|
||||
) {
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
CREATE TABLE `objects`
|
||||
(
|
||||
`do_not_access_rowid_alias` INTEGER PRIMARY KEY,
|
||||
`object_type` INT NOT NULL,
|
||||
`id` INT GENERATED ALWAYS AS (`do_not_access_rowid_alias` | (`object_type` << 56)) VIRTUAL,
|
||||
`object_type` INT NOT NULL,
|
||||
`id` INT GENERATED ALWAYS AS (`do_not_access_rowid_alias` | (`object_type` << 56)
|
||||
) VIRTUAL,
|
||||
`name` TEXT NOT NULL,
|
||||
`information` TEXT NOT NULL
|
||||
) STRICT;
|
||||
|
|
@ -11,7 +12,7 @@ CREATE UNIQUE INDEX `object_id` ON `objects` (`id`);
|
|||
CREATE INDEX `object_type` ON `objects` (`object_type`);
|
||||
|
||||
CREATE
|
||||
VIRTUAL TABLE `objects_fts` USING fts5
|
||||
VIRTUAL TABLE `objects_fts` USING fts5
|
||||
(
|
||||
`name`,
|
||||
`information`,
|
||||
|
|
@ -23,7 +24,7 @@ CREATE
|
|||
"unicode61 remove_diacritics 2 tokenchars '-_'"
|
||||
);
|
||||
|
||||
CREATE TABLE `blueprints`
|
||||
CREATE TABLE `entities`
|
||||
(
|
||||
`id` INT,
|
||||
|
||||
|
|
@ -31,7 +32,7 @@ CREATE TABLE `blueprints`
|
|||
FOREIGN KEY (`id`) REFERENCES `objects` (`id`) ON DELETE CASCADE
|
||||
) WITHOUT ROWID, STRICT;
|
||||
|
||||
CREATE TABLE `entities`
|
||||
CREATE TABLE `blueprints`
|
||||
(
|
||||
`id` INT,
|
||||
|
||||
|
|
@ -69,7 +70,7 @@ CREATE INDEX `properties_type` ON `properties` (`type`);
|
|||
CREATE INDEX `properties_source` ON `properties` (`source`);
|
||||
|
||||
CREATE
|
||||
VIRTUAL TABLE `property_default_value_fts` USING fts5
|
||||
VIRTUAL TABLE `property_default_value_fts` USING fts5
|
||||
(
|
||||
`default_value`,
|
||||
content=
|
||||
|
|
@ -81,7 +82,7 @@ CREATE
|
|||
);
|
||||
|
||||
CREATE
|
||||
VIRTUAL TABLE `property_settings_fts` USING fts5
|
||||
VIRTUAL TABLE `property_settings_fts` USING fts5
|
||||
(
|
||||
`settings`,
|
||||
content=
|
||||
|
|
@ -104,7 +105,7 @@ CREATE TABLE `values`
|
|||
) WITHOUT ROWID, STRICT;
|
||||
|
||||
CREATE
|
||||
VIRTUAL TABLE `values_fts` USING fts5
|
||||
VIRTUAL TABLE `values_fts` USING fts5
|
||||
(
|
||||
`value`,
|
||||
content=
|
||||
|
|
|
|||
|
|
@ -2,25 +2,54 @@
|
|||
|
||||
#include <values/number_value.hpp>
|
||||
|
||||
IkarusNumberValue * ikarus_number_value_create(long double value) {
|
||||
return new IkarusNumberValue{value};
|
||||
IkarusNumberValue::IkarusNumberValue():
|
||||
IkarusValue{this} {}
|
||||
|
||||
boost::container::vector<long double>& IkarusNumberValue::get_value() {
|
||||
return _value;
|
||||
}
|
||||
|
||||
boost::container::vector<long double> const& IkarusNumberValue::get_value() const {
|
||||
return _value;
|
||||
}
|
||||
|
||||
IkarusNumberValue * ikarus_number_value_create(long double * data, size_t data_size) {
|
||||
auto * ret = new IkarusNumberValue{};
|
||||
|
||||
ikarus_number_value_set(ret, data, data_size);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
IkarusNumberValue * ikarus_number_value_create_indeterminate() {
|
||||
auto * ret = new IkarusNumberValue{0.0};
|
||||
auto * ret = new IkarusNumberValue{};
|
||||
ret->set_intermediate(true);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
long double ikarus_number_value_get(IkarusNumberValue const * value) {
|
||||
return value->get_value();
|
||||
long double * ikarus_number_value_get(IkarusNumberValue * value, size_t * data_size_out) {
|
||||
// NOLINTNEXTLINE(*-pro-type-const-cast)
|
||||
return const_cast<long double *>(ikarus_number_value_get_const(value, data_size_out));
|
||||
}
|
||||
|
||||
void ikarus_number_value_set(IkarusNumberValue * value, long double new_value) {
|
||||
value->set_value(new_value);
|
||||
long double const * ikarus_number_value_get_const(IkarusNumberValue const * value, size_t * data_size_out) {
|
||||
if (data_size_out != nullptr) {
|
||||
*data_size_out = value->get_value().size();
|
||||
}
|
||||
|
||||
return value->get_value().data();
|
||||
}
|
||||
|
||||
struct IkarusValue * ikarus_number_value_to_value(IkarusNumberValue * number_value) {
|
||||
return static_cast<IkarusValue *>(number_value);
|
||||
void ikarus_number_value_set(IkarusNumberValue * value, long double * new_data, size_t new_data_size) {
|
||||
value->get_value().reserve(new_data_size);
|
||||
|
||||
for (auto i = 0; i < new_data_size; ++i) {
|
||||
// NOLINTNEXTLINE(*-pro-bounds-pointer-arithmetic)
|
||||
value->get_value().emplace_back(new_data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
struct IkarusValue * ikarus_number_value_to_value(IkarusNumberValue * value) {
|
||||
return static_cast<IkarusValue *>(value);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <boost/container/vector.hpp>
|
||||
|
||||
#include <values/value.hpp>
|
||||
|
||||
/// \private
|
||||
struct IkarusNumberValue final : IkarusValue {
|
||||
public:
|
||||
explicit IkarusNumberValue(long double value):
|
||||
IkarusValue{this},
|
||||
_value{value} {}
|
||||
explicit IkarusNumberValue();
|
||||
|
||||
IkarusNumberValue(IkarusNumberValue const&) = default;
|
||||
IkarusNumberValue(IkarusNumberValue&&) = default;
|
||||
|
|
@ -18,14 +19,9 @@ public:
|
|||
~IkarusNumberValue() override = default;
|
||||
|
||||
public:
|
||||
[[nodiscard]] long double get_value() const {
|
||||
return _value;
|
||||
}
|
||||
|
||||
void set_value(long double value) {
|
||||
_value = value;
|
||||
}
|
||||
[[nodiscard]] boost::container::vector<long double>& get_value();
|
||||
[[nodiscard]] boost::container::vector<long double> const& get_value() const;
|
||||
|
||||
private:
|
||||
long double _value;
|
||||
boost::container::vector<long double> _value{};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,26 +1,55 @@
|
|||
#include "ikarus/values/text_value.h"
|
||||
|
||||
#include "text_value.hpp"
|
||||
#include <values/text_value.hpp>
|
||||
|
||||
IkarusTextValue * ikarus_text_value_create(char const * value) {
|
||||
return new IkarusTextValue{value};
|
||||
IkarusTextValue::IkarusTextValue():
|
||||
IkarusValue{this} {}
|
||||
|
||||
boost::container::vector<char const *>& IkarusTextValue::get_value() {
|
||||
return _value;
|
||||
}
|
||||
|
||||
boost::container::vector<char const *> const& IkarusTextValue::get_value() const {
|
||||
return _value;
|
||||
}
|
||||
|
||||
IkarusTextValue * ikarus_text_value_create(char const ** data, size_t data_size) {
|
||||
auto * ret = new IkarusTextValue{};
|
||||
|
||||
ikarus_text_value_set(ret, data, data_size);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
IkarusTextValue * ikarus_text_value_create_indeterminate() {
|
||||
auto * ret = new IkarusTextValue{""};
|
||||
auto * ret = new IkarusTextValue{};
|
||||
ret->set_intermediate(true);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
char const * ikarus_text_value_get(IkarusTextValue const * value) {
|
||||
char ** ikarus_text_value_get(IkarusTextValue * value, size_t * data_size_out) {
|
||||
// NOLINTNEXTLINE(*-pro-type-const-cast)
|
||||
return const_cast<char **>(ikarus_text_value_get_const(value, data_size_out));
|
||||
}
|
||||
|
||||
char const * const * ikarus_text_value_get_const(IkarusTextValue const * value, size_t * data_size_out) {
|
||||
if (data_size_out != nullptr) {
|
||||
*data_size_out = value->get_value().size();
|
||||
}
|
||||
|
||||
return value->get_value().data();
|
||||
}
|
||||
|
||||
void ikarus_text_value_set(IkarusTextValue * value, char const * new_value) {
|
||||
value->set_value(new_value);
|
||||
void ikarus_text_value_set(IkarusTextValue * value, char const ** new_data, size_t new_data_size) {
|
||||
value->get_value().reserve(new_data_size);
|
||||
|
||||
for (auto i = 0; i < new_data_size; ++i) {
|
||||
// NOLINTNEXTLINE(*-pro-bounds-pointer-arithmetic)
|
||||
value->get_value().emplace_back(new_data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
struct IkarusValue * ikarus_text_value_to_value(IkarusTextValue * text_value) {
|
||||
return static_cast<IkarusValue *>(text_value);
|
||||
struct IkarusValue * ikarus_text_value_to_value(IkarusTextValue * value) {
|
||||
return static_cast<IkarusValue *>(value);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,33 +1,28 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/container/vector.hpp>
|
||||
|
||||
#include <values/value.hpp>
|
||||
|
||||
/// \private
|
||||
struct IkarusTextValue final : IkarusValue {
|
||||
public:
|
||||
explicit IkarusTextValue(std::string value):
|
||||
IkarusValue{this},
|
||||
_value(std::move(value)) {}
|
||||
explicit IkarusTextValue();
|
||||
|
||||
IkarusTextValue(IkarusTextValue const&) = default;
|
||||
IkarusTextValue(IkarusTextValue&&) noexcept = default;
|
||||
IkarusTextValue(IkarusTextValue&&) = default;
|
||||
|
||||
IkarusTextValue& operator=(IkarusTextValue const&) = default;
|
||||
IkarusTextValue& operator=(IkarusTextValue&&) noexcept = default;
|
||||
IkarusTextValue& operator=(IkarusTextValue&&) = default;
|
||||
|
||||
~IkarusTextValue() override = default;
|
||||
|
||||
public:
|
||||
[[nodiscard]] std::string_view get_value() const noexcept {
|
||||
return _value;
|
||||
}
|
||||
|
||||
void set_value(std::string_view value) {
|
||||
_value = value;
|
||||
}
|
||||
[[nodiscard]] boost::container::vector<char const *>& get_value();
|
||||
[[nodiscard]] boost::container::vector<char const *> const& get_value() const;
|
||||
|
||||
private:
|
||||
std::string _value;
|
||||
boost::container::vector<char const *> _value{};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,26 +1,60 @@
|
|||
#include "ikarus/values/toggle_value.h"
|
||||
|
||||
#include "toggle_value.hpp"
|
||||
#include <values/toggle_value.hpp>
|
||||
|
||||
IkarusToggleValue * ikarus_toggle_value_create(bool value) {
|
||||
return new IkarusToggleValue{value};
|
||||
IkarusToggleValue::IkarusToggleValue():
|
||||
IkarusValue{this} {}
|
||||
|
||||
boost::container::vector<bool>& IkarusToggleValue::get_value() {
|
||||
return _value;
|
||||
}
|
||||
|
||||
boost::container::vector<bool> const& IkarusToggleValue::get_value() const {
|
||||
return _value;
|
||||
}
|
||||
|
||||
IkarusToggleValue * ikarus_toggle_value_create(bool * data, size_t data_size) {
|
||||
auto * ret = new IkarusToggleValue{};
|
||||
|
||||
ikarus_toggle_value_set(ret, data, data_size);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
IkarusToggleValue * ikarus_toggle_value_create_indeterminate() {
|
||||
auto * ret = new IkarusToggleValue{false};
|
||||
auto * ret = new IkarusToggleValue{};
|
||||
ret->set_intermediate(true);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool ikarus_toggle_value_get(IkarusToggleValue const * value) {
|
||||
return value->get_value();
|
||||
bool * ikarus_toggle_value_get(IkarusToggleValue * value, size_t * data_size_out) {
|
||||
// NOLINTNEXTLINE(*-pro-type-const-cast)
|
||||
return const_cast<bool *>(ikarus_toggle_value_get_const(value, data_size_out));
|
||||
}
|
||||
|
||||
void ikarus_toggle_value_set(IkarusToggleValue * value, bool new_value) {
|
||||
value->set_value(new_value);
|
||||
bool const * ikarus_toggle_value_get_const(IkarusToggleValue const * value, size_t * data_size_out) {
|
||||
if (data_size_out != nullptr) {
|
||||
*data_size_out = value->get_value().size();
|
||||
}
|
||||
|
||||
return value->get_value().data();
|
||||
}
|
||||
|
||||
struct IkarusValue * ikarus_toggle_value_to_value(IkarusToggleValue * toggle_value) {
|
||||
return static_cast<IkarusValue *>(toggle_value);
|
||||
void ikarus_toggle_value_set(IkarusToggleValue * value, bool * new_data, size_t new_data_size) {
|
||||
if (new_data == nullptr || new_data_size == 0) {
|
||||
value->get_value().clear();
|
||||
return;
|
||||
}
|
||||
|
||||
value->get_value().reserve(new_data_size);
|
||||
|
||||
for (auto i = 0; i < new_data_size; ++i) {
|
||||
// NOLINTNEXTLINE(*-pro-bounds-pointer-arithmetic)
|
||||
value->get_value().emplace_back(new_data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
struct IkarusValue * ikarus_toggle_value_to_value(IkarusToggleValue * value) {
|
||||
return static_cast<IkarusValue *>(value);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <boost/container/vector.hpp>
|
||||
|
||||
#include <values/value.hpp>
|
||||
|
||||
/// \private
|
||||
struct IkarusToggleValue final : IkarusValue {
|
||||
public:
|
||||
explicit IkarusToggleValue(bool value):
|
||||
IkarusValue{this},
|
||||
_value{value} {}
|
||||
explicit IkarusToggleValue();
|
||||
|
||||
IkarusToggleValue(IkarusToggleValue const&) = default;
|
||||
IkarusToggleValue(IkarusToggleValue&&) = default;
|
||||
|
|
@ -18,14 +19,9 @@ public:
|
|||
~IkarusToggleValue() override = default;
|
||||
|
||||
public:
|
||||
[[nodiscard]] bool get_value() const {
|
||||
return _value;
|
||||
}
|
||||
|
||||
void set_value(bool value) {
|
||||
_value = value;
|
||||
}
|
||||
[[nodiscard]] boost::container::vector<bool>& get_value();
|
||||
[[nodiscard]] boost::container::vector<bool> const& get_value() const;
|
||||
|
||||
private:
|
||||
bool _value;
|
||||
boost::container::vector<bool> _value{};
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue