diff --git a/include/ikarus/objects/properties/number_property.h b/include/ikarus/objects/properties/number_property.h index 8ca4ffd..2fcf63b 100644 --- a/include/ikarus/objects/properties/number_property.h +++ b/include/ikarus/objects/properties/number_property.h @@ -24,12 +24,15 @@ struct IkarusNumberProperty; /// \param property_source The property source to create the property for. /// \pre \li Must not be null. /// \pre \li Must exist. +/// \param default_value The default value for the property. +/// \pre \li Must not be null. /// \param error_out \see errors.h /// \return The created property or null if an error occurs. IKA_API IkarusNumberProperty * ikarus_number_property_create( struct IkarusProject * project, char const * name, struct IkarusPropertySource * property_source, + struct IkarusNumberValue * default_value, IkarusErrorData * error_out ); diff --git a/include/ikarus/objects/properties/text_property.h b/include/ikarus/objects/properties/text_property.h index 0408614..5e59d92 100644 --- a/include/ikarus/objects/properties/text_property.h +++ b/include/ikarus/objects/properties/text_property.h @@ -24,12 +24,15 @@ struct IkarusTextProperty; /// \param property_source The property source to create the property for. /// \pre \li Must not be null. /// \pre \li Must exist. +/// \param default_value The default value for the property. +/// \pre \li Must not be null. /// \param error_out \see errors.h /// \return The created property or null if an error occurs. IKA_API IkarusTextProperty * ikarus_text_property_create( struct IkarusProject * project, char const * name, struct IkarusPropertySource * property_source, + struct IkarusTextValue* default_value, IkarusErrorData * error_out ); diff --git a/include/ikarus/objects/properties/toggle_property.h b/include/ikarus/objects/properties/toggle_property.h index 892d418..403f392 100644 --- a/include/ikarus/objects/properties/toggle_property.h +++ b/include/ikarus/objects/properties/toggle_property.h @@ -24,12 +24,15 @@ struct IkarusToggleProperty; /// \param property_source The property source to create the property for. /// \pre \li Must not be null. /// \pre \li Must exist. +/// \param default_value The default value for the property. +/// \pre \li Must not be null. /// \param error_out \see errors.h /// \return The created property or null if an error occurs. IKA_API IkarusToggleProperty * ikarus_toggle_property_create( struct IkarusProject * project, char const * name, struct IkarusPropertySource * property_source, + struct IkarusToggleValue * default_value, IkarusErrorData * error_out ); diff --git a/src/objects/properties/number_property.cpp b/src/objects/properties/number_property.cpp index 9d0fe13..b94429d 100644 --- a/src/objects/properties/number_property.cpp +++ b/src/objects/properties/number_property.cpp @@ -1,9 +1,10 @@ -#include "number_property.hpp" +#include "ikarus/objects/properties/number_property.h" #include #include +#include #include #include #include @@ -15,9 +16,10 @@ IkarusNumberProperty * ikarus_number_property_create( struct IkarusProject * project, char const * name, struct IkarusPropertySource * property_source, + struct IkarusNumberValue * default_value, IkarusErrorData * error_out ) { - return ikarus::util::create_property(project, name, property_source, error_out); + return ikarus::util::create_property(project, name, property_source, default_value, error_out); } IkarusNumberValue * ikarus_number_property_get_default_value(IkarusNumberProperty * property, IkarusErrorData * error_out) { diff --git a/src/objects/properties/text_property.cpp b/src/objects/properties/text_property.cpp index 8b3b1a5..c7541ff 100644 --- a/src/objects/properties/text_property.cpp +++ b/src/objects/properties/text_property.cpp @@ -15,9 +15,10 @@ IkarusTextProperty * ikarus_text_property_create( struct IkarusProject * project, char const * name, struct IkarusPropertySource * property_source, + struct IkarusTextValue * default_value, IkarusErrorData * error_out ) { - return ikarus::util::create_property(project, name, property_source, error_out); + return ikarus::util::create_property(project, name, property_source, default_value, error_out); } IkarusTextValue * ikarus_text_property_get_default_value(IkarusTextProperty * property, IkarusErrorData * error_out) { diff --git a/src/objects/properties/toggle_property.cpp b/src/objects/properties/toggle_property.cpp index e0931fa..2cde654 100644 --- a/src/objects/properties/toggle_property.cpp +++ b/src/objects/properties/toggle_property.cpp @@ -15,9 +15,10 @@ IkarusToggleProperty * ikarus_toggle_property_create( struct IkarusProject * project, char const * name, struct IkarusPropertySource * property_source, + struct IkarusToggleValue * default_value, IkarusErrorData * error_out ) { - return ikarus::util::create_property(project, name, property_source, error_out); + return ikarus::util::create_property(project, name, property_source, default_value, error_out); } IkarusToggleValue * ikarus_toggle_property_get_default_value(struct IkarusToggleProperty * property, IkarusErrorData * error_out) { diff --git a/src/objects/properties/util.hpp b/src/objects/properties/util.hpp index 2e11475..d9321c7 100644 --- a/src/objects/properties/util.hpp +++ b/src/objects/properties/util.hpp @@ -18,6 +18,7 @@ T * create_property( struct IkarusProject * project, char const * name, struct IkarusPropertySource * property_source, + typename T::value_type * default_value, IkarusErrorData * error_out ) { IKARUS_FAIL_IF_NULL(project, nullptr); @@ -29,20 +30,22 @@ T * create_property( fmt::format("{} name cannot be empty or blank", boost::typeindex::type_id().pretty_name()), IkarusErrorInfo_Client_InvalidInput ) + IKARUS_FAIL_IF_NULL(default_value, nullptr); IKARUS_VTRYRV_OR_FAIL( IkarusId const id, nullptr, "failed to create property: {}", IkarusErrorInfo_Database_QueryFailed, - project->db->transact([name, property_source](auto * db) -> cppbase::Result { + project->db->transact([name, property_source, default_value](auto * db) -> cppbase::Result { TRY(db->execute("INSERT INTO `objects`(`type`, `name`, `information`) VALUES(?, ?, ?)", IkarusObjectType_Property, name, "")); auto id = ikarus_id_from_data_and_type(db->last_insert_rowid(), IkarusObjectType_Property); TRY(db->execute( - "INSERT INTO `properties`(`id`, `type`, `source`) VALUES(?, ?, ?)", + "INSERT INTO `properties`(`id`, `type`, `source`, `default_value`) VALUES(?, ?, ?, ?)", id, T::PropertyType, - property_source->get_id() + property_source->get_id(), + boost::json::serialize(default_value->to_json()) )); return cppbase::ok(id); }) diff --git a/vendor/sqlitecpp b/vendor/sqlitecpp index eadf323..77e7260 160000 --- a/vendor/sqlitecpp +++ b/vendor/sqlitecpp @@ -1 +1 @@ -Subproject commit eadf3237bfa853763b332777e9dc0f16df8cca71 +Subproject commit 77e726036b52fff6f82ff2d44081f05aee7408a8