add default values as param to property_create funcs
Signed-off-by: Folling <mail@folling.io>
This commit is contained in:
parent
8f82b0e3da
commit
70fca82425
8 changed files with 24 additions and 8 deletions
|
|
@ -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
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
#include "number_property.hpp"
|
||||
#include "ikarus/objects/properties/number_property.h"
|
||||
|
||||
#include <cppbase/result.hpp>
|
||||
|
||||
#include <ikarus/objects/properties/property.h>
|
||||
|
||||
#include <objects/properties/number_property.hpp>
|
||||
#include <objects/properties/property_source.hpp>
|
||||
#include <objects/properties/util.hpp>
|
||||
#include <values/value.hpp>
|
||||
|
|
@ -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<IkarusNumberProperty>(project, name, property_source, error_out);
|
||||
return ikarus::util::create_property<IkarusNumberProperty>(project, name, property_source, default_value, error_out);
|
||||
}
|
||||
|
||||
IkarusNumberValue * ikarus_number_property_get_default_value(IkarusNumberProperty * property, IkarusErrorData * error_out) {
|
||||
|
|
|
|||
|
|
@ -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<IkarusTextProperty>(project, name, property_source, error_out);
|
||||
return ikarus::util::create_property<IkarusTextProperty>(project, name, property_source, default_value, error_out);
|
||||
}
|
||||
|
||||
IkarusTextValue * ikarus_text_property_get_default_value(IkarusTextProperty * property, IkarusErrorData * error_out) {
|
||||
|
|
|
|||
|
|
@ -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<IkarusToggleProperty>(project, name, property_source, error_out);
|
||||
return ikarus::util::create_property<IkarusToggleProperty>(project, name, property_source, default_value, error_out);
|
||||
}
|
||||
|
||||
IkarusToggleValue * ikarus_toggle_property_get_default_value(struct IkarusToggleProperty * property, IkarusErrorData * error_out) {
|
||||
|
|
|
|||
|
|
@ -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<T>().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<IkarusId, sqlitecpp::TransactionError> {
|
||||
project->db->transact([name, property_source, default_value](auto * db) -> cppbase::Result<IkarusId, sqlitecpp::TransactionError> {
|
||||
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);
|
||||
})
|
||||
|
|
|
|||
2
vendor/sqlitecpp
vendored
2
vendor/sqlitecpp
vendored
|
|
@ -1 +1 @@
|
|||
Subproject commit eadf3237bfa853763b332777e9dc0f16df8cca71
|
||||
Subproject commit 77e726036b52fff6f82ff2d44081f05aee7408a8
|
||||
Loading…
Add table
Add a link
Reference in a new issue