add src/ikarus subdir and make names unique for objects per scope
Signed-off-by: Folling <mail@folling.io>
This commit is contained in:
parent
ced123b628
commit
9f943cc6a2
51 changed files with 590 additions and 735 deletions
26
.clang-tidy
26
.clang-tidy
|
|
@ -1,26 +1,24 @@
|
||||||
Checks: >-
|
Checks: >-
|
||||||
-*,
|
-*,
|
||||||
bugprone-*, -bugprone-lambda-function-name,
|
# bugprone-*, -bugprone-lambda-function-name,
|
||||||
cppcoreguidelines-*, -cppcoreguidelines-macro-usage, -cppcoreguidelines-owning-memory, -cppcoreguidelines-non-private-member-variables-in-classes,
|
# cppcoreguidelines-*, -cppcoreguidelines-macro-usage, -cppcoreguidelines-owning-memory, -cppcoreguidelines-non-private-member-variables-in-classes,
|
||||||
clang-analyzer-*,
|
# clang-analyzer-*,
|
||||||
google-*, -google-readability-todo,
|
# google-*, -google-readability-todo,
|
||||||
modernize-*, -modernize-use-trailing-return-type,
|
# modernize-*, -modernize-use-trailing-return-type,
|
||||||
performance-*, -performance-enum-size,
|
# performance-*, -performance-enum-size,
|
||||||
portability-*,
|
# portability-*,
|
||||||
readability-*, -readability-redundant-access-specifiers
|
# readability-*, -readability-redundant-access-specifiers
|
||||||
CheckOptions:
|
CheckOptions:
|
||||||
readability-identifier-length.IgnoredParameterNames: '^(db|rc|id|ec)$'
|
readability-identifier-length.IgnoredParameterNames: '^(db|rc|id|ec)$'
|
||||||
readability-identifier-length.IgnoredLoopCounterNames: '^[ij]$'
|
readability-identifier-length.IgnoredLoopCounterNames: '^[ij]$'
|
||||||
readability-identifier-length.IgnoredVariableNames: '^(db|rc|id|ec)$'
|
readability-identifier-length.IgnoredVariableNames: '^(db|rc|id|ec)$'
|
||||||
cppcoreguidelines-avoid-do-while.IgnoreMacros: Yes
|
cppcoreguidelines-avoid-do-while.IgnoreMacros: Yes
|
||||||
HeaderFileExtensions:
|
HeaderFileExtensions:
|
||||||
- h
|
# - hpp
|
||||||
- hpp
|
# - tpp
|
||||||
- tpp
|
# - ipp
|
||||||
- ipp
|
|
||||||
ImplementationFileExtensions:
|
ImplementationFileExtensions:
|
||||||
- c
|
# - cpp
|
||||||
- cpp
|
|
||||||
FormatStyle: file
|
FormatStyle: file
|
||||||
InheritParentConfig: false
|
InheritParentConfig: false
|
||||||
WarningsAsErrors: '*'
|
WarningsAsErrors: '*'
|
||||||
|
|
|
||||||
192
clang-format.txt
192
clang-format.txt
|
|
@ -1,192 +0,0 @@
|
||||||
BasedOnStyle: Google
|
|
||||||
|
|
||||||
AccessModifierOffset: -4
|
|
||||||
|
|
||||||
AlignAfterOpenBracket: BlockIndent
|
|
||||||
AlignArrayOfStructures: Right
|
|
||||||
AlignConsecutiveAssignments:
|
|
||||||
Enabled: false
|
|
||||||
AlignConsecutiveBitFields:
|
|
||||||
Enabled: false
|
|
||||||
AlignConsecutiveDeclarations:
|
|
||||||
Enabled: false
|
|
||||||
AlignConsecutiveMacros: AcrossEmptyLines
|
|
||||||
AlignEscapedNewlines: Left
|
|
||||||
AlignOperands: Align
|
|
||||||
AlignTrailingComments: true
|
|
||||||
|
|
||||||
AllowAllArgumentsOnNextLine: false
|
|
||||||
AllowAllParametersOfDeclarationOnNextLine: false
|
|
||||||
AllowShortBlocksOnASingleLine: Empty
|
|
||||||
AllowShortCaseLabelsOnASingleLine: true
|
|
||||||
AllowShortEnumsOnASingleLine: true
|
|
||||||
AllowShortFunctionsOnASingleLine: Empty
|
|
||||||
AllowShortIfStatementsOnASingleLine: WithoutElse
|
|
||||||
AllowShortLambdasOnASingleLine: All
|
|
||||||
AllowShortLoopsOnASingleLine: true
|
|
||||||
|
|
||||||
AlwaysBreakAfterReturnType: None
|
|
||||||
AlwaysBreakBeforeMultilineStrings: true
|
|
||||||
AlwaysBreakTemplateDeclarations: Yes
|
|
||||||
|
|
||||||
BinPackArguments: false
|
|
||||||
BinPackParameters: false
|
|
||||||
|
|
||||||
BitFieldColonSpacing: Both
|
|
||||||
|
|
||||||
BraceWrapping:
|
|
||||||
AfterCaseLabel: false
|
|
||||||
AfterClass: false
|
|
||||||
AfterControlStatement: Never
|
|
||||||
AfterEnum: false
|
|
||||||
AfterFunction: false
|
|
||||||
AfterNamespace: false
|
|
||||||
AfterStruct: false
|
|
||||||
AfterUnion: false
|
|
||||||
AfterExternBlock: false
|
|
||||||
BeforeCatch: false
|
|
||||||
BeforeElse: false
|
|
||||||
BeforeLambdaBody: false
|
|
||||||
BeforeWhile: false
|
|
||||||
IndentBraces: false
|
|
||||||
SplitEmptyFunction: false
|
|
||||||
SplitEmptyNamespace: false
|
|
||||||
SplitEmptyRecord: false
|
|
||||||
|
|
||||||
BracedInitializerIndentWidth: 4
|
|
||||||
|
|
||||||
# BreakAdjacentStringLiterals: true
|
|
||||||
BreakAfterAttributes: Never
|
|
||||||
BreakBeforeBinaryOperators: None
|
|
||||||
BreakBeforeBraces: Custom
|
|
||||||
BreakBeforeConceptDeclarations: Always
|
|
||||||
BreakBeforeInlineASMColon: OnlyMultiline
|
|
||||||
BreakBeforeTernaryOperators: false
|
|
||||||
BreakConstructorInitializers: AfterColon
|
|
||||||
BreakInheritanceList: AfterColon
|
|
||||||
BreakStringLiterals: false
|
|
||||||
|
|
||||||
ColumnLimit: 140
|
|
||||||
|
|
||||||
CompactNamespaces: false
|
|
||||||
ConstructorInitializerIndentWidth: 4
|
|
||||||
ContinuationIndentWidth: 4
|
|
||||||
|
|
||||||
Cpp11BracedListStyle: true
|
|
||||||
|
|
||||||
DerivePointerAlignment: false
|
|
||||||
|
|
||||||
EmptyLineAfterAccessModifier: Never
|
|
||||||
EmptyLineBeforeAccessModifier: Always
|
|
||||||
|
|
||||||
ExperimentalAutoDetectBinPacking: true
|
|
||||||
|
|
||||||
FixNamespaceComments: true
|
|
||||||
|
|
||||||
IncludeBlocks: Regroup
|
|
||||||
IncludeCategories:
|
|
||||||
- Regex: '^".+\.(h|hpp)"$'
|
|
||||||
Priority: 1
|
|
||||||
- Regex: '^<[a-z0-9_]+\.h>$'
|
|
||||||
Priority: 2
|
|
||||||
- Regex: '^<[a-z0-9_]+>$'
|
|
||||||
Priority: 3
|
|
||||||
- Regex: '^<boost/.*>$'
|
|
||||||
Priority: 4
|
|
||||||
- Regex: '^<expected/.*>$'
|
|
||||||
Priority: 5
|
|
||||||
- Regex: '^<fmt/.*>$'
|
|
||||||
Priority: 6
|
|
||||||
- Regex: '^<nlohmann/.*>$'
|
|
||||||
Priority: 7
|
|
||||||
- Regex: '^<range-v3/.*>$'
|
|
||||||
Priority: 8
|
|
||||||
- Regex: '^<catch2/.*>$'
|
|
||||||
Priority: 9
|
|
||||||
- Regex: '^<unicode/.*>$'
|
|
||||||
Priority: 10
|
|
||||||
- Regex: '^<cppbase/.*>$'
|
|
||||||
Priority: 11
|
|
||||||
- Regex: '^<sqlitecpp/.*>$'
|
|
||||||
Priority: 12
|
|
||||||
- Regex: '^<ikarus/.*>$'
|
|
||||||
Priority: 13
|
|
||||||
|
|
||||||
IndentAccessModifiers: false
|
|
||||||
IndentCaseBlocks: false
|
|
||||||
IndentCaseLabels: false
|
|
||||||
IndentExternBlock: NoIndent
|
|
||||||
IndentGotoLabels: false
|
|
||||||
IndentPPDirectives: None
|
|
||||||
IndentRequiresClause: true
|
|
||||||
IndentWidth: 4
|
|
||||||
IndentWrappedFunctionNames: false
|
|
||||||
InsertBraces: true
|
|
||||||
InsertNewlineAtEOF: true
|
|
||||||
InsertTrailingCommas: Wrapped
|
|
||||||
|
|
||||||
IntegerLiteralSeparator:
|
|
||||||
Binary: -1
|
|
||||||
Decimal: 3
|
|
||||||
Hex: -1
|
|
||||||
|
|
||||||
KeepEmptyLinesAtEOF: false
|
|
||||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
|
||||||
|
|
||||||
LambdaBodyIndentation: Signature
|
|
||||||
Language: Cpp
|
|
||||||
|
|
||||||
LineEnding: LF
|
|
||||||
|
|
||||||
MaxEmptyLinesToKeep: 1
|
|
||||||
|
|
||||||
NamespaceIndentation: None
|
|
||||||
|
|
||||||
PPIndentWidth: -1
|
|
||||||
PackConstructorInitializers: Never
|
|
||||||
|
|
||||||
PointerAlignment: Middle
|
|
||||||
QualifierAlignment: Right
|
|
||||||
# QualifierOrder: [ 'friend', 'constexpr', 'inline', 'static', 'type', 'const', 'volatile' ]
|
|
||||||
ReferenceAlignment: Middle
|
|
||||||
|
|
||||||
ReflowComments: true
|
|
||||||
RemoveBracesLLVM: false
|
|
||||||
RemoveParentheses: MultipleParentheses
|
|
||||||
RemoveSemicolon: true
|
|
||||||
|
|
||||||
RequiresClausePosition: OwnLine
|
|
||||||
RequiresExpressionIndentation: OuterScope
|
|
||||||
|
|
||||||
SeparateDefinitionBlocks: Always
|
|
||||||
|
|
||||||
SortIncludes: CaseInsensitive
|
|
||||||
SortUsingDeclarations: LexicographicNumeric
|
|
||||||
|
|
||||||
SpaceAfterCStyleCast: false
|
|
||||||
SpaceAfterLogicalNot: false
|
|
||||||
SpaceAfterTemplateKeyword: false
|
|
||||||
SpaceAroundPointerQualifiers: Both
|
|
||||||
SpaceBeforeAssignmentOperators: true
|
|
||||||
SpaceBeforeCaseColon: false
|
|
||||||
SpaceBeforeCpp11BracedList: false
|
|
||||||
SpaceBeforeCtorInitializerColon: false
|
|
||||||
SpaceBeforeInheritanceColon: true
|
|
||||||
SpaceBeforeParens: ControlStatements
|
|
||||||
SpaceBeforeRangeBasedForLoopColon: true
|
|
||||||
SpaceBeforeSquareBrackets: false
|
|
||||||
SpaceInEmptyBlock: false
|
|
||||||
SpaceInEmptyParentheses: false
|
|
||||||
SpacesInAngles: false
|
|
||||||
SpacesInCStyleCastParentheses: false
|
|
||||||
SpacesInConditionalStatement: false
|
|
||||||
SpacesInContainerLiterals: false
|
|
||||||
SpacesInLineCommentPrefix:
|
|
||||||
Minimum: 1
|
|
||||||
Maximum: 1
|
|
||||||
SpacesInParentheses: false
|
|
||||||
SpacesInSquareBrackets: false
|
|
||||||
Standard: c++20
|
|
||||||
|
|
||||||
TabWidth: 4
|
|
||||||
UseTab: Never
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
/// \file global.h
|
/// \file errors.h
|
||||||
/// \author Folling <folling@ikarus.world>
|
/// \author Folling <folling@ikarus.world>
|
||||||
|
|
||||||
#include <ikarus/macros.h>
|
#include <ikarus/macros.h>
|
||||||
|
|
@ -92,6 +92,7 @@ enum IkarusErrorInfo {
|
||||||
IkarusErrorInfo_LibIkarus_Timeout = 0x06000003,
|
IkarusErrorInfo_LibIkarus_Timeout = 0x06000003,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// \brief The maximum length of an error message.
|
||||||
size_t const IKARUS_ERROR_DATA_MAX_MESSAGE_LIMIT = 128;
|
size_t const IKARUS_ERROR_DATA_MAX_MESSAGE_LIMIT = 128;
|
||||||
|
|
||||||
/// \brief The data stored for an error
|
/// \brief The data stored for an error
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,6 @@
|
||||||
#include <ikarus/objects/object_type.h>
|
#include <ikarus/objects/object_type.h>
|
||||||
#include <ikarus/stdtypes.h>
|
#include <ikarus/stdtypes.h>
|
||||||
|
|
||||||
IKARUS_BEGIN_HEADER
|
|
||||||
|
|
||||||
/// \defgroup id Ids
|
/// \defgroup id Ids
|
||||||
/// \brief Ids are used to identify objects in the database.
|
/// \brief Ids are used to identify objects in the database.
|
||||||
/// \details They are stored as 64 bit integers with the following layout:
|
/// \details They are stored as 64 bit integers with the following layout:
|
||||||
|
|
@ -22,6 +20,8 @@ IKARUS_BEGIN_HEADER
|
||||||
/// - last 56 bits: incremented counter generated by the database
|
/// - last 56 bits: incremented counter generated by the database
|
||||||
/// @{
|
/// @{
|
||||||
|
|
||||||
|
IKARUS_BEGIN_HEADER
|
||||||
|
|
||||||
/// \brief A wrapper around a 64 bit integer that represents the id of an object.
|
/// \brief A wrapper around a 64 bit integer that represents the id of an object.
|
||||||
/// \details They are stored as 64 bit integers with the following layout:
|
/// \details They are stored as 64 bit integers with the following layout:
|
||||||
/// - first bit: ignored, technically we could use it, but SQLite doesn't support u64 integers.
|
/// - first bit: ignored, technically we could use it, but SQLite doesn't support u64 integers.
|
||||||
|
|
@ -41,6 +41,6 @@ IKA_API IkarusId ikarus_id_from_data_and_type(int64_t data, IkarusObjectType typ
|
||||||
/// \return The object type of the given id.
|
/// \return The object type of the given id.
|
||||||
IKA_API IkarusObjectType ikarus_id_get_object_type(IkarusId id);
|
IKA_API IkarusObjectType ikarus_id_get_object_type(IkarusId id);
|
||||||
|
|
||||||
/// @}
|
|
||||||
|
|
||||||
IKARUS_END_HEADER
|
IKARUS_END_HEADER
|
||||||
|
|
||||||
|
/// @}
|
||||||
|
|
|
||||||
|
|
@ -25,9 +25,9 @@ struct IkarusBlueprint;
|
||||||
/// \param name The name of the blueprint.
|
/// \param name The name of the blueprint.
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
/// \pre \li Must not be empty.
|
/// \pre \li Must not be empty.
|
||||||
|
/// \pre \li Must be unique among all blueprints in the project.
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \return The created blueprint or null if an error occurs.
|
/// \return The created blueprint or null if an error occurs.
|
||||||
/// \remark Must be freed using #ikarus_free.
|
|
||||||
IKA_API IkarusBlueprint * ikarus_blueprint_create(struct IkarusProject * project, char const * name, IkarusErrorData * error_out);
|
IKA_API IkarusBlueprint * ikarus_blueprint_create(struct IkarusProject * project, char const * name, IkarusErrorData * error_out);
|
||||||
|
|
||||||
/// \brief Deletes & frees a blueprint.
|
/// \brief Deletes & frees a blueprint.
|
||||||
|
|
@ -38,6 +38,33 @@ IKA_API IkarusBlueprint * ikarus_blueprint_create(struct IkarusProject * project
|
||||||
/// \remark The blueprint must not be accessed after deletion.
|
/// \remark The blueprint must not be accessed after deletion.
|
||||||
IKA_API void ikarus_blueprint_delete(IkarusBlueprint * blueprint, IkarusErrorData * error_out);
|
IKA_API void ikarus_blueprint_delete(IkarusBlueprint * blueprint, IkarusErrorData * error_out);
|
||||||
|
|
||||||
|
/// \brief Gets the project a blueprint is part of.
|
||||||
|
/// \param blueprint The blueprint to get the project of.
|
||||||
|
/// \pre \li Must not be null.
|
||||||
|
/// \pre \li Must exist.
|
||||||
|
/// \param error_out \see errors.h
|
||||||
|
/// \return The project the blueprint is part of or null if an error occurs.
|
||||||
|
IKA_API IkarusProject * ikarus_blueprint_get_project(IkarusBlueprint const * blueprint, IkarusErrorData * error_out);
|
||||||
|
|
||||||
|
/// \brief Gets the name of a blueprint.
|
||||||
|
/// \param blueprint The blueprint to get the name of.
|
||||||
|
/// \pre \li Must not be null.
|
||||||
|
/// \pre \li Must exist.
|
||||||
|
/// \param error_out \see errors.h
|
||||||
|
/// \return The name of the blueprint or null if an error occurs.
|
||||||
|
IKA_API char const * ikarus_blueprint_get_name(IkarusBlueprint const * blueprint, IkarusErrorData * error_out);
|
||||||
|
|
||||||
|
/// \brief Sets the name of a blueprint.
|
||||||
|
/// \param blueprint The blueprint to set the name of.
|
||||||
|
/// \pre \li Must not be null.
|
||||||
|
/// \pre \li Must exist.
|
||||||
|
/// \param name The new name of the blueprint.
|
||||||
|
/// \pre \li Must not be null.
|
||||||
|
/// \pre \li Must not be empty.
|
||||||
|
/// \pre \li Must be unique among all blueprints in the project.
|
||||||
|
/// \param error_out \see errors.h
|
||||||
|
IKA_API void ikarus_blueprint_set_name(IkarusBlueprint * blueprint, char const * name, IkarusErrorData * error_out);
|
||||||
|
|
||||||
/// \brief Gets the properties of a blueprint.
|
/// \brief Gets the properties of a blueprint.
|
||||||
/// \param blueprint The blueprint to get the properties of.
|
/// \param blueprint The blueprint to get the properties of.
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
|
|
@ -86,18 +113,6 @@ IKA_API void ikarus_blueprint_get_linked_entities(
|
||||||
/// \return The number of linked entities or undefined if an error occurs.
|
/// \return The number of linked entities or undefined if an error occurs.
|
||||||
IKA_API size_t ikarus_blueprint_get_linked_entity_count(IkarusBlueprint const * blueprint, IkarusErrorData * error_out);
|
IKA_API size_t ikarus_blueprint_get_linked_entity_count(IkarusBlueprint const * blueprint, IkarusErrorData * error_out);
|
||||||
|
|
||||||
/// \brief Casts a blueprint to an object.
|
|
||||||
/// \param blueprint The blueprint to cast.
|
|
||||||
/// \pre \li Must not be null.
|
|
||||||
/// \pre \li Must exist.
|
|
||||||
/// \param error_out \see errors.h
|
|
||||||
/// \return The blueprint represented as an object or null if an error occurs.
|
|
||||||
/// \remark This operation is guaranteed to be very fast and is intended to be used frequently.
|
|
||||||
IKA_API struct IkarusObject * ikarus_blueprint_to_object(IkarusBlueprint * blueprint, IkarusErrorData * error_out);
|
|
||||||
|
|
||||||
/// \see ikarus_blueprint_to_object
|
|
||||||
IKA_API struct IkarusObject const * ikarus_blueprint_to_object_const(IkarusBlueprint const * blueprint, IkarusErrorData * error_out);
|
|
||||||
|
|
||||||
IKARUS_END_HEADER
|
IKARUS_END_HEADER
|
||||||
|
|
||||||
// @}
|
// @}
|
||||||
|
|
|
||||||
|
|
@ -41,9 +41,9 @@ struct IkarusEntity;
|
||||||
/// \param name The name of the entity.
|
/// \param name The name of the entity.
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
/// \pre \li Must not be empty.
|
/// \pre \li Must not be empty.
|
||||||
|
/// \pre \li Must be unique among all entities in the project.
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \return The created entity or null if an error occurs.
|
/// \return The created entity or null if an error occurs.
|
||||||
/// \remark Must be freed using #ikarus_free.
|
|
||||||
IKA_API IkarusEntity * ikarus_entity_create(struct IkarusProject * project, char const * name, IkarusErrorData * error_out);
|
IKA_API IkarusEntity * ikarus_entity_create(struct IkarusProject * project, char const * name, IkarusErrorData * error_out);
|
||||||
|
|
||||||
/// \brief Deletes an entity.
|
/// \brief Deletes an entity.
|
||||||
|
|
@ -54,6 +54,33 @@ IKA_API IkarusEntity * ikarus_entity_create(struct IkarusProject * project, char
|
||||||
/// \remark The entity must not be accessed after deletion.
|
/// \remark The entity must not be accessed after deletion.
|
||||||
IKA_API void ikarus_entity_delete(IkarusEntity * entity, IkarusErrorData * error_out);
|
IKA_API void ikarus_entity_delete(IkarusEntity * entity, IkarusErrorData * error_out);
|
||||||
|
|
||||||
|
/// \brief Gets the project an entity is part of.
|
||||||
|
/// \param entity The entity to get the project of.
|
||||||
|
/// \pre \li Must not be null.
|
||||||
|
/// \pre \li Must exist.
|
||||||
|
/// \param error_out \see errors.h
|
||||||
|
/// \return The project the entity is part of or null if an error occurs.
|
||||||
|
IKA_API IkarusProject * ikarus_entity_get_project(IkarusEntity const * entity, IkarusErrorData * error_out);
|
||||||
|
|
||||||
|
/// \brief Gets the name of an entity.
|
||||||
|
/// \param entity The entity to get the name of.
|
||||||
|
/// \pre \li Must not be null.
|
||||||
|
/// \pre \li Must exist.
|
||||||
|
/// \param error_out \see errors.h
|
||||||
|
/// \return The name of the entity or null if an error occurs.
|
||||||
|
IKA_API char const * ikarus_entity_get_name(IkarusEntity const * entity, IkarusErrorData * error_out);
|
||||||
|
|
||||||
|
/// \brief Sets the name of an entity.
|
||||||
|
/// \param entity The entity to set the name of.
|
||||||
|
/// \pre \li Must not be null.
|
||||||
|
/// \pre \li Must exist.
|
||||||
|
/// \param name The new name of the entity.
|
||||||
|
/// \pre \li Must not be null.
|
||||||
|
/// \pre \li Must not be empty.
|
||||||
|
/// \pre \li Must be unique among all entities in the project.
|
||||||
|
/// \param error_out \see errors.h
|
||||||
|
IKA_API void ikarus_entity_set_name(IkarusEntity * entity, char const * name, IkarusErrorData * error_out);
|
||||||
|
|
||||||
/// \brief Checks if an entity is linked to a blueprint.
|
/// \brief Checks if an entity is linked to a blueprint.
|
||||||
/// \param entity The entity to check.
|
/// \param entity The entity to check.
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
|
|
@ -182,18 +209,6 @@ IKA_API void ikarus_entity_set_value(
|
||||||
IkarusErrorData * error_out
|
IkarusErrorData * error_out
|
||||||
);
|
);
|
||||||
|
|
||||||
/// \brief Casts an entity to an object.
|
|
||||||
/// \param entity The entity to cast.
|
|
||||||
/// \pre \li Must not be null.
|
|
||||||
/// \pre \li Must exist.
|
|
||||||
/// \param error_out \see errors.h
|
|
||||||
/// \return The entity represented as an object or null if an error occurs.
|
|
||||||
/// \remark This operation is guaranteed to be very fast and is intended to be used frequently.
|
|
||||||
IKA_API struct IkarusObject * ikarus_entity_to_object(IkarusEntity * entity, IkarusErrorData * error_out);
|
|
||||||
|
|
||||||
/// \see ikarus_entity_to_object
|
|
||||||
IKA_API struct IkarusObject const * ikarus_entity_to_object_const(IkarusEntity const * entity, IkarusErrorData * error_out);
|
|
||||||
|
|
||||||
IKARUS_END_HEADER
|
IKARUS_END_HEADER
|
||||||
|
|
||||||
// @}
|
// @}
|
||||||
|
|
|
||||||
|
|
@ -19,62 +19,6 @@ IKARUS_BEGIN_HEADER
|
||||||
/// \brief A generic object. Wraps all types of objects, including folders.
|
/// \brief A generic object. Wraps all types of objects, including folders.
|
||||||
struct IkarusObject;
|
struct IkarusObject;
|
||||||
|
|
||||||
/// \brief Fetches the project of an object.
|
|
||||||
/// \param object The object to fetch the project from.
|
|
||||||
/// \pre \li Must not be null.
|
|
||||||
/// \pre \li Must exist.
|
|
||||||
/// \param error_out \see errors.h
|
|
||||||
/// \return The project of the object or null if an error occurs.
|
|
||||||
IKA_API struct IkarusProject * ikarus_object_get_project(IkarusObject const * object, IkarusErrorData * error_out);
|
|
||||||
|
|
||||||
/// \brief Fetches the name of an object.
|
|
||||||
/// \param object The object to fetch the name from.
|
|
||||||
/// \pre \li Must not be null.
|
|
||||||
/// \pre \li Must exist.
|
|
||||||
/// \param error_out \see errors.h
|
|
||||||
/// \return The name of the object or null if an error occurs.
|
|
||||||
IKA_API char const * ikarus_object_get_name(IkarusObject const * object, IkarusErrorData * error_out);
|
|
||||||
|
|
||||||
/// \brief Sets the name of an object.
|
|
||||||
/// \param object The object to set the name of.
|
|
||||||
/// \pre \li Must not be null.
|
|
||||||
/// \pre \li Must exist.
|
|
||||||
/// \param new_name The new name of the object.
|
|
||||||
/// \pre \li Must not be null.
|
|
||||||
/// \pre \li Must not be empty.
|
|
||||||
/// \param error_out \see errors.h
|
|
||||||
IKA_API void ikarus_object_set_name(IkarusObject const * object, char const * new_name, IkarusErrorData * error_out);
|
|
||||||
|
|
||||||
/// \brief Fetches the information of an object.
|
|
||||||
/// \param object The object to fetch the information from.
|
|
||||||
/// \pre \li Must not be null.
|
|
||||||
/// \pre \li Must exist.
|
|
||||||
/// \param error_out \see errors.h
|
|
||||||
/// \return The information of the object or null if an error occurs.
|
|
||||||
IKA_API char const * ikarus_object_get_info(IkarusObject const * object, IkarusErrorData * error_out);
|
|
||||||
|
|
||||||
/// \brief Sets the information of an object.
|
|
||||||
/// \param object The object to set the information of.
|
|
||||||
/// \pre \li Must not be null.
|
|
||||||
/// \pre \li Must exist.
|
|
||||||
/// \param new_info The new information of the object.
|
|
||||||
/// \pre \li Must not be null.
|
|
||||||
/// \param error_out \see errors.h
|
|
||||||
IKA_API void ikarus_object_set_info(IkarusObject const * object, char const * new_info, IkarusErrorData * error_out);
|
|
||||||
|
|
||||||
/// \brief Compares two objects for equality.
|
|
||||||
/// \details This neither compares the pointers nor does a deep copy. Instead it figures out if the objects _are_ the
|
|
||||||
/// same object.
|
|
||||||
/// \param lhs The left hand side object.
|
|
||||||
/// \pre \li Must not be null.
|
|
||||||
/// \pre \li Must exist.
|
|
||||||
/// \param rhs The right hand side object.
|
|
||||||
/// \pre \li Must not be null.
|
|
||||||
/// \pre \li Must exist.
|
|
||||||
/// \param error_out \see errors.h
|
|
||||||
/// \return True if the objects are equal, false otherwise.
|
|
||||||
IKA_API bool ikarus_object_is_equal(IkarusObject const * lhs, IkarusObject const * rhs, IkarusErrorData * error_out);
|
|
||||||
|
|
||||||
/// \brief Visits an object. Calling the appropriate function for the object's type.
|
/// \brief Visits an object. Calling the appropriate function for the object's type.
|
||||||
/// \param object The object to visit.
|
/// \param object The object to visit.
|
||||||
/// \param blueprint_visitor The function to call if the object is a blueprint. Skipped if null.
|
/// \param blueprint_visitor The function to call if the object is a blueprint. Skipped if null.
|
||||||
|
|
@ -84,9 +28,9 @@ IKA_API bool ikarus_object_is_equal(IkarusObject const * lhs, IkarusObject const
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
IKA_API void ikarus_object_visit(
|
IKA_API void ikarus_object_visit(
|
||||||
IkarusObject * object,
|
IkarusObject * object,
|
||||||
void (*blueprint_visitor)(struct IkarusBlueprint *, void *),
|
void (*blueprint_visitor)(struct IkarusBlueprint *, IkarusErrorData * error_out, void *),
|
||||||
void (*property_visitor)(struct IkarusProperty *, void *),
|
void (*property_visitor)(struct IkarusProperty *, IkarusErrorData * error_out, void *),
|
||||||
void (*entity_visitor)(struct IkarusEntity *, void *),
|
void (*entity_visitor)(struct IkarusEntity *, IkarusErrorData * error_out, void *),
|
||||||
void * data,
|
void * data,
|
||||||
IkarusErrorData * error_out
|
IkarusErrorData * error_out
|
||||||
);
|
);
|
||||||
|
|
@ -94,9 +38,9 @@ IKA_API void ikarus_object_visit(
|
||||||
/// \see ikarus_object_visit
|
/// \see ikarus_object_visit
|
||||||
IKA_API void ikarus_object_visit_const(
|
IKA_API void ikarus_object_visit_const(
|
||||||
IkarusObject const * object,
|
IkarusObject const * object,
|
||||||
void (*blueprint_visitor)(struct IkarusBlueprint const *, void *),
|
void (*blueprint_visitor)(struct IkarusBlueprint const *, IkarusErrorData * error_out, void *),
|
||||||
void (*property_visitor)(struct IkarusProperty const *, void *),
|
void (*property_visitor)(struct IkarusProperty const *, IkarusErrorData * error_out, void *),
|
||||||
void (*entity_visitor)(struct IkarusEntity const *, void *),
|
void (*entity_visitor)(struct IkarusEntity const *, IkarusErrorData * error_out, void *),
|
||||||
void * data,
|
void * data,
|
||||||
IkarusErrorData * error_out
|
IkarusErrorData * error_out
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,6 @@ IKA_API void ikarus_property_delete(IkarusProperty * property, IkarusErrorData *
|
||||||
/// \pre \li Must exist.
|
/// \pre \li Must exist.
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \return The type info of the property or null if an error occurs.
|
/// \return The type info of the property or null if an error occurs.
|
||||||
/// \remark Must be freed using #ikarus_free.
|
|
||||||
IKA_API IkarusPropertyType ikarus_property_get_type(IkarusProperty const * property, IkarusErrorData * error_out);
|
IKA_API IkarusPropertyType ikarus_property_get_type(IkarusProperty const * property, IkarusErrorData * error_out);
|
||||||
|
|
||||||
/// \brief Gets the source of a property.
|
/// \brief Gets the source of a property.
|
||||||
|
|
@ -80,7 +79,7 @@ IKA_API IkarusPropertyType ikarus_property_get_type(IkarusProperty const * prope
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \return The source of the property or null if an error occurs.
|
/// \return The source of the property or null if an error occurs.
|
||||||
/// \remark Must be freed using #ikarus_free.
|
/// \remark Must be freed using #ikarus_free.
|
||||||
IKA_API struct IkarusPropertySource const * ikarus_property_get_source(IkarusProperty const * property, IkarusErrorData * error_out);
|
IKA_API struct IkarusPropertyScope const * ikarus_property_get_scope(IkarusProperty const * property, IkarusErrorData * error_out);
|
||||||
|
|
||||||
/// \brief Gets the default value of a property.
|
/// \brief Gets the default value of a property.
|
||||||
/// \param property The property to get the type info of.
|
/// \param property The property to get the type info of.
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
IKARUS_BEGIN_HEADER
|
IKARUS_BEGIN_HEADER
|
||||||
|
|
||||||
struct IkarusPropertySource;
|
struct IkarusPropertyScope;
|
||||||
|
|
||||||
/// \brief Creates an blueprint property source.
|
/// \brief Creates an blueprint property source.
|
||||||
/// \param blueprint The blueprint to create the property source for.
|
/// \param blueprint The blueprint to create the property source for.
|
||||||
|
|
@ -20,7 +20,7 @@ struct IkarusPropertySource;
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \return The created property source or null if an error occurs.
|
/// \return The created property source or null if an error occurs.
|
||||||
/// \remark Must be freed using #ikarus_free.
|
/// \remark Must be freed using #ikarus_free.
|
||||||
IKA_API struct IkarusPropertySource *
|
IKA_API struct IkarusPropertyScope *
|
||||||
ikarus_property_source_create_blueprint(struct IkarusBlueprint * blueprint, IkarusErrorData * error_out);
|
ikarus_property_source_create_blueprint(struct IkarusBlueprint * blueprint, IkarusErrorData * error_out);
|
||||||
|
|
||||||
/// \brief Creates an entity property source.
|
/// \brief Creates an entity property source.
|
||||||
|
|
@ -30,7 +30,7 @@ ikarus_property_source_create_blueprint(struct IkarusBlueprint * blueprint, Ikar
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \return The created property source or null if an error occurs.
|
/// \return The created property source or null if an error occurs.
|
||||||
/// \remark Must be freed using #ikarus_free.
|
/// \remark Must be freed using #ikarus_free.
|
||||||
IKA_API struct IkarusPropertySource * ikarus_property_source_create_entity(struct IkarusEntity * entity, IkarusErrorData * error_out);
|
IKA_API struct IkarusPropertyScope * ikarus_property_source_create_entity(struct IkarusEntity * entity, IkarusErrorData * error_out);
|
||||||
|
|
||||||
/// \brief Visits a property source, calling the appropriate callback.
|
/// \brief Visits a property source, calling the appropriate callback.
|
||||||
/// \param property_source The property source to visit.
|
/// \param property_source The property source to visit.
|
||||||
|
|
@ -41,7 +41,7 @@ IKA_API struct IkarusPropertySource * ikarus_property_source_create_entity(struc
|
||||||
/// \param user_data User data to pass to the callbacks.
|
/// \param user_data User data to pass to the callbacks.
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
IKA_API void ikarus_property_source_visit(
|
IKA_API void ikarus_property_source_visit(
|
||||||
struct IkarusPropertySource * property_source,
|
struct IkarusPropertyScope * property_source,
|
||||||
void (*blueprint_visitor)(struct IkarusBlueprint *, void *),
|
void (*blueprint_visitor)(struct IkarusBlueprint *, void *),
|
||||||
void (*entity_visitor)(struct IkarusEntity *, void *),
|
void (*entity_visitor)(struct IkarusEntity *, void *),
|
||||||
void * user_data,
|
void * user_data,
|
||||||
|
|
@ -50,7 +50,7 @@ IKA_API void ikarus_property_source_visit(
|
||||||
|
|
||||||
/// \see ikarus_property_source_visit
|
/// \see ikarus_property_source_visit
|
||||||
IKA_API void ikarus_property_source_visit_const(
|
IKA_API void ikarus_property_source_visit_const(
|
||||||
struct IkarusPropertySource const * property_source,
|
struct IkarusPropertyScope const * property_source,
|
||||||
void (*blueprint_visitor)(struct IkarusBlueprint const *, void *),
|
void (*blueprint_visitor)(struct IkarusBlueprint const *, void *),
|
||||||
void (*entity_visitor)(struct IkarusEntity const *, void *),
|
void (*entity_visitor)(struct IkarusEntity const *, void *),
|
||||||
void * user_data,
|
void * user_data,
|
||||||
|
|
@ -80,29 +80,6 @@ IKA_API void ikarus_project_set_name(IkarusProject * project, char const * new_n
|
||||||
/// \remark Ownership remains with libikarus, must not be freed.
|
/// \remark Ownership remains with libikarus, must not be freed.
|
||||||
IKA_API char const * ikarus_project_get_path(IkarusProject const * project, IkarusErrorData * error_out);
|
IKA_API char const * ikarus_project_get_path(IkarusProject const * project, IkarusErrorData * error_out);
|
||||||
|
|
||||||
/// \brief Gets the blueprints of a project.
|
|
||||||
/// \param project The project to get the blueprints of.
|
|
||||||
/// \pre \li Must not be null.
|
|
||||||
/// \pre \li Must exist.
|
|
||||||
/// \param blueprints_out The buffer to write the blueprints to.
|
|
||||||
/// \pre \li Must not be null.
|
|
||||||
/// \param blueprints_out_size The size of the buffer.
|
|
||||||
/// \param error_out \see errors.h
|
|
||||||
IKA_API void ikarus_project_get_blueprints(
|
|
||||||
IkarusProject * project,
|
|
||||||
struct IkarusBlueprint ** blueprints_out,
|
|
||||||
size_t blueprints_out_size,
|
|
||||||
IkarusErrorData * error_out
|
|
||||||
);
|
|
||||||
|
|
||||||
/// \brief Gets the number of blueprints of a project.
|
|
||||||
/// \param project The project to get the number of blueprints of.
|
|
||||||
/// \pre \li Must not be null.
|
|
||||||
/// \pre \li Must exist.
|
|
||||||
/// \param error_out \see errors.h
|
|
||||||
/// \return The number of blueprints or undefined if an error occurs.
|
|
||||||
IKA_API size_t ikarus_project_get_blueprint_count(IkarusProject const * project, IkarusErrorData * error_out);
|
|
||||||
|
|
||||||
/// \brief Gets the entities of a project.
|
/// \brief Gets the entities of a project.
|
||||||
/// \param project The project to get the entities of.
|
/// \param project The project to get the entities of.
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
|
|
@ -126,6 +103,71 @@ IKA_API void ikarus_project_get_entities(
|
||||||
/// \return The number of entities or undefined if an error occurs.
|
/// \return The number of entities or undefined if an error occurs.
|
||||||
IKA_API size_t ikarus_project_get_entity_count(IkarusProject * project, IkarusErrorData * error_out);
|
IKA_API size_t ikarus_project_get_entity_count(IkarusProject * project, IkarusErrorData * error_out);
|
||||||
|
|
||||||
|
/// \brief Gets the blueprints of a project.
|
||||||
|
/// \param project The project to get the blueprints of.
|
||||||
|
/// \pre \li Must not be null.
|
||||||
|
/// \pre \li Must exist.
|
||||||
|
/// \param blueprints_out The buffer to write the blueprints to.
|
||||||
|
/// \pre \li Must not be null.
|
||||||
|
/// \param blueprints_out_size The size of the buffer.
|
||||||
|
/// \param error_out \see errors.h
|
||||||
|
IKA_API void ikarus_project_get_blueprints(
|
||||||
|
IkarusProject * project,
|
||||||
|
struct IkarusBlueprint ** blueprints_out,
|
||||||
|
size_t blueprints_out_size,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
);
|
||||||
|
|
||||||
|
/// \brief Gets the number of blueprints of a project.
|
||||||
|
/// \param project The project to get the number of blueprints of.
|
||||||
|
/// \pre \li Must not be null.
|
||||||
|
/// \pre \li Must exist.
|
||||||
|
/// \param error_out \see errors.h
|
||||||
|
/// \return The number of blueprints or undefined if an error occurs.
|
||||||
|
IKA_API size_t ikarus_project_get_blueprint_count(IkarusProject const * project, IkarusErrorData * error_out);
|
||||||
|
|
||||||
|
/// \brief Finds an entity by a given name.
|
||||||
|
/// \param project The project to search.
|
||||||
|
/// \pre \li Must not be null.
|
||||||
|
/// \pre \li Must exist.
|
||||||
|
/// \param name The name to search for.
|
||||||
|
/// \pre \li Must not be null.
|
||||||
|
/// \pre \li Must not be empty.
|
||||||
|
/// \param error_out \see errors.h
|
||||||
|
/// \return The entity with the given name or null if none was found.
|
||||||
|
IKA_API struct IkarusEntity* get_entity_by_name(
|
||||||
|
IkarusProject const * project,
|
||||||
|
char const * name,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
);
|
||||||
|
|
||||||
|
/// \brief Finds a property by a given name.
|
||||||
|
/// \param project The project to search.
|
||||||
|
/// \pre \li Must not be null.
|
||||||
|
/// \pre \li Must exist.
|
||||||
|
/// \param scope The scope of the property.
|
||||||
|
/// \pre \li Must not be null.
|
||||||
|
/// \pre \li Must exist.
|
||||||
|
/// \remark Property names are unique only within their scope.
|
||||||
|
/// \param name The name to search for.
|
||||||
|
/// \pre \li Must not be null.
|
||||||
|
/// \pre \li Must not be empty.
|
||||||
|
/// \param error_out \see errors.h
|
||||||
|
/// \return The property with the given name or null if none was found.
|
||||||
|
IKA_API struct IkarusProperty *
|
||||||
|
get_property_by_name(IkarusProject const * project, struct IkarusPropertyScope * scope, char const * name, IkarusErrorData * error_out);
|
||||||
|
|
||||||
|
/// \brief Finds a blueprint by a given name.
|
||||||
|
/// \param project The project to search.
|
||||||
|
/// \pre \li Must not be null.
|
||||||
|
/// \pre \li Must exist.
|
||||||
|
/// \param name The name to search for.
|
||||||
|
/// \pre \li Must not be null.
|
||||||
|
/// \pre \li Must not be empty.
|
||||||
|
/// \param error_out \see errors.h
|
||||||
|
/// \return The blueprint with the given name or null if none was found.
|
||||||
|
IKA_API struct IkarusBlueprint * get_blueprints_by_name(IkarusProject const * project, char const * name, IkarusErrorData * error_out);
|
||||||
|
|
||||||
IKARUS_END_HEADER
|
IKARUS_END_HEADER
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
#include "ikarus/errors.h"
|
#include "ikarus/errors.h"
|
||||||
|
|
||||||
#include "cppbase/functional.hpp"
|
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <ranges>
|
#include <ranges>
|
||||||
|
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
|
|
||||||
|
#include <cppbase/functional.hpp>
|
||||||
|
|
||||||
char const * get_error_info_name(IkarusErrorInfo info) {
|
char const * get_error_info_name(IkarusErrorInfo info) {
|
||||||
switch (info) {
|
switch (info) {
|
||||||
case IkarusErrorInfo_None: return "None";
|
case IkarusErrorInfo_None: return "None";
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
#include <ikarus/objects/object_type.h>
|
#include <ikarus/objects/object_type.h>
|
||||||
|
|
||||||
constexpr uint64_t IKARUS_ID_OBJECT_TYPE_BITS = 8;
|
constexpr uint64_t IKARUS_ID_OBJECT_TYPE_BITS = 8;
|
||||||
constexpr uint64_t IKARUS_ID_OBJECT_RANDOM_BITS = sizeof(IkarusId) * 8 - IKARUS_ID_OBJECT_TYPE_BITS;
|
constexpr uint64_t IKARUS_ID_OBJECT_RANDOM_BITS = sizeof(IkarusId) - IKARUS_ID_OBJECT_TYPE_BITS;
|
||||||
|
|
||||||
auto ikarus_id_from_data_and_type(int64_t data, IkarusObjectType type) -> IkarusId {
|
auto ikarus_id_from_data_and_type(int64_t data, IkarusObjectType type) -> IkarusId {
|
||||||
return data | (static_cast<IkarusId>(type) << IKARUS_ID_OBJECT_RANDOM_BITS);
|
return data | (static_cast<IkarusId>(type) << IKARUS_ID_OBJECT_RANDOM_BITS);
|
||||||
|
|
@ -1,24 +1,23 @@
|
||||||
#include "ikarus/objects/blueprint.h"
|
#include "ikarus/objects/blueprint.h"
|
||||||
|
|
||||||
#include "ikarus/objects/properties/property.h"
|
|
||||||
#include "objects/blueprint.hpp"
|
|
||||||
|
|
||||||
#include <cppbase/logger.hpp>
|
#include <cppbase/logger.hpp>
|
||||||
#include <cppbase/result.hpp>
|
#include <cppbase/result.hpp>
|
||||||
#include <cppbase/strings.hpp>
|
#include <cppbase/strings.hpp>
|
||||||
|
|
||||||
#include <errors.hpp>
|
#include <ikarus/errors.hpp>
|
||||||
#include <objects/entity.hpp>
|
#include <ikarus/objects/blueprint.hpp>
|
||||||
#include <objects/properties/property.hpp>
|
#include <ikarus/objects/entity.hpp>
|
||||||
#include <persistence/project.hpp>
|
#include <ikarus/objects/properties/property.h>
|
||||||
|
#include <ikarus/objects/properties/property.hpp>
|
||||||
|
#include <ikarus/objects/util.hpp>
|
||||||
|
#include <ikarus/persistence/project.hpp>
|
||||||
|
|
||||||
IkarusBlueprint::IkarusBlueprint(IkarusProject * project, IkarusId id):
|
IkarusBlueprint::IkarusBlueprint(IkarusProject * project, IkarusId id):
|
||||||
IkarusObject{project, id} {}
|
IkarusObject{project, id} {}
|
||||||
|
|
||||||
IkarusBlueprint * ikarus_blueprint_create(struct IkarusProject * project, char const * name, IkarusErrorData * error_out) {
|
IkarusBlueprint * ikarus_blueprint_create(struct IkarusProject * project, char const * name, IkarusErrorData * error_out) {
|
||||||
IKARUS_FAIL_IF_NULL(project, nullptr);
|
IKARUS_FAIL_IF_NULL(project, nullptr);
|
||||||
IKARUS_FAIL_IF_NULL(name, nullptr);
|
IKARUS_FAIL_IF_NAME_INVALID(name, project, nullptr, nullptr);
|
||||||
IKARUS_FAIL_IF(cppbase::is_empty_or_blank(name), nullptr, "name must not be empty", IkarusErrorInfo_Client_InvalidInput);
|
|
||||||
|
|
||||||
IKARUS_VTRYRV_OR_FAIL(
|
IKARUS_VTRYRV_OR_FAIL(
|
||||||
IkarusId const id,
|
IkarusId const id,
|
||||||
|
|
@ -50,6 +49,18 @@ void ikarus_blueprint_delete(IkarusBlueprint * blueprint, IkarusErrorData * erro
|
||||||
blueprint->project->uncache(blueprint);
|
blueprint->project->uncache(blueprint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IkarusProject * ikarus_blueprint_get_project(IkarusBlueprint const * blueprint, IkarusErrorData * error_out) {
|
||||||
|
return ikarus::util::object_get_project(blueprint, error_out);
|
||||||
|
}
|
||||||
|
|
||||||
|
char const * ikarus_blueprint_get_name(IkarusBlueprint const * blueprint, IkarusErrorData * error_out) {
|
||||||
|
return ikarus::util::object_get_name(blueprint, error_out);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ikarus_blueprint_set_name(IkarusBlueprint * blueprint, char const * name, IkarusErrorData * error_out) {
|
||||||
|
ikarus::util::object_set_name(blueprint, name, error_out);
|
||||||
|
}
|
||||||
|
|
||||||
void ikarus_blueprint_get_properties(
|
void ikarus_blueprint_get_properties(
|
||||||
IkarusBlueprint const * blueprint,
|
IkarusBlueprint const * blueprint,
|
||||||
struct IkarusProperty ** properties_out,
|
struct IkarusProperty ** properties_out,
|
||||||
|
|
@ -147,17 +158,3 @@ size_t ikarus_blueprint_get_linked_entity_count(IkarusBlueprint const * blueprin
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// No existence checks here for performance reasons. All methods on IkarusObject perform this check anyway.
|
|
||||||
|
|
||||||
IkarusObject * ikarus_blueprint_to_object(IkarusBlueprint * blueprint, IkarusErrorData * error_out) {
|
|
||||||
IKARUS_FAIL_IF_NULL(blueprint, nullptr);
|
|
||||||
|
|
||||||
return static_cast<IkarusObject *>(blueprint);
|
|
||||||
}
|
|
||||||
|
|
||||||
IkarusObject const * ikarus_blueprint_to_object_const(IkarusBlueprint const * blueprint, IkarusErrorData * error_out) {
|
|
||||||
IKARUS_FAIL_IF_NULL(blueprint, nullptr);
|
|
||||||
|
|
||||||
return static_cast<IkarusObject const *>(blueprint);
|
|
||||||
}
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <objects/object.hpp>
|
#include <ikarus/objects/object.hpp>
|
||||||
|
|
||||||
struct IkarusBlueprint : IkarusObject {
|
struct IkarusBlueprint : IkarusObject {
|
||||||
|
public:
|
||||||
IkarusBlueprint(struct IkarusProject * project, IkarusId id);
|
IkarusBlueprint(struct IkarusProject * project, IkarusId id);
|
||||||
|
|
||||||
IkarusBlueprint(IkarusBlueprint const &) = default;
|
IkarusBlueprint(IkarusBlueprint const &) = default;
|
||||||
|
|
@ -12,4 +13,9 @@ struct IkarusBlueprint : IkarusObject {
|
||||||
IkarusBlueprint & operator=(IkarusBlueprint &&) = default;
|
IkarusBlueprint & operator=(IkarusBlueprint &&) = default;
|
||||||
|
|
||||||
~IkarusBlueprint() override = default;
|
~IkarusBlueprint() override = default;
|
||||||
|
|
||||||
|
public:
|
||||||
|
inline std::string_view get_table_name() const noexcept override {
|
||||||
|
return "blueprints";
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -1,19 +1,18 @@
|
||||||
#include "entity.hpp"
|
#include "entity.hpp"
|
||||||
|
|
||||||
#include "values/value.hpp"
|
|
||||||
|
|
||||||
#include <cppbase/strings.hpp>
|
#include <cppbase/strings.hpp>
|
||||||
|
|
||||||
#include <errors.hpp>
|
#include <ikarus/errors.hpp>
|
||||||
#include <objects/blueprint.hpp>
|
#include <ikarus/objects/blueprint.hpp>
|
||||||
#include <objects/properties/property.hpp>
|
#include <ikarus/objects/properties/property.hpp>
|
||||||
#include <persistence/project.hpp>
|
#include <ikarus/objects/util.hpp>
|
||||||
#include <values/entity_property_value.hpp>
|
#include <ikarus/persistence/project.hpp>
|
||||||
|
#include <ikarus/values/entity_property_value.hpp>
|
||||||
|
#include <ikarus/values/value.hpp>
|
||||||
|
|
||||||
IkarusEntity * ikarus_entity_create(struct IkarusProject * project, char const * name, IkarusErrorData * error_out) {
|
IkarusEntity * ikarus_entity_create(struct IkarusProject * project, char const * name, IkarusErrorData * error_out) {
|
||||||
IKARUS_FAIL_IF_NULL(project, nullptr);
|
IKARUS_FAIL_IF_NULL(project, nullptr);
|
||||||
IKARUS_FAIL_IF_NULL(name, nullptr);
|
IKARUS_FAIL_IF_NAME_INVALID(name, project, nullptr, nullptr);
|
||||||
IKARUS_FAIL_IF(cppbase::is_empty_or_blank(name), nullptr, "name must not be empty", IkarusErrorInfo_Client_InvalidInput);
|
|
||||||
|
|
||||||
IKARUS_VTRYRV_OR_FAIL(
|
IKARUS_VTRYRV_OR_FAIL(
|
||||||
IkarusId const id,
|
IkarusId const id,
|
||||||
|
|
@ -21,9 +20,9 @@ IkarusEntity * ikarus_entity_create(struct IkarusProject * project, char const *
|
||||||
"failed to create entity: {}",
|
"failed to create entity: {}",
|
||||||
IkarusErrorInfo_Database_QueryFailed,
|
IkarusErrorInfo_Database_QueryFailed,
|
||||||
project->db->transact([name](auto * db) -> cppbase::Result<IkarusId, sqlitecpp::TransactionError> {
|
project->db->transact([name](auto * db) -> cppbase::Result<IkarusId, sqlitecpp::TransactionError> {
|
||||||
TRY(db->execute("INSERT INTO `objects`(`type`, `name`, `information`) VALUES(?, ?, ?)", IkarusObjectType_Entity, name, ""));
|
TRY(db->execute("INSERT INTO `objects`(`type`) VALUES(?, ?, ?)", IkarusObjectType_Entity));
|
||||||
auto id = ikarus_id_from_data_and_type(db->last_insert_rowid(), IkarusObjectType_Entity);
|
auto id = ikarus_id_from_data_and_type(db->last_insert_rowid(), IkarusObjectType_Entity);
|
||||||
TRY(db->execute("INSERT INTO `entities`(`id`) VALUES(?)", id));
|
TRY(db->execute("INSERT INTO `entities`(`id`, `name`) VALUES(?)", id, name));
|
||||||
return cppbase::ok(id);
|
return cppbase::ok(id);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
@ -45,6 +44,18 @@ void ikarus_entity_delete(IkarusEntity * entity, IkarusErrorData * error_out) {
|
||||||
entity->project->uncache(entity);
|
entity->project->uncache(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IkarusProject * ikarus_entity_get_project(IkarusEntity const * entity, IkarusErrorData * error_out) {
|
||||||
|
return ikarus::util::object_get_project(entity, error_out);
|
||||||
|
}
|
||||||
|
|
||||||
|
char const * ikarus_entity_get_name(IkarusEntity const * entity, IkarusErrorData * error_out) {
|
||||||
|
return ikarus::util::object_get_name(entity, error_out);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ikarus_entity_set_name(IkarusEntity * entity, char const * name, IkarusErrorData * error_out) {
|
||||||
|
ikarus::util::object_set_name(entity, name, error_out);
|
||||||
|
}
|
||||||
|
|
||||||
bool ikarus_entity_is_linked_to_blueprint(
|
bool ikarus_entity_is_linked_to_blueprint(
|
||||||
IkarusEntity const * entity,
|
IkarusEntity const * entity,
|
||||||
struct IkarusBlueprint const * blueprint,
|
struct IkarusBlueprint const * blueprint,
|
||||||
|
|
@ -273,17 +284,3 @@ void ikarus_entity_set_value(
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// No existence checks here for performance reasons. All methods on IkarusObject perform this check anyway.
|
|
||||||
|
|
||||||
struct IkarusObject * ikarus_entity_to_object(IkarusEntity * entity, IkarusErrorData * error_out) {
|
|
||||||
IKARUS_FAIL_IF_NULL(entity, nullptr);
|
|
||||||
|
|
||||||
return static_cast<IkarusObject *>(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct IkarusObject const * ikarus_entity_to_object_const(IkarusEntity const * entity, IkarusErrorData * error_out) {
|
|
||||||
IKARUS_FAIL_IF_NULL(entity, nullptr);
|
|
||||||
|
|
||||||
return static_cast<IkarusObject const *>(entity);
|
|
||||||
}
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <objects/object.hpp>
|
#include <ikarus/objects/object.hpp>
|
||||||
|
|
||||||
struct IkarusEntity : IkarusObject {
|
struct IkarusEntity : IkarusObject {
|
||||||
|
public:
|
||||||
inline IkarusEntity(struct IkarusProject * project, IkarusId id):
|
inline IkarusEntity(struct IkarusProject * project, IkarusId id):
|
||||||
IkarusObject{project, id} {}
|
IkarusObject{project, id} {}
|
||||||
|
|
||||||
|
|
@ -13,4 +14,9 @@ struct IkarusEntity : IkarusObject {
|
||||||
IkarusEntity & operator=(IkarusEntity &&) = default;
|
IkarusEntity & operator=(IkarusEntity &&) = default;
|
||||||
|
|
||||||
~IkarusEntity() override = default;
|
~IkarusEntity() override = default;
|
||||||
|
|
||||||
|
public:
|
||||||
|
inline std::string_view get_table_name() const noexcept override {
|
||||||
|
return "entities";
|
||||||
|
}
|
||||||
};
|
};
|
||||||
93
src/ikarus/objects/object.cpp
Normal file
93
src/ikarus/objects/object.cpp
Normal file
|
|
@ -0,0 +1,93 @@
|
||||||
|
#include "object.hpp"
|
||||||
|
|
||||||
|
#include <fmt/format.h>
|
||||||
|
|
||||||
|
#include <cppbase/strings.hpp>
|
||||||
|
|
||||||
|
#include <ikarus/errors.h>
|
||||||
|
#include <ikarus/errors.hpp>
|
||||||
|
#include <ikarus/objects/blueprint.hpp>
|
||||||
|
#include <ikarus/objects/entity.hpp>
|
||||||
|
#include <ikarus/objects/object.h>
|
||||||
|
#include <ikarus/objects/properties/property.hpp>
|
||||||
|
#include <ikarus/persistence/project.hpp>
|
||||||
|
|
||||||
|
IkarusObject::IkarusObject(IkarusProject * project, IkarusId id):
|
||||||
|
project{project},
|
||||||
|
id{id} {}
|
||||||
|
|
||||||
|
void ikarus_object_visit(
|
||||||
|
IkarusObject * object,
|
||||||
|
void (*blueprint_visitor)(struct IkarusBlueprint *, IkarusErrorData * error_out, void *),
|
||||||
|
void (*property_visitor)(struct IkarusProperty *, IkarusErrorData * error_out, void *),
|
||||||
|
void (*entity_visitor)(struct IkarusEntity *, IkarusErrorData * error_out, void *),
|
||||||
|
void * data,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
) {
|
||||||
|
struct Data {
|
||||||
|
void (*blueprint_visitor)(struct IkarusBlueprint *, IkarusErrorData * error_out, void *);
|
||||||
|
void (*property_visitor)(struct IkarusProperty *, IkarusErrorData * error_out, void *);
|
||||||
|
void (*entity_visitor)(struct IkarusEntity *, IkarusErrorData * error_out, void *);
|
||||||
|
void * data;
|
||||||
|
};
|
||||||
|
|
||||||
|
Data passthru_data{blueprint_visitor, property_visitor, entity_visitor, data};
|
||||||
|
|
||||||
|
ikarus_object_visit_const(
|
||||||
|
object,
|
||||||
|
[](IkarusBlueprint const * blueprint, IkarusErrorData * error_out, void * data) {
|
||||||
|
auto const * passthru_data = static_cast<Data *>(data);
|
||||||
|
passthru_data->blueprint_visitor(const_cast<IkarusBlueprint *>(blueprint), error_out, passthru_data->data);
|
||||||
|
},
|
||||||
|
[](IkarusProperty const * property, IkarusErrorData * error_out, void * data) {
|
||||||
|
auto const * passthru_data = static_cast<Data *>(data);
|
||||||
|
passthru_data->property_visitor(const_cast<IkarusProperty *>(property), error_out, passthru_data->data);
|
||||||
|
},
|
||||||
|
[](IkarusEntity const * entity, IkarusErrorData * error_out, void * data) {
|
||||||
|
auto const * passthru_data = static_cast<Data *>(data);
|
||||||
|
passthru_data->entity_visitor(const_cast<IkarusEntity *>(entity), error_out, passthru_data->data);
|
||||||
|
},
|
||||||
|
&passthru_data,
|
||||||
|
error_out
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ikarus_object_visit_const(
|
||||||
|
IkarusObject const * object,
|
||||||
|
void (*blueprint_visitor)(struct IkarusBlueprint const *, IkarusErrorData * error_out, void *),
|
||||||
|
void (*property_visitor)(struct IkarusProperty const *, IkarusErrorData * error_out, void *),
|
||||||
|
void (*entity_visitor)(struct IkarusEntity const *, IkarusErrorData * error_out, void *),
|
||||||
|
void * data,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
) {
|
||||||
|
IKARUS_FAIL_IF_NULL(object, );
|
||||||
|
IKARUS_FAIL_IF_OBJECT_MISSING(object, );
|
||||||
|
|
||||||
|
switch (ikarus_id_get_object_type(object->id)) {
|
||||||
|
case IkarusObjectType_Entity: {
|
||||||
|
auto const * entity = dynamic_cast<IkarusEntity const *>(object);
|
||||||
|
IKARUS_FAIL_IF(entity == nullptr, , "object with entity id wasn't a entity", IkarusErrorInfo_LibIkarus_InvalidState);
|
||||||
|
entity_visitor(entity, error_out, data);
|
||||||
|
}
|
||||||
|
case IkarusObjectType_Blueprint: {
|
||||||
|
auto const * blueprint = dynamic_cast<IkarusBlueprint const *>(object);
|
||||||
|
IKARUS_FAIL_IF(blueprint == nullptr, , "object with blueprint id wasn't a blueprint", IkarusErrorInfo_LibIkarus_InvalidState);
|
||||||
|
blueprint_visitor(blueprint, error_out, data);
|
||||||
|
}
|
||||||
|
case IkarusObjectType_Property: {
|
||||||
|
auto const * property = dynamic_cast<IkarusProperty const *>(object);
|
||||||
|
IKARUS_FAIL_IF(property == nullptr, , "object with property id wasn't a property", IkarusErrorInfo_LibIkarus_InvalidState);
|
||||||
|
property_visitor(property, error_out, data);
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
IKARUS_FAIL(
|
||||||
|
,
|
||||||
|
fmt::format("unknown object type: {}", ikarus_object_type_to_string(ikarus_id_get_object_type(object->id))),
|
||||||
|
IkarusErrorInfo_LibIkarus_InvalidState
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// not needed, but a good delineation of our intention if this function gets extended
|
||||||
|
IKARUS_FAIL_IF_ERROR()
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
#include <ikarus/id.h>
|
#include <ikarus/id.h>
|
||||||
|
|
||||||
struct IkarusObject {
|
struct IkarusObject {
|
||||||
|
|
@ -14,6 +16,9 @@ public:
|
||||||
|
|
||||||
virtual ~IkarusObject() = default;
|
virtual ~IkarusObject() = default;
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual std::string_view get_table_name() const noexcept = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
struct IkarusProject * project;
|
struct IkarusProject * project;
|
||||||
IkarusId id;
|
IkarusId id;
|
||||||
|
|
@ -1,13 +1,11 @@
|
||||||
#include "ikarus/objects/properties/number_property.h"
|
#include "number_property.hpp"
|
||||||
|
|
||||||
#include <cppbase/result.hpp>
|
#include <cppbase/result.hpp>
|
||||||
|
|
||||||
#include <ikarus/objects/properties/property.h>
|
#include <ikarus/objects/properties/property.h>
|
||||||
|
#include <ikarus/objects/properties/property_scope.hpp>
|
||||||
#include <objects/properties/number_property.hpp>
|
#include <ikarus/objects/properties/util.hpp>
|
||||||
#include <objects/properties/property_source.hpp>
|
#include <ikarus/values/value.hpp>
|
||||||
#include <objects/properties/util.hpp>
|
|
||||||
#include <values/value.hpp>
|
|
||||||
|
|
||||||
IkarusNumberProperty::IkarusNumberProperty(IkarusProject * project, IkarusId id):
|
IkarusNumberProperty::IkarusNumberProperty(IkarusProject * project, IkarusId id):
|
||||||
IkarusProperty{project, id, this} {}
|
IkarusProperty{project, id, this} {}
|
||||||
|
|
@ -15,11 +13,10 @@ IkarusNumberProperty::IkarusNumberProperty(IkarusProject * project, IkarusId id)
|
||||||
IkarusNumberProperty * ikarus_number_property_create(
|
IkarusNumberProperty * ikarus_number_property_create(
|
||||||
struct IkarusProject * project,
|
struct IkarusProject * project,
|
||||||
char const * name,
|
char const * name,
|
||||||
struct IkarusPropertySource * property_source,
|
struct IkarusPropertyScope * property_source,
|
||||||
struct IkarusNumberValue * default_value,
|
|
||||||
IkarusErrorData * error_out
|
IkarusErrorData * error_out
|
||||||
) {
|
) {
|
||||||
return ikarus::util::create_property<IkarusNumberProperty>(project, name, property_source, default_value, error_out);
|
return ikarus::util::create_property<IkarusNumberProperty>(project, name, property_source, 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) {
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <ikarus/objects/properties/property.hpp>
|
||||||
#include <ikarus/objects/properties/property_type.h>
|
#include <ikarus/objects/properties/property_type.h>
|
||||||
|
#include <ikarus/values/number_value.hpp>
|
||||||
#include <objects/properties/property.hpp>
|
|
||||||
#include <values/number_value.hpp>
|
|
||||||
|
|
||||||
struct IkarusNumberProperty : IkarusProperty {
|
struct IkarusNumberProperty : IkarusProperty {
|
||||||
public:
|
public:
|
||||||
|
|
@ -2,14 +2,13 @@
|
||||||
|
|
||||||
#include <cppbase/logger.hpp>
|
#include <cppbase/logger.hpp>
|
||||||
|
|
||||||
|
#include <ikarus/errors.hpp>
|
||||||
#include <ikarus/objects/properties/property.h>
|
#include <ikarus/objects/properties/property.h>
|
||||||
|
#include <ikarus/objects/properties/property_scope.hpp>
|
||||||
#include <ikarus/objects/properties/property_type.h>
|
#include <ikarus/objects/properties/property_type.h>
|
||||||
|
#include <ikarus/objects/util.hpp>
|
||||||
#include <errors.hpp>
|
#include <ikarus/persistence/project.hpp>
|
||||||
#include <objects/properties/property_source.hpp>
|
#include <ikarus/values/value.hpp>
|
||||||
#include <persistence/project.hpp>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <values/value.hpp>
|
|
||||||
|
|
||||||
IkarusProperty::IkarusProperty(IkarusProject * project, IkarusId id, Data data):
|
IkarusProperty::IkarusProperty(IkarusProject * project, IkarusId id, Data data):
|
||||||
IkarusObject{project, id},
|
IkarusObject{project, id},
|
||||||
|
|
@ -29,6 +28,18 @@ IKA_API void ikarus_property_delete(IkarusProperty * property, IkarusErrorData *
|
||||||
property->project->uncache(property);
|
property->project->uncache(property);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IkarusProject * ikarus_property_get_project(IkarusProperty const * property, IkarusErrorData * error_out) {
|
||||||
|
return ikarus::util::object_get_project(property, error_out);
|
||||||
|
}
|
||||||
|
|
||||||
|
char const * ikarus_property_get_name(IkarusProperty const * property, IkarusErrorData * error_out) {
|
||||||
|
return ikarus::util::object_get_name(property, error_out);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ikarus_property_set_name(IkarusProperty * property, char const * name, IkarusErrorData * error_out) {
|
||||||
|
ikarus::util::object_set_name(property, name, error_out);
|
||||||
|
}
|
||||||
|
|
||||||
IkarusPropertyType ikarus_property_get_type(IkarusProperty const * property, IkarusErrorData * error_out) {
|
IkarusPropertyType ikarus_property_get_type(IkarusProperty const * property, IkarusErrorData * error_out) {
|
||||||
IKARUS_FAIL_IF_NULL(property, IkarusPropertyType_Toggle);
|
IKARUS_FAIL_IF_NULL(property, IkarusPropertyType_Toggle);
|
||||||
IKARUS_FAIL_IF_OBJECT_MISSING(property, IkarusPropertyType_Toggle);
|
IKARUS_FAIL_IF_OBJECT_MISSING(property, IkarusPropertyType_Toggle);
|
||||||
|
|
@ -44,7 +55,7 @@ IkarusPropertyType ikarus_property_get_type(IkarusProperty const * property, Ika
|
||||||
return static_cast<IkarusPropertyType>(ret);
|
return static_cast<IkarusPropertyType>(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
IkarusPropertySource const * ikarus_property_get_source(IkarusProperty const * property, IkarusErrorData * error_out) {
|
IkarusPropertyScope const * ikarus_property_get_scope(IkarusProperty const * property, IkarusErrorData * error_out) {
|
||||||
IKARUS_FAIL_IF_NULL(property, nullptr);
|
IKARUS_FAIL_IF_NULL(property, nullptr);
|
||||||
IKARUS_FAIL_IF_OBJECT_MISSING(property, nullptr);
|
IKARUS_FAIL_IF_OBJECT_MISSING(property, nullptr);
|
||||||
|
|
||||||
|
|
@ -57,8 +68,8 @@ IkarusPropertySource const * ikarus_property_get_source(IkarusProperty const * p
|
||||||
);
|
);
|
||||||
|
|
||||||
switch (ikarus_id_get_object_type(source)) {
|
switch (ikarus_id_get_object_type(source)) {
|
||||||
case IkarusObjectType_Blueprint: return new IkarusPropertySource{property->project->get_blueprint(source)};
|
case IkarusObjectType_Blueprint: return new IkarusPropertyScope{property->project->get_blueprint(source)};
|
||||||
case IkarusObjectType_Entity: return new IkarusPropertySource{property->project->get_entity(source)};
|
case IkarusObjectType_Entity: return new IkarusPropertyScope{property->project->get_entity(source)};
|
||||||
default:
|
default:
|
||||||
IKARUS_FAIL(
|
IKARUS_FAIL(
|
||||||
nullptr,
|
nullptr,
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#include <variant>
|
#include <variant>
|
||||||
|
|
||||||
#include <objects/object.hpp>
|
#include <ikarus/objects/object.hpp>
|
||||||
|
|
||||||
struct IkarusProperty : IkarusObject {
|
struct IkarusProperty : IkarusObject {
|
||||||
public:
|
public:
|
||||||
|
|
@ -19,6 +19,11 @@ public:
|
||||||
|
|
||||||
~IkarusProperty() override = default;
|
~IkarusProperty() override = default;
|
||||||
|
|
||||||
|
public:
|
||||||
|
inline std::string_view get_table_name() const noexcept override {
|
||||||
|
return "properties";
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Data data;
|
Data data;
|
||||||
};
|
};
|
||||||
|
|
@ -1,16 +1,15 @@
|
||||||
#include "property_source.hpp"
|
#include "property_scope.hpp"
|
||||||
|
|
||||||
#include <boost/functional/overloaded_function.hpp>
|
|
||||||
|
|
||||||
#include <objects/blueprint.hpp>
|
|
||||||
#include <objects/entity.hpp>
|
|
||||||
#include <cppbase/templates.hpp>
|
#include <cppbase/templates.hpp>
|
||||||
|
|
||||||
IkarusPropertySource::IkarusPropertySource(Data data):
|
#include <ikarus/objects/blueprint.hpp>
|
||||||
|
#include <ikarus/objects/entity.hpp>
|
||||||
|
|
||||||
|
IkarusPropertyScope::IkarusPropertyScope(Data data):
|
||||||
data{data} {}
|
data{data} {}
|
||||||
|
|
||||||
IkarusId IkarusPropertySource::get_id() const {
|
IkarusId IkarusPropertyScope::get_id() const {
|
||||||
return boost::variant2::visit(
|
return std::visit(
|
||||||
cppbase::overloaded{
|
cppbase::overloaded{
|
||||||
[](IkarusBlueprint const * blueprint) { return blueprint->id; },
|
[](IkarusBlueprint const * blueprint) { return blueprint->id; },
|
||||||
[](IkarusEntity const * entity) { return entity->id; }
|
[](IkarusEntity const * entity) { return entity->id; }
|
||||||
|
|
@ -19,37 +18,37 @@ IkarusId IkarusPropertySource::get_id() const {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
IkarusPropertySource * ikarus_property_source_create_blueprint(IkarusBlueprint * blueprint) {
|
IkarusPropertyScope * ikarus_property_source_create_blueprint(IkarusBlueprint * blueprint) {
|
||||||
return new IkarusPropertySource{blueprint};
|
return new IkarusPropertyScope{blueprint};
|
||||||
}
|
}
|
||||||
|
|
||||||
IkarusPropertySource * ikarus_property_source_create_entity(IkarusEntity * entity) {
|
IkarusPropertyScope * ikarus_property_source_create_entity(IkarusEntity * entity) {
|
||||||
return new IkarusPropertySource{entity};
|
return new IkarusPropertyScope{entity};
|
||||||
}
|
}
|
||||||
|
|
||||||
void ikarus_property_source_visit(
|
void ikarus_property_source_visit(
|
||||||
struct IkarusPropertySource * property_source,
|
struct IkarusPropertyScope * property_source,
|
||||||
void (*blueprint_visitor)(struct IkarusBlueprint *, void *),
|
void (*blueprint_visitor)(struct IkarusBlueprint *, void *),
|
||||||
void (*entity_visitor)(struct IkarusEntity *, void *),
|
void (*entity_visitor)(struct IkarusEntity *, void *),
|
||||||
void * user_data
|
void * user_data
|
||||||
) {
|
) {
|
||||||
boost::variant2::visit(
|
std::visit(
|
||||||
boost::make_overloaded_function(
|
cppbase::overloaded{
|
||||||
[blueprint_visitor, user_data](IkarusBlueprint * blueprint) { blueprint_visitor(blueprint, user_data); },
|
[blueprint_visitor, user_data](IkarusBlueprint * blueprint) { blueprint_visitor(blueprint, user_data); },
|
||||||
[entity_visitor, user_data](IkarusEntity * entity) { entity_visitor(entity, user_data); }
|
[entity_visitor, user_data](IkarusEntity * entity) { entity_visitor(entity, user_data); }
|
||||||
),
|
},
|
||||||
property_source->data
|
property_source->data
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ikarus_property_source_visit_const(
|
void ikarus_property_source_visit_const(
|
||||||
struct IkarusPropertySource const * property_source,
|
struct IkarusPropertyScope const * property_source,
|
||||||
void (*blueprint_visitor)(struct IkarusBlueprint const *, void *),
|
void (*blueprint_visitor)(struct IkarusBlueprint const *, void *),
|
||||||
void (*entity_visitor)(struct IkarusEntity const *, void *),
|
void (*entity_visitor)(struct IkarusEntity const *, void *),
|
||||||
void * user_data
|
void * user_data
|
||||||
) {
|
) {
|
||||||
boost::variant2::visit(
|
std::visit(
|
||||||
boost::make_overloaded_function(
|
cppbase::overloaded(
|
||||||
[blueprint_visitor, user_data](IkarusBlueprint const * blueprint) { blueprint_visitor(blueprint, user_data); },
|
[blueprint_visitor, user_data](IkarusBlueprint const * blueprint) { blueprint_visitor(blueprint, user_data); },
|
||||||
[entity_visitor, user_data](IkarusEntity const * entity) { entity_visitor(entity, user_data); }
|
[entity_visitor, user_data](IkarusEntity const * entity) { entity_visitor(entity, user_data); }
|
||||||
),
|
),
|
||||||
39
src/ikarus/objects/properties/property_scope.hpp
Normal file
39
src/ikarus/objects/properties/property_scope.hpp
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <variant>
|
||||||
|
|
||||||
|
#include <ikarus/id.h>
|
||||||
|
#include <ikarus/objects/properties/property_scope.h>
|
||||||
|
|
||||||
|
#define IKARUS_FAIL_IF_PROPERTY_SCOPE_INVALID(scope, ret) \
|
||||||
|
std::visit( \
|
||||||
|
cppbase::overloaded{[error_out](auto const * object) { \
|
||||||
|
IKARUS_FAIL_IF_NULL(object, ); \
|
||||||
|
IKARUS_FAIL_IF_OBJECT_MISSING(object, ); \
|
||||||
|
}}, \
|
||||||
|
scope->data \
|
||||||
|
); \
|
||||||
|
\
|
||||||
|
IKARUS_FAIL_IF_ERROR(nullptr);
|
||||||
|
|
||||||
|
struct IkarusPropertyScope {
|
||||||
|
public:
|
||||||
|
using Data = std::variant<IkarusBlueprint *, IkarusEntity *>;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit IkarusPropertyScope(Data data);
|
||||||
|
|
||||||
|
IkarusPropertyScope(IkarusPropertyScope const &) = default;
|
||||||
|
IkarusPropertyScope(IkarusPropertyScope &&) = default;
|
||||||
|
|
||||||
|
IkarusPropertyScope & operator=(IkarusPropertyScope const &) = default;
|
||||||
|
IkarusPropertyScope & operator=(IkarusPropertyScope &&) = default;
|
||||||
|
|
||||||
|
virtual ~IkarusPropertyScope() = default;
|
||||||
|
|
||||||
|
public:
|
||||||
|
[[nodiscard]] IkarusId get_id() const;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Data data;
|
||||||
|
};
|
||||||
|
|
@ -3,10 +3,9 @@
|
||||||
#include <cppbase/result.hpp>
|
#include <cppbase/result.hpp>
|
||||||
|
|
||||||
#include <ikarus/objects/properties/property.h>
|
#include <ikarus/objects/properties/property.h>
|
||||||
|
#include <ikarus/objects/properties/property_scope.hpp>
|
||||||
#include <objects/properties/property_source.hpp>
|
#include <ikarus/objects/properties/util.hpp>
|
||||||
#include <objects/properties/util.hpp>
|
#include <ikarus/values/value.hpp>
|
||||||
#include <values/value.hpp>
|
|
||||||
|
|
||||||
IkarusTextProperty::IkarusTextProperty(IkarusProject * project, IkarusId id):
|
IkarusTextProperty::IkarusTextProperty(IkarusProject * project, IkarusId id):
|
||||||
IkarusProperty{project, id, this} {}
|
IkarusProperty{project, id, this} {}
|
||||||
|
|
@ -14,11 +13,10 @@ IkarusTextProperty::IkarusTextProperty(IkarusProject * project, IkarusId id):
|
||||||
IkarusTextProperty * ikarus_text_property_create(
|
IkarusTextProperty * ikarus_text_property_create(
|
||||||
struct IkarusProject * project,
|
struct IkarusProject * project,
|
||||||
char const * name,
|
char const * name,
|
||||||
struct IkarusPropertySource * property_source,
|
struct IkarusPropertyScope * property_source,
|
||||||
struct IkarusTextValue * default_value,
|
|
||||||
IkarusErrorData * error_out
|
IkarusErrorData * error_out
|
||||||
) {
|
) {
|
||||||
return ikarus::util::create_property<IkarusTextProperty>(project, name, property_source, default_value, error_out);
|
return ikarus::util::create_property<IkarusTextProperty>(project, name, property_source, 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) {
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <ikarus/objects/properties/property.hpp>
|
||||||
#include <ikarus/objects/properties/property_type.h>
|
#include <ikarus/objects/properties/property_type.h>
|
||||||
|
#include <ikarus/values/text_value.hpp>
|
||||||
#include <objects/properties/property.hpp>
|
|
||||||
#include <values/text_value.hpp>
|
|
||||||
|
|
||||||
struct IkarusTextProperty : IkarusProperty {
|
struct IkarusTextProperty : IkarusProperty {
|
||||||
public:
|
public:
|
||||||
|
|
@ -3,10 +3,9 @@
|
||||||
#include <cppbase/result.hpp>
|
#include <cppbase/result.hpp>
|
||||||
|
|
||||||
#include <ikarus/objects/properties/property.h>
|
#include <ikarus/objects/properties/property.h>
|
||||||
|
#include <ikarus/objects/properties/property_scope.hpp>
|
||||||
#include <objects/properties/property_source.hpp>
|
#include <ikarus/objects/properties/util.hpp>
|
||||||
#include <objects/properties/util.hpp>
|
#include <ikarus/values/value.hpp>
|
||||||
#include <values/value.hpp>
|
|
||||||
|
|
||||||
IkarusToggleProperty::IkarusToggleProperty(IkarusProject * project, IkarusId id):
|
IkarusToggleProperty::IkarusToggleProperty(IkarusProject * project, IkarusId id):
|
||||||
IkarusProperty{project, id, this} {}
|
IkarusProperty{project, id, this} {}
|
||||||
|
|
@ -14,11 +13,10 @@ IkarusToggleProperty::IkarusToggleProperty(IkarusProject * project, IkarusId id)
|
||||||
IkarusToggleProperty * ikarus_toggle_property_create(
|
IkarusToggleProperty * ikarus_toggle_property_create(
|
||||||
struct IkarusProject * project,
|
struct IkarusProject * project,
|
||||||
char const * name,
|
char const * name,
|
||||||
struct IkarusPropertySource * property_source,
|
struct IkarusPropertyScope * property_source,
|
||||||
struct IkarusToggleValue * default_value,
|
|
||||||
IkarusErrorData * error_out
|
IkarusErrorData * error_out
|
||||||
) {
|
) {
|
||||||
return ikarus::util::create_property<IkarusToggleProperty>(project, name, property_source, default_value, error_out);
|
return ikarus::util::create_property<IkarusToggleProperty>(project, name, property_source, 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) {
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <ikarus/objects/properties/property.hpp>
|
||||||
#include <ikarus/objects/properties/property_type.h>
|
#include <ikarus/objects/properties/property_type.h>
|
||||||
|
#include <ikarus/values/toggle_value.hpp>
|
||||||
#include <objects/properties/property.hpp>
|
|
||||||
#include <values/toggle_value.hpp>
|
|
||||||
|
|
||||||
struct IkarusToggleProperty : IkarusProperty {
|
struct IkarusToggleProperty : IkarusProperty {
|
||||||
public:
|
public:
|
||||||
|
|
@ -4,48 +4,40 @@
|
||||||
|
|
||||||
#include <cppbase/strings.hpp>
|
#include <cppbase/strings.hpp>
|
||||||
|
|
||||||
|
#include <ikarus/errors.hpp>
|
||||||
#include <ikarus/objects/properties/property.h>
|
#include <ikarus/objects/properties/property.h>
|
||||||
|
#include <ikarus/objects/properties/property.hpp>
|
||||||
#include <errors.hpp>
|
#include <ikarus/objects/properties/property_scope.hpp>
|
||||||
#include <objects/properties/property.hpp>
|
#include <ikarus/objects/util.hpp>
|
||||||
#include <objects/properties/property_source.hpp>
|
#include <ikarus/persistence/project.hpp>
|
||||||
#include <persistence/project.hpp>
|
#include <ikarus/values/value.hpp>
|
||||||
#include <values/value.hpp>
|
|
||||||
|
|
||||||
namespace ikarus::util {
|
namespace ikarus::util {
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T * create_property(
|
T * create_property(
|
||||||
struct IkarusProject * project,
|
struct IkarusProject * project,
|
||||||
char const * name,
|
char const * name,
|
||||||
struct IkarusPropertySource * property_source,
|
struct IkarusPropertyScope * property_scope,
|
||||||
typename T::value_type * default_value,
|
|
||||||
IkarusErrorData * error_out
|
IkarusErrorData * error_out
|
||||||
) {
|
) {
|
||||||
IKARUS_FAIL_IF_NULL(project, nullptr);
|
IKARUS_FAIL_IF_NULL(project, nullptr);
|
||||||
IKARUS_FAIL_IF_NULL(name, nullptr);
|
IKARUS_FAIL_IF_NULL(property_scope, nullptr);
|
||||||
IKARUS_FAIL_IF_NULL(property_source, nullptr);
|
IKARUS_FAIL_IF_PROPERTY_SCOPE_INVALID(property_scope, nullptr);
|
||||||
IKARUS_FAIL_IF(
|
IKARUS_FAIL_IF_NAME_INVALID(name, project, property_scope, nullptr);
|
||||||
cppbase::is_empty_or_blank(name),
|
|
||||||
nullptr,
|
|
||||||
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(
|
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, default_value](auto * db) -> cppbase::Result<IkarusId, sqlitecpp::TransactionError> {
|
project->db->transact([name, property_scope](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`, `default_value`) VALUES(?, ?, ?, ?)",
|
"INSERT INTO `properties`(`id`, `type`, `source`) VALUES(?, ?, ?)",
|
||||||
id,
|
id,
|
||||||
T::PropertyType,
|
T::PropertyType,
|
||||||
property_source->get_id(),
|
property_scope->get_id()
|
||||||
boost::json::serialize(default_value->to_json())
|
|
||||||
));
|
));
|
||||||
return cppbase::ok(id);
|
return cppbase::ok(id);
|
||||||
})
|
})
|
||||||
125
src/ikarus/objects/util.hpp
Normal file
125
src/ikarus/objects/util.hpp
Normal file
|
|
@ -0,0 +1,125 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
|
#include <cppbase/strings.hpp>
|
||||||
|
|
||||||
|
#include <ikarus/errors.h>
|
||||||
|
#include <ikarus/errors.hpp>
|
||||||
|
#include <ikarus/objects/blueprint.hpp>
|
||||||
|
#include <ikarus/objects/entity.hpp>
|
||||||
|
#include <ikarus/objects/object.hpp>
|
||||||
|
#include <ikarus/objects/properties/property.h>
|
||||||
|
#include <ikarus/objects/properties/property.hpp>
|
||||||
|
#include <ikarus/objects/properties/property_scope.hpp>
|
||||||
|
#include <ikarus/persistence/project.hpp>
|
||||||
|
|
||||||
|
namespace ikarus::util {
|
||||||
|
|
||||||
|
template<typename O>
|
||||||
|
[[nodiscard]] IkarusProject * object_get_project(O const * object, IkarusErrorData * error_out) {
|
||||||
|
IKARUS_FAIL_IF_NULL(object, nullptr);
|
||||||
|
IKARUS_FAIL_IF_OBJECT_MISSING(object, nullptr);
|
||||||
|
|
||||||
|
return object->project;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename O>
|
||||||
|
[[nodiscard]] char const * object_get_name(O const * object, IkarusErrorData * error_out) {
|
||||||
|
IKARUS_FAIL_IF_NULL(object, nullptr);
|
||||||
|
IKARUS_FAIL_IF_OBJECT_MISSING(object, nullptr);
|
||||||
|
|
||||||
|
IKARUS_VTRYRV_OR_FAIL(
|
||||||
|
auto const ret,
|
||||||
|
nullptr,
|
||||||
|
fmt::runtime(fmt::format("unable to fetch {} name: {{}}", ikarus_object_type_to_string(ikarus_id_get_object_type(object->id)))),
|
||||||
|
IkarusErrorInfo_Database_QueryFailed,
|
||||||
|
object->project->db
|
||||||
|
->template query_one<std::string>(fmt::format("SELECT `name` FROM `{}` WHERE `id` = ?", object->get_table_name()), object->id)
|
||||||
|
);
|
||||||
|
|
||||||
|
return strdup(ret.data());
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] inline bool name_is_unique(
|
||||||
|
IkarusProject const * project,
|
||||||
|
std::string_view name,
|
||||||
|
[[maybe_unused]] IkarusBlueprint const * blueprint,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
) {
|
||||||
|
IKARUS_VTRYRV_OR_FAIL(
|
||||||
|
bool const exists,
|
||||||
|
false,
|
||||||
|
"unable to check if blueprint name is unique",
|
||||||
|
IkarusErrorInfo_Database_QueryFailed,
|
||||||
|
project->db->query_one<bool>("SELECT EXISTS(SELECT 1 FROM `blueprints` WHERE `name` = ?)", name)
|
||||||
|
);
|
||||||
|
|
||||||
|
return exists;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] inline bool name_is_unique(
|
||||||
|
IkarusProject const * project,
|
||||||
|
std::string_view name,
|
||||||
|
[[maybe_unused]] IkarusEntity const * entity,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
) {
|
||||||
|
IKARUS_VTRYRV_OR_FAIL(
|
||||||
|
bool const exists,
|
||||||
|
false,
|
||||||
|
"unable to check if entity name is unique",
|
||||||
|
IkarusErrorInfo_Database_QueryFailed,
|
||||||
|
project->db->query_one<bool>("SELECT EXISTS(SELECT 1 FROM `entities` WHERE `name` = ?)", name)
|
||||||
|
);
|
||||||
|
|
||||||
|
return exists;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] inline bool
|
||||||
|
name_is_unique(IkarusProject const * project, std::string_view name, IkarusPropertyScope const * scope, IkarusErrorData * error_out) {
|
||||||
|
IKARUS_VTRYRV_OR_FAIL(
|
||||||
|
bool const exists,
|
||||||
|
false,
|
||||||
|
"unable to check if property name is unique",
|
||||||
|
IkarusErrorInfo_Database_QueryFailed,
|
||||||
|
project->db->query_one<bool>("SELECT EXISTS(SELECT 1 FROM `properties` WHERE `name` = ? AND `scope` = ?)", name, scope->get_id())
|
||||||
|
);
|
||||||
|
|
||||||
|
return exists;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] inline bool
|
||||||
|
name_is_unique(IkarusProject * project, std::string_view name, IkarusProperty const * property, IkarusErrorData * error_out) {
|
||||||
|
std::unique_ptr<IkarusPropertyScope const> scope{ikarus_property_get_scope(property, error_out)};
|
||||||
|
IKARUS_FAIL_IF_ERROR(false);
|
||||||
|
|
||||||
|
return name_is_unique(project, name, scope.get(), error_out);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define IKARUS_FAIL_IF_NAME_INVALID(name, project, object, ret, ...) \
|
||||||
|
IKARUS_FAIL_IF_NULL(name, ret); \
|
||||||
|
IKARUS_FAIL_IF(cppbase::is_empty_or_blank(name), ret, "name must not be empty", IkarusErrorInfo_Client_InvalidInput); \
|
||||||
|
IKARUS_FAIL_IF( \
|
||||||
|
!ikarus::util::name_is_unique(project, name, object, error_out), \
|
||||||
|
ret, \
|
||||||
|
"name must be unique", \
|
||||||
|
IkarusErrorInfo_Client_InvalidInput \
|
||||||
|
); \
|
||||||
|
IKARUS_FAIL_IF_ERROR(ret);
|
||||||
|
|
||||||
|
template<typename O>
|
||||||
|
void object_set_name(O * object, char const * name, IkarusErrorData * error_out) {
|
||||||
|
IKARUS_FAIL_IF_NULL(object, );
|
||||||
|
IKARUS_FAIL_IF_OBJECT_MISSING(object, );
|
||||||
|
IKARUS_FAIL_IF_NULL(name, );
|
||||||
|
IKARUS_FAIL_IF_NAME_INVALID(name, object->project, object, );
|
||||||
|
|
||||||
|
IKARUS_TRYRV_OR_FAIL(
|
||||||
|
,
|
||||||
|
fmt::runtime(fmt::format("unable to set {} name: {{}}", ikarus_object_type_to_string(ikarus_id_get_object_type(object->id)))),
|
||||||
|
IkarusErrorInfo_Database_QueryFailed,
|
||||||
|
object->project->db->execute(fmt::format("UPDATE `{}` SET `name` = ? WHERE `id` = ?", object->get_table_name()), name, object->id)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace ikarus::util
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
#include <sqlitecpp/connection.hpp>
|
#include <sqlitecpp/connection.hpp>
|
||||||
|
|
||||||
namespace ikarus {
|
namespace ikarus {
|
||||||
CPPBASE_ASSET(m0_initial_layout, "persistence/migrations/m0_initial_layout.sql");
|
CPPBASE_ASSET(m0_initial_layout, "ikarus/persistence/migrations/m0_initial_layout.sql");
|
||||||
|
|
||||||
class Migration : public sqlitecpp::Migration {
|
class Migration : public sqlitecpp::Migration {
|
||||||
public:
|
public:
|
||||||
|
|
@ -2,36 +2,29 @@ CREATE TABLE `objects`
|
||||||
(
|
(
|
||||||
`do_not_access_rowid_alias` INTEGER PRIMARY KEY,
|
`do_not_access_rowid_alias` INTEGER PRIMARY KEY,
|
||||||
`type` INT NOT NULL,
|
`type` INT NOT NULL,
|
||||||
`id` INT GENERATED ALWAYS AS (`do_not_access_rowid_alias` | (`type` << 56)) VIRTUAL,
|
`id` INT GENERATED ALWAYS AS (`do_not_access_rowid_alias` | (`type` << 56)) VIRTUAL UNIQUE
|
||||||
`name` TEXT NOT NULL,
|
|
||||||
`information` TEXT NOT NULL
|
|
||||||
) STRICT;
|
) STRICT;
|
||||||
|
|
||||||
CREATE UNIQUE INDEX `object_id` ON `objects` (`id`);
|
CREATE UNIQUE INDEX `object_id` ON `objects` (`id`);
|
||||||
CREATE INDEX `object_type` ON `objects` (`type`);
|
CREATE INDEX `object_type` ON `objects` (`type`);
|
||||||
|
|
||||||
CREATE VIRTUAL TABLE `objects_fts` USING fts5
|
|
||||||
(
|
|
||||||
`name`,
|
|
||||||
`information`,
|
|
||||||
content='objects',
|
|
||||||
content_rowid='id',
|
|
||||||
tokenize="unicode61 remove_diacritics 2 tokenchars '-_'"
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE `entities`
|
CREATE TABLE `entities`
|
||||||
(
|
(
|
||||||
`id` INT,
|
`id` INT,
|
||||||
|
`name` TEXT NOT NULL,
|
||||||
|
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
|
UNIQUE (`name`),
|
||||||
FOREIGN KEY (`id`) REFERENCES `objects` (`id`) ON DELETE CASCADE
|
FOREIGN KEY (`id`) REFERENCES `objects` (`id`) ON DELETE CASCADE
|
||||||
) WITHOUT ROWID, STRICT;
|
) WITHOUT ROWID, STRICT;
|
||||||
|
|
||||||
CREATE TABLE `blueprints`
|
CREATE TABLE `blueprints`
|
||||||
(
|
(
|
||||||
`id` INT,
|
`id` INT,
|
||||||
|
`name` TEXT NOT NULL,
|
||||||
|
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
|
UNIQUE (`name`),
|
||||||
FOREIGN KEY (`id`) REFERENCES `objects` (`id`) ON DELETE CASCADE
|
FOREIGN KEY (`id`) REFERENCES `objects` (`id`) ON DELETE CASCADE
|
||||||
) WITHOUT ROWID, STRICT;
|
) WITHOUT ROWID, STRICT;
|
||||||
|
|
||||||
|
|
@ -40,23 +33,22 @@ CREATE TABLE `entity_blueprint_links`
|
||||||
`entity` INT NOT NULL,
|
`entity` INT NOT NULL,
|
||||||
`blueprint` INT NOT NULL,
|
`blueprint` INT NOT NULL,
|
||||||
|
|
||||||
PRIMARY KEY (`entity`),
|
PRIMARY KEY (`entity`, `blueprint`),
|
||||||
UNIQUE (`entity`, `blueprint`),
|
|
||||||
FOREIGN KEY (`entity`) REFERENCES `entities` (`id`) ON DELETE CASCADE,
|
FOREIGN KEY (`entity`) REFERENCES `entities` (`id`) ON DELETE CASCADE,
|
||||||
FOREIGN KEY (`blueprint`) REFERENCES `blueprints` (`id`) ON DELETE CASCADE
|
FOREIGN KEY (`blueprint`) REFERENCES `blueprints` (`id`) ON DELETE CASCADE
|
||||||
) WITHOUT ROWID, STRICT;
|
) WITHOUT ROWID, STRICT;
|
||||||
|
|
||||||
CREATE INDEX `entity_blueprints_blueprint` ON `entity_blueprint_links` (`blueprint`);
|
|
||||||
|
|
||||||
CREATE TABLE `properties`
|
CREATE TABLE `properties`
|
||||||
(
|
(
|
||||||
`id` INT,
|
`id` INT,
|
||||||
|
`name` TEXT NOT NULL,
|
||||||
`type` INT NOT NULL,
|
`type` INT NOT NULL,
|
||||||
`default_value` TEXT NOT NULL,
|
`default_value` TEXT NOT NULL,
|
||||||
`settings` TEXT NOT NULL,
|
`settings` TEXT NOT NULL,
|
||||||
`source` INT NOT NULL,
|
`source` INT NOT NULL,
|
||||||
|
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
|
UNIQUE(`source`, `name`),
|
||||||
FOREIGN KEY (`id`) REFERENCES `objects` (`id`) ON DELETE CASCADE,
|
FOREIGN KEY (`id`) REFERENCES `objects` (`id`) ON DELETE CASCADE,
|
||||||
FOREIGN KEY (`source`) REFERENCES `objects` (`id`) ON DELETE CASCADE
|
FOREIGN KEY (`source`) REFERENCES `objects` (`id`) ON DELETE CASCADE
|
||||||
) WITHOUT ROWID, STRICT;
|
) WITHOUT ROWID, STRICT;
|
||||||
|
|
@ -64,24 +56,6 @@ CREATE TABLE `properties`
|
||||||
CREATE INDEX `properties_type` ON `properties` (`type`);
|
CREATE INDEX `properties_type` ON `properties` (`type`);
|
||||||
CREATE INDEX `properties_source` ON `properties` (`source`);
|
CREATE INDEX `properties_source` ON `properties` (`source`);
|
||||||
|
|
||||||
CREATE
|
|
||||||
VIRTUAL TABLE `property_default_value_fts` USING fts5
|
|
||||||
(
|
|
||||||
`default_value`,
|
|
||||||
content='properties',
|
|
||||||
content_rowid='object_id',
|
|
||||||
tokenize="unicode61 remove_diacritics 2 tokenchars '-_'"
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE
|
|
||||||
VIRTUAL TABLE `property_settings_fts` USING fts5
|
|
||||||
(
|
|
||||||
`settings`,
|
|
||||||
content='properties',
|
|
||||||
content_rowid='object_id',
|
|
||||||
tokenize="unicode61 remove_diacritics 2 tokenchars '-_'"
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE `values`
|
CREATE TABLE `values`
|
||||||
(
|
(
|
||||||
`entity` INT NOT NULL,
|
`entity` INT NOT NULL,
|
||||||
|
|
@ -92,11 +66,3 @@ CREATE TABLE `values`
|
||||||
FOREIGN KEY (`entity`) REFERENCES `entities` (`id`) ON DELETE CASCADE,
|
FOREIGN KEY (`entity`) REFERENCES `entities` (`id`) ON DELETE CASCADE,
|
||||||
FOREIGN KEY (`property`) REFERENCES `properties` (`id`) ON DELETE CASCADE
|
FOREIGN KEY (`property`) REFERENCES `properties` (`id`) ON DELETE CASCADE
|
||||||
) WITHOUT ROWID, STRICT;
|
) WITHOUT ROWID, STRICT;
|
||||||
|
|
||||||
CREATE
|
|
||||||
VIRTUAL TABLE `values_fts` USING fts5
|
|
||||||
(
|
|
||||||
`value`,
|
|
||||||
content='values',
|
|
||||||
tokenize="unicode61 remove_diacritics 2 tokenchars '-_'"
|
|
||||||
);
|
|
||||||
|
|
@ -4,14 +4,14 @@
|
||||||
|
|
||||||
#include <cppbase/strings.hpp>
|
#include <cppbase/strings.hpp>
|
||||||
|
|
||||||
#include <objects/blueprint.hpp>
|
#include <ikarus/objects/blueprint.hpp>
|
||||||
#include <objects/entity.hpp>
|
#include <ikarus/objects/entity.hpp>
|
||||||
#include <objects/properties/number_property.hpp>
|
#include <ikarus/objects/properties/number_property.hpp>
|
||||||
#include <objects/properties/property.hpp>
|
#include <ikarus/objects/properties/property.hpp>
|
||||||
#include <objects/properties/text_property.hpp>
|
#include <ikarus/objects/properties/text_property.hpp>
|
||||||
#include <objects/properties/toggle_property.hpp>
|
#include <ikarus/objects/properties/toggle_property.hpp>
|
||||||
#include <persistence/migrations.hpp>
|
#include <ikarus/persistence/migrations.hpp>
|
||||||
#include <persistence/project.hpp>
|
#include <ikarus/persistence/project.hpp>
|
||||||
|
|
||||||
IkarusProject::IkarusProject(std::string_view name, std::string_view path, std::unique_ptr<sqlitecpp::Connection> && db):
|
IkarusProject::IkarusProject(std::string_view name, std::string_view path, std::unique_ptr<sqlitecpp::Connection> && db):
|
||||||
name{name},
|
name{name},
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#include "values/entity_property_value.hpp"
|
#include "entity_property_value.hpp"
|
||||||
|
|
||||||
#include <errors.hpp>
|
#include <ikarus/errors.hpp>
|
||||||
|
|
||||||
IkarusEntity const * ikarus_entity_property_value_get_entity(IkarusEntityPropertyValue const * value, IkarusErrorData * error_out) {
|
IkarusEntity const * ikarus_entity_property_value_get_entity(IkarusEntityPropertyValue const * value, IkarusErrorData * error_out) {
|
||||||
IKARUS_FAIL_IF_NULL(value, nullptr);
|
IKARUS_FAIL_IF_NULL(value, nullptr);
|
||||||
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
#include <boost/functional/overloaded_function.hpp>
|
#include <boost/functional/overloaded_function.hpp>
|
||||||
|
|
||||||
#include <values/number_value.hpp>
|
#include <ikarus/values/number_value.hpp>
|
||||||
#include <values/value_base.hpp>
|
#include <ikarus/values/value_base.hpp>
|
||||||
|
|
||||||
IkarusNumberValue::IkarusNumberValue():
|
IkarusNumberValue::IkarusNumberValue():
|
||||||
IkarusValue{this} {}
|
IkarusValue{this} {}
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
#include <boost/container/small_vector.hpp>
|
#include <boost/container/small_vector.hpp>
|
||||||
#include <boost/variant2.hpp>
|
#include <boost/variant2.hpp>
|
||||||
|
|
||||||
#include <values/value.hpp>
|
#include <ikarus/values/value.hpp>
|
||||||
|
|
||||||
struct IkarusNumberValue : IkarusValue {
|
struct IkarusNumberValue : IkarusValue {
|
||||||
public:
|
public:
|
||||||
|
|
@ -3,8 +3,8 @@
|
||||||
#include <boost/bind/bind.hpp>
|
#include <boost/bind/bind.hpp>
|
||||||
#include <boost/functional/overloaded_function.hpp>
|
#include <boost/functional/overloaded_function.hpp>
|
||||||
|
|
||||||
#include <values/text_value.hpp>
|
#include <ikarus/values/text_value.hpp>
|
||||||
#include <values/value_base.hpp>
|
#include <ikarus/values/value_base.hpp>
|
||||||
|
|
||||||
IkarusTextValue::IkarusTextValue():
|
IkarusTextValue::IkarusTextValue():
|
||||||
IkarusValue{this} {}
|
IkarusValue{this} {}
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#include <boost/container/small_vector.hpp>
|
#include <boost/container/small_vector.hpp>
|
||||||
|
|
||||||
#include <values/value.hpp>
|
#include <ikarus/values/value.hpp>
|
||||||
|
|
||||||
struct IkarusTextValue : IkarusValue {
|
struct IkarusTextValue : IkarusValue {
|
||||||
public:
|
public:
|
||||||
|
|
@ -3,8 +3,8 @@
|
||||||
#include <boost/functional/overloaded_function.hpp>
|
#include <boost/functional/overloaded_function.hpp>
|
||||||
#include <boost/range/adaptors.hpp>
|
#include <boost/range/adaptors.hpp>
|
||||||
|
|
||||||
#include <values/toggle_value.hpp>
|
#include <ikarus/values/toggle_value.hpp>
|
||||||
#include <values/value_base.hpp>
|
#include <ikarus/values/value_base.hpp>
|
||||||
|
|
||||||
IkarusToggleValue::IkarusToggleValue():
|
IkarusToggleValue::IkarusToggleValue():
|
||||||
IkarusValue{this} {}
|
IkarusValue{this} {}
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#include <boost/container/small_vector.hpp>
|
#include <boost/container/small_vector.hpp>
|
||||||
|
|
||||||
#include <values/value.hpp>
|
#include <ikarus/values/value.hpp>
|
||||||
|
|
||||||
struct IkarusToggleValue : IkarusValue {
|
struct IkarusToggleValue : IkarusValue {
|
||||||
public:
|
public:
|
||||||
|
|
@ -10,11 +10,10 @@
|
||||||
#include <boost/json/src.hpp>
|
#include <boost/json/src.hpp>
|
||||||
|
|
||||||
#include <ikarus/objects/properties/property_type.h>
|
#include <ikarus/objects/properties/property_type.h>
|
||||||
|
#include <ikarus/values/number_value.hpp>
|
||||||
#include <values/number_value.hpp>
|
#include <ikarus/values/text_value.hpp>
|
||||||
#include <values/text_value.hpp>
|
#include <ikarus/values/toggle_value.hpp>
|
||||||
#include <values/toggle_value.hpp>
|
#include <ikarus/values/value.hpp>
|
||||||
#include <values/value.hpp>
|
|
||||||
|
|
||||||
IkarusValue::IkarusValue(Data data):
|
IkarusValue::IkarusValue(Data data):
|
||||||
data(data) {}
|
data(data) {}
|
||||||
|
|
@ -5,8 +5,8 @@
|
||||||
|
|
||||||
#include <cppbase/result.hpp>
|
#include <cppbase/result.hpp>
|
||||||
|
|
||||||
#include <errors.hpp>
|
#include <ikarus/errors.hpp>
|
||||||
#include <persistence/project.hpp>
|
#include <ikarus/persistence/project.hpp>
|
||||||
|
|
||||||
struct IkarusValue {
|
struct IkarusValue {
|
||||||
public:
|
public:
|
||||||
|
|
@ -1,170 +0,0 @@
|
||||||
#include "object.hpp"
|
|
||||||
|
|
||||||
#include <fmt/format.h>
|
|
||||||
|
|
||||||
#include <cppbase/strings.hpp>
|
|
||||||
|
|
||||||
#include <ikarus/errors.h>
|
|
||||||
#include <ikarus/objects/object.h>
|
|
||||||
|
|
||||||
#include <errors.hpp>
|
|
||||||
#include <objects/blueprint.hpp>
|
|
||||||
#include <objects/entity.hpp>
|
|
||||||
#include <objects/properties/property.hpp>
|
|
||||||
#include <persistence/project.hpp>
|
|
||||||
|
|
||||||
IkarusObject::IkarusObject(IkarusProject * project, IkarusId id):
|
|
||||||
project{project},
|
|
||||||
id{id} {}
|
|
||||||
|
|
||||||
IkarusProject * ikarus_object_get_project(IkarusObject const * object, IkarusErrorData * error_out) {
|
|
||||||
IKARUS_FAIL_IF_NULL(object, nullptr);
|
|
||||||
IKARUS_FAIL_IF_OBJECT_MISSING(object, nullptr);
|
|
||||||
|
|
||||||
return object->project;
|
|
||||||
}
|
|
||||||
|
|
||||||
char const * ikarus_object_get_name(IkarusObject const * object, IkarusErrorData * error_out) {
|
|
||||||
IKARUS_FAIL_IF_NULL(object, nullptr);
|
|
||||||
IKARUS_FAIL_IF_OBJECT_MISSING(object, nullptr);
|
|
||||||
|
|
||||||
IKARUS_VTRYRV_OR_FAIL(
|
|
||||||
std::string ret,
|
|
||||||
nullptr,
|
|
||||||
"unable to get object name: {}",
|
|
||||||
IkarusErrorInfo_Database_QueryFailed,
|
|
||||||
object->project->db->template query_one<std::string>("SELECT `name` FROM `objects` WHERE `id` = ?", object->id)
|
|
||||||
);
|
|
||||||
|
|
||||||
return strdup(ret.data());
|
|
||||||
}
|
|
||||||
|
|
||||||
void ikarus_object_set_name(IkarusObject * object, char const * name, IkarusErrorData * error_out) {
|
|
||||||
IKARUS_FAIL_IF_NULL(object, );
|
|
||||||
IKARUS_FAIL_IF_OBJECT_MISSING(object, );
|
|
||||||
IKARUS_FAIL_IF_NULL(name, );
|
|
||||||
IKARUS_FAIL_IF(cppbase::is_empty_or_blank(name), , "name must not be empty", IkarusErrorInfo_Client_InvalidInput);
|
|
||||||
|
|
||||||
IKARUS_TRYRV_OR_FAIL(
|
|
||||||
,
|
|
||||||
"unable to set object name: {}",
|
|
||||||
IkarusErrorInfo_Database_QueryFailed,
|
|
||||||
object->project->db->template execute("UPDATE `objects` SET `name` = ? WHERE `id` = ?", name, object->id)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
char const * ikarus_object_get_information(IkarusObject const * object, IkarusErrorData * error_out) {
|
|
||||||
IKARUS_FAIL_IF_NULL(object, nullptr);
|
|
||||||
IKARUS_FAIL_IF_OBJECT_MISSING(object, nullptr);
|
|
||||||
|
|
||||||
IKARUS_VTRYRV_OR_FAIL(
|
|
||||||
std::string ret,
|
|
||||||
nullptr,
|
|
||||||
"unable to get object information: {}",
|
|
||||||
IkarusErrorInfo_Database_QueryFailed,
|
|
||||||
object->project->db->template query_one<std::string>("SELECT `information` FROM `objects` WHERE `id` = ?", object->id)
|
|
||||||
);
|
|
||||||
|
|
||||||
return strdup(ret.data());
|
|
||||||
}
|
|
||||||
|
|
||||||
void ikarus_object_set_information(IkarusObject * object, char const * information, IkarusErrorData * error_out) {
|
|
||||||
IKARUS_FAIL_IF_NULL(object, );
|
|
||||||
IKARUS_FAIL_IF_OBJECT_MISSING(object, );
|
|
||||||
IKARUS_FAIL_IF_NULL(information, );
|
|
||||||
IKARUS_FAIL_IF(cppbase::is_empty_or_blank(information), , "information must not be empty", IkarusErrorInfo_Client_InvalidInput);
|
|
||||||
|
|
||||||
IKARUS_TRYRV_OR_FAIL(
|
|
||||||
,
|
|
||||||
"unable to set object information: {}",
|
|
||||||
IkarusErrorInfo_Database_QueryFailed,
|
|
||||||
object->project->db->template execute("UPDATE `objects` SET `information` = ? WHERE `id` = ?", information, object->id)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ikarus_object_is_equal(IkarusObject const * lhs, IkarusObject const * rhs, IkarusErrorData * error_out) {
|
|
||||||
IKARUS_FAIL_IF_NULL(lhs, false);
|
|
||||||
IKARUS_FAIL_IF_OBJECT_MISSING(lhs, false);
|
|
||||||
IKARUS_FAIL_IF_NULL(rhs, false);
|
|
||||||
IKARUS_FAIL_IF_OBJECT_MISSING(rhs, false);
|
|
||||||
|
|
||||||
return lhs->id == rhs->id;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ikarus_object_visit(
|
|
||||||
IkarusObject * object,
|
|
||||||
void (*blueprint_visitor)(struct IkarusBlueprint *, void *),
|
|
||||||
void (*property_visitor)(struct IkarusProperty *, void *),
|
|
||||||
void (*entity_visitor)(struct IkarusEntity *, void *),
|
|
||||||
void * data,
|
|
||||||
IkarusErrorData * error_out
|
|
||||||
) {
|
|
||||||
struct Data {
|
|
||||||
void (*blueprint_visitor)(struct IkarusBlueprint *, void *);
|
|
||||||
void (*property_visitor)(struct IkarusProperty *, void *);
|
|
||||||
void (*entity_visitor)(struct IkarusEntity *, void *);
|
|
||||||
void * data;
|
|
||||||
};
|
|
||||||
|
|
||||||
Data passthru_data{
|
|
||||||
blueprint_visitor,
|
|
||||||
property_visitor,
|
|
||||||
entity_visitor,
|
|
||||||
data,
|
|
||||||
};
|
|
||||||
|
|
||||||
ikarus_object_visit_const(
|
|
||||||
object,
|
|
||||||
[](IkarusBlueprint const * blueprint, void * data) {
|
|
||||||
auto const * passthru_data = static_cast<Data *>(data);
|
|
||||||
passthru_data->blueprint_visitor(const_cast<IkarusBlueprint *>(blueprint), passthru_data->data);
|
|
||||||
},
|
|
||||||
[](IkarusProperty const * property, void * data) {
|
|
||||||
auto const * passthru_data = static_cast<Data *>(data);
|
|
||||||
passthru_data->property_visitor(const_cast<IkarusProperty *>(property), passthru_data->data);
|
|
||||||
},
|
|
||||||
[](IkarusEntity const * entity, void * data) {
|
|
||||||
auto const * passthru_data = static_cast<Data *>(data);
|
|
||||||
passthru_data->entity_visitor(const_cast<IkarusEntity *>(entity), passthru_data->data);
|
|
||||||
},
|
|
||||||
&passthru_data,
|
|
||||||
error_out
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ikarus_object_visit_const(
|
|
||||||
IkarusObject const * object,
|
|
||||||
void (*blueprint_visitor)(struct IkarusBlueprint const *, void *),
|
|
||||||
void (*property_visitor)(struct IkarusProperty const *, void *),
|
|
||||||
void (*entity_visitor)(struct IkarusEntity const *, void *),
|
|
||||||
void * data,
|
|
||||||
IkarusErrorData * error_out
|
|
||||||
) {
|
|
||||||
IKARUS_FAIL_IF_NULL(object, );
|
|
||||||
IKARUS_FAIL_IF_OBJECT_MISSING(object, );
|
|
||||||
|
|
||||||
switch (ikarus_id_get_object_type(object->id)) {
|
|
||||||
case IkarusObjectType_Entity: {
|
|
||||||
auto const * entity = dynamic_cast<IkarusEntity const *>(object);
|
|
||||||
IKARUS_FAIL_IF(entity == nullptr, , "object with entity id wasn't a entity", IkarusErrorInfo_LibIkarus_InvalidState);
|
|
||||||
entity_visitor(entity, data);
|
|
||||||
}
|
|
||||||
case IkarusObjectType_Blueprint: {
|
|
||||||
auto const * blueprint = dynamic_cast<IkarusBlueprint const *>(object);
|
|
||||||
IKARUS_FAIL_IF(blueprint == nullptr, , "object with blueprint id wasn't a blueprint", IkarusErrorInfo_LibIkarus_InvalidState);
|
|
||||||
blueprint_visitor(blueprint, data);
|
|
||||||
}
|
|
||||||
case IkarusObjectType_Property: {
|
|
||||||
auto const * property = dynamic_cast<IkarusProperty const *>(object);
|
|
||||||
IKARUS_FAIL_IF(property == nullptr, , "object with property id wasn't a property", IkarusErrorInfo_LibIkarus_InvalidState);
|
|
||||||
property_visitor(property, data);
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
IKARUS_FAIL(
|
|
||||||
,
|
|
||||||
fmt::format("unknown object type: {}", ikarus_object_type_to_string(ikarus_id_get_object_type(object->id))),
|
|
||||||
IkarusErrorInfo_LibIkarus_InvalidState
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,27 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <boost/variant2.hpp>
|
|
||||||
#include <ikarus/id.h>
|
|
||||||
#include <ikarus/objects/properties/property_source.h>
|
|
||||||
|
|
||||||
struct IkarusPropertySource {
|
|
||||||
public:
|
|
||||||
using Data = boost::variant2::variant<IkarusBlueprint *, IkarusEntity *>;
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit IkarusPropertySource(Data data);
|
|
||||||
|
|
||||||
IkarusPropertySource(IkarusPropertySource const &) = default;
|
|
||||||
IkarusPropertySource(IkarusPropertySource &&) = default;
|
|
||||||
|
|
||||||
IkarusPropertySource & operator=(IkarusPropertySource const &) = default;
|
|
||||||
IkarusPropertySource & operator=(IkarusPropertySource &&) = default;
|
|
||||||
|
|
||||||
virtual ~IkarusPropertySource() = default;
|
|
||||||
|
|
||||||
public:
|
|
||||||
[[nodiscard]] IkarusId get_id() const;
|
|
||||||
|
|
||||||
public:
|
|
||||||
Data data;
|
|
||||||
};
|
|
||||||
2
vendor/sqlitecpp
vendored
2
vendor/sqlitecpp
vendored
|
|
@ -1 +1 @@
|
||||||
Subproject commit 77e726036b52fff6f82ff2d44081f05aee7408a8
|
Subproject commit eadf3237bfa853763b332777e9dc0f16df8cca71
|
||||||
Loading…
Add table
Add a link
Reference in a new issue