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.
|
/// \param property_source The property source to create the property for.
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
/// \pre \li Must exist.
|
/// \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
|
/// \param error_out \see errors.h
|
||||||
/// \return The created property or null if an error occurs.
|
/// \return The created property or null if an error occurs.
|
||||||
IKA_API IkarusNumberProperty * ikarus_number_property_create(
|
IKA_API IkarusNumberProperty * ikarus_number_property_create(
|
||||||
struct IkarusProject * project,
|
struct IkarusProject * project,
|
||||||
char const * name,
|
char const * name,
|
||||||
struct IkarusPropertySource * property_source,
|
struct IkarusPropertySource * property_source,
|
||||||
|
struct IkarusNumberValue * default_value,
|
||||||
IkarusErrorData * error_out
|
IkarusErrorData * error_out
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,12 +24,15 @@ struct IkarusTextProperty;
|
||||||
/// \param property_source The property source to create the property for.
|
/// \param property_source The property source to create the property for.
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
/// \pre \li Must exist.
|
/// \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
|
/// \param error_out \see errors.h
|
||||||
/// \return The created property or null if an error occurs.
|
/// \return The created property or null if an error occurs.
|
||||||
IKA_API IkarusTextProperty * ikarus_text_property_create(
|
IKA_API IkarusTextProperty * ikarus_text_property_create(
|
||||||
struct IkarusProject * project,
|
struct IkarusProject * project,
|
||||||
char const * name,
|
char const * name,
|
||||||
struct IkarusPropertySource * property_source,
|
struct IkarusPropertySource * property_source,
|
||||||
|
struct IkarusTextValue* default_value,
|
||||||
IkarusErrorData * error_out
|
IkarusErrorData * error_out
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,12 +24,15 @@ struct IkarusToggleProperty;
|
||||||
/// \param property_source The property source to create the property for.
|
/// \param property_source The property source to create the property for.
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
/// \pre \li Must exist.
|
/// \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
|
/// \param error_out \see errors.h
|
||||||
/// \return The created property or null if an error occurs.
|
/// \return The created property or null if an error occurs.
|
||||||
IKA_API IkarusToggleProperty * ikarus_toggle_property_create(
|
IKA_API IkarusToggleProperty * ikarus_toggle_property_create(
|
||||||
struct IkarusProject * project,
|
struct IkarusProject * project,
|
||||||
char const * name,
|
char const * name,
|
||||||
struct IkarusPropertySource * property_source,
|
struct IkarusPropertySource * property_source,
|
||||||
|
struct IkarusToggleValue * default_value,
|
||||||
IkarusErrorData * error_out
|
IkarusErrorData * error_out
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
#include "number_property.hpp"
|
#include "ikarus/objects/properties/number_property.h"
|
||||||
|
|
||||||
#include <cppbase/result.hpp>
|
#include <cppbase/result.hpp>
|
||||||
|
|
||||||
#include <ikarus/objects/properties/property.h>
|
#include <ikarus/objects/properties/property.h>
|
||||||
|
|
||||||
|
#include <objects/properties/number_property.hpp>
|
||||||
#include <objects/properties/property_source.hpp>
|
#include <objects/properties/property_source.hpp>
|
||||||
#include <objects/properties/util.hpp>
|
#include <objects/properties/util.hpp>
|
||||||
#include <values/value.hpp>
|
#include <values/value.hpp>
|
||||||
|
|
@ -15,9 +16,10 @@ IkarusNumberProperty * ikarus_number_property_create(
|
||||||
struct IkarusProject * project,
|
struct IkarusProject * project,
|
||||||
char const * name,
|
char const * name,
|
||||||
struct IkarusPropertySource * property_source,
|
struct IkarusPropertySource * property_source,
|
||||||
|
struct IkarusNumberValue * default_value,
|
||||||
IkarusErrorData * error_out
|
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) {
|
IkarusNumberValue * ikarus_number_property_get_default_value(IkarusNumberProperty * property, IkarusErrorData * error_out) {
|
||||||
|
|
|
||||||
|
|
@ -15,9 +15,10 @@ IkarusTextProperty * ikarus_text_property_create(
|
||||||
struct IkarusProject * project,
|
struct IkarusProject * project,
|
||||||
char const * name,
|
char const * name,
|
||||||
struct IkarusPropertySource * property_source,
|
struct IkarusPropertySource * property_source,
|
||||||
|
struct IkarusTextValue * default_value,
|
||||||
IkarusErrorData * error_out
|
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) {
|
IkarusTextValue * ikarus_text_property_get_default_value(IkarusTextProperty * property, IkarusErrorData * error_out) {
|
||||||
|
|
|
||||||
|
|
@ -15,9 +15,10 @@ IkarusToggleProperty * ikarus_toggle_property_create(
|
||||||
struct IkarusProject * project,
|
struct IkarusProject * project,
|
||||||
char const * name,
|
char const * name,
|
||||||
struct IkarusPropertySource * property_source,
|
struct IkarusPropertySource * property_source,
|
||||||
|
struct IkarusToggleValue * default_value,
|
||||||
IkarusErrorData * error_out
|
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) {
|
IkarusToggleValue * ikarus_toggle_property_get_default_value(struct IkarusToggleProperty * property, IkarusErrorData * error_out) {
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ T * create_property(
|
||||||
struct IkarusProject * project,
|
struct IkarusProject * project,
|
||||||
char const * name,
|
char const * name,
|
||||||
struct IkarusPropertySource * property_source,
|
struct IkarusPropertySource * property_source,
|
||||||
|
typename T::value_type * default_value,
|
||||||
IkarusErrorData * error_out
|
IkarusErrorData * error_out
|
||||||
) {
|
) {
|
||||||
IKARUS_FAIL_IF_NULL(project, nullptr);
|
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()),
|
fmt::format("{} name cannot be empty or blank", boost::typeindex::type_id<T>().pretty_name()),
|
||||||
IkarusErrorInfo_Client_InvalidInput
|
IkarusErrorInfo_Client_InvalidInput
|
||||||
)
|
)
|
||||||
|
IKARUS_FAIL_IF_NULL(default_value, nullptr);
|
||||||
|
|
||||||
IKARUS_VTRYRV_OR_FAIL(
|
IKARUS_VTRYRV_OR_FAIL(
|
||||||
IkarusId const id,
|
IkarusId const id,
|
||||||
nullptr,
|
nullptr,
|
||||||
"failed to create property: {}",
|
"failed to create property: {}",
|
||||||
IkarusErrorInfo_Database_QueryFailed,
|
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, ""));
|
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);
|
auto id = ikarus_id_from_data_and_type(db->last_insert_rowid(), IkarusObjectType_Property);
|
||||||
TRY(db->execute(
|
TRY(db->execute(
|
||||||
"INSERT INTO `properties`(`id`, `type`, `source`) VALUES(?, ?, ?)",
|
"INSERT INTO `properties`(`id`, `type`, `source`, `default_value`) VALUES(?, ?, ?, ?)",
|
||||||
id,
|
id,
|
||||||
T::PropertyType,
|
T::PropertyType,
|
||||||
property_source->get_id()
|
property_source->get_id(),
|
||||||
|
boost::json::serialize(default_value->to_json())
|
||||||
));
|
));
|
||||||
return cppbase::ok(id);
|
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