add flatbuffers support and initial rewrite
Signed-off-by: Folling <mail@folling.io>
This commit is contained in:
parent
5f7a62ecb7
commit
4d7bf09c4e
72 changed files with 3929 additions and 1403 deletions
|
|
@ -64,9 +64,9 @@ BreakBeforeInlineASMColon: OnlyMultiline
|
||||||
BreakBeforeTernaryOperators: false
|
BreakBeforeTernaryOperators: false
|
||||||
BreakConstructorInitializers: AfterColon
|
BreakConstructorInitializers: AfterColon
|
||||||
BreakInheritanceList: AfterColon
|
BreakInheritanceList: AfterColon
|
||||||
BreakStringLiterals: false
|
BreakStringLiterals: true
|
||||||
|
|
||||||
ColumnLimit: 140
|
ColumnLimit: 80
|
||||||
CommentPragmas: '^\\.+'
|
CommentPragmas: '^\\.+'
|
||||||
CompactNamespaces: false
|
CompactNamespaces: false
|
||||||
ConstructorInitializerIndentWidth: 4
|
ConstructorInitializerIndentWidth: 4
|
||||||
|
|
@ -117,7 +117,7 @@ IndentCaseBlocks: false
|
||||||
IndentCaseLabels: false
|
IndentCaseLabels: false
|
||||||
IndentExternBlock: NoIndent
|
IndentExternBlock: NoIndent
|
||||||
IndentGotoLabels: false
|
IndentGotoLabels: false
|
||||||
IndentPPDirectives: None
|
IndentPPDirectives: BeforeHash
|
||||||
IndentRequiresClause: true
|
IndentRequiresClause: true
|
||||||
IndentWidth: 4
|
IndentWidth: 4
|
||||||
IndentWrappedFunctionNames: false
|
IndentWrappedFunctionNames: false
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,11 @@ add_library(
|
||||||
${SOURCE_FILES}
|
${SOURCE_FILES}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
add_dependencies(
|
||||||
|
ikarus
|
||||||
|
flatbuffer_headers
|
||||||
|
)
|
||||||
|
|
||||||
set_target_properties(
|
set_target_properties(
|
||||||
ikarus PROPERTIES
|
ikarus PROPERTIES
|
||||||
CXX_STANDARD 23
|
CXX_STANDARD 23
|
||||||
|
|
@ -71,9 +76,4 @@ if (LIBIKARUS_BUILD_DOCS)
|
||||||
ikarus
|
ikarus
|
||||||
libikarus_docs
|
libikarus_docs
|
||||||
)
|
)
|
||||||
|
|
||||||
add_dependencies(
|
|
||||||
libikarus_tests
|
|
||||||
libikarus_docs
|
|
||||||
)
|
|
||||||
endif ()
|
endif ()
|
||||||
|
|
|
||||||
|
|
@ -6,3 +6,4 @@ file(
|
||||||
|
|
||||||
set(INCLUDE_FILES ${FILES} PARENT_SCOPE)
|
set(INCLUDE_FILES ${FILES} PARENT_SCOPE)
|
||||||
|
|
||||||
|
add_subdirectory(ikarus)
|
||||||
1
include/ikarus/CMakeLists.txt
Normal file
1
include/ikarus/CMakeLists.txt
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
add_subdirectory(models)
|
||||||
|
|
@ -4,11 +4,10 @@
|
||||||
/// \author Folling <folling@ikarus.world>
|
/// \author Folling <folling@ikarus.world>
|
||||||
|
|
||||||
#include <ikarus/macros.h>
|
#include <ikarus/macros.h>
|
||||||
#include <ikarus/stdtypes.h>
|
|
||||||
|
|
||||||
/// \addtogroup errors Errors
|
/// \addtogroup errors Errors
|
||||||
/// \brief Error handling within libikarus
|
/// \brief Error handling within libikarus
|
||||||
/// \details Functions in Ikarus may fail, in which case they have an out parameter for the error.
|
/// \details Functions in Ikarus may fail. To report the type of failure all functions have an out parameter for the error.
|
||||||
/// Upon erring the function will store relevant information about the error in the out parameter.
|
/// Upon erring the function will store relevant information about the error in the out parameter.
|
||||||
/// If the out parameter is null nothing will be stored. This is not recommended as it essentially ignores errors.
|
/// If the out parameter is null nothing will be stored. This is not recommended as it essentially ignores errors.
|
||||||
/// For the sake of simplicity we have avoided mechanisms that "force" clients to handle errors.
|
/// For the sake of simplicity we have avoided mechanisms that "force" clients to handle errors.
|
||||||
|
|
@ -93,7 +92,7 @@ enum IkarusErrorInfo {
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \brief The maximum length of an error message.
|
/// \brief The maximum length of an error message.
|
||||||
size_t const IKARUS_ERROR_DATA_MAX_MESSAGE_LIMIT = 128;
|
#define IKARUS_ERROR_DATA_MAX_MESSAGE_LIMIT 128
|
||||||
|
|
||||||
/// \brief The data stored for an error
|
/// \brief The data stored for an error
|
||||||
struct IkarusErrorData {
|
struct IkarusErrorData {
|
||||||
|
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
/// \file global.h
|
|
||||||
/// \author Folling <folling@ikarus.world>
|
|
||||||
|
|
||||||
#include <ikarus/macros.h>
|
|
||||||
|
|
||||||
/// \defgroup global Global
|
|
||||||
/// \brief Information relevant to the entire library.
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
IKARUS_BEGIN_HEADER
|
|
||||||
|
|
||||||
/// \brief Frees a pointer allocated by ikarus. Every pointer returned by a function must be freed using this function
|
|
||||||
/// unless explicitly stated otherwise.
|
|
||||||
IKA_API void ikarus_free(void * ptr);
|
|
||||||
|
|
||||||
IKARUS_END_HEADER
|
|
||||||
|
|
||||||
/// @}
|
|
||||||
|
|
@ -1,46 +0,0 @@
|
||||||
// IMPLEMENTATION_DETAIL_DATABASE
|
|
||||||
|
|
||||||
/// \file id.h
|
|
||||||
/// \author Folling <folling@ikarus.world>
|
|
||||||
|
|
||||||
/// \privatesection
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <ikarus/macros.h>
|
|
||||||
#include <ikarus/objects/object_type.h>
|
|
||||||
#include <ikarus/stdtypes.h>
|
|
||||||
|
|
||||||
/// \defgroup id Ids
|
|
||||||
/// \brief Ids are used to identify objects in the database.
|
|
||||||
/// \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.
|
|
||||||
/// To avoid ordering fiascos and potential index performance degradation we just skip the first bit.
|
|
||||||
/// - next 7 bits: #IkarusObjectType
|
|
||||||
/// - 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.
|
|
||||||
/// \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.
|
|
||||||
/// To avoid ordering fiascos and potential index performance degradation we just skip the first bit.
|
|
||||||
/// - next 7 bits: #IkarusObjectType
|
|
||||||
/// - last 56 bits: incremented counter generated by the database
|
|
||||||
typedef int64_t IkarusId;
|
|
||||||
|
|
||||||
/// \brief Creates an id from the given data and type.
|
|
||||||
/// \param data The data to use for the id.
|
|
||||||
/// \param type The type to use for the id.
|
|
||||||
/// \return The created id.
|
|
||||||
IKA_API IkarusId ikarus_id_from_data_and_type(int64_t data, IkarusObjectType type);
|
|
||||||
|
|
||||||
/// \brief Fetches the object type of the given id.
|
|
||||||
/// \param id The id to fetch the object type for.
|
|
||||||
/// \return The object type of the given id.
|
|
||||||
IKA_API IkarusObjectType ikarus_id_get_object_type(IkarusId id);
|
|
||||||
|
|
||||||
IKARUS_END_HEADER
|
|
||||||
|
|
||||||
/// @}
|
|
||||||
|
|
@ -1,23 +1,19 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#if defined(__unix__)
|
#define IKA_API
|
||||||
|
|
||||||
|
#if defined(__unix__)
|
||||||
#define IKA_OS_FAMILY_UNIX
|
#define IKA_OS_FAMILY_UNIX
|
||||||
#define IKA_API __attribute__((visibility("default")))
|
#define IKA_API __attribute__((visibility("default")))
|
||||||
|
|
||||||
#if defined(linux)
|
#if defined(linux)
|
||||||
#define IKA_OS_LINUX
|
#define IKA_OS_LINUX
|
||||||
#endif
|
#endif
|
||||||
|
#elif defined(_WIN32)
|
||||||
#elif defined(_WIN32) || defined(WIN32)
|
|
||||||
#define IKA_OS_WIN
|
#define IKA_OS_WIN
|
||||||
#define IKA_API __declspec(dllexport)
|
#define IKA_API __declspec(dllexport)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef IKA_API
|
|
||||||
#define IKA_API
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#define IKARUS_BEGIN_HEADER extern "C" {
|
#define IKARUS_BEGIN_HEADER extern "C" {
|
||||||
#define IKARUS_END_HEADER }
|
#define IKARUS_END_HEADER }
|
||||||
|
|
|
||||||
41
include/ikarus/models/CMakeLists.txt
Normal file
41
include/ikarus/models/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
file(
|
||||||
|
GLOB_RECURSE
|
||||||
|
FLATBUFFER_SOURCES
|
||||||
|
"*.fbs"
|
||||||
|
)
|
||||||
|
|
||||||
|
foreach (FLATBUFFER_SOURCE IN LISTS ${FLATBUFFER_SOURCES})
|
||||||
|
cmake_path(
|
||||||
|
GET
|
||||||
|
${FLATBUFFER_SOURCE}
|
||||||
|
FILENAME
|
||||||
|
FLATBUFFER_SOURCE_NAME
|
||||||
|
)
|
||||||
|
|
||||||
|
string(
|
||||||
|
CONCAT
|
||||||
|
FLATBUFFER_GENERATED_SOURCE_NAME
|
||||||
|
${FLATBUFFER_SOURCE_NAME}
|
||||||
|
"_generated"
|
||||||
|
)
|
||||||
|
|
||||||
|
cmake_path(
|
||||||
|
REPLACE_EXTENSION
|
||||||
|
${FLATBUFFER_GENERATED_SOURCE_NAME}
|
||||||
|
".h"
|
||||||
|
OUTPUT_VARIABLE
|
||||||
|
FLATBUFFER_GENERATED_HEADER
|
||||||
|
)
|
||||||
|
|
||||||
|
list(APPEND FLATBUFFER_GENERATED_HEADERS ${FLATBUFFER_GENERATED_HEADER})
|
||||||
|
endforeach ()
|
||||||
|
|
||||||
|
add_custom_target(
|
||||||
|
flatbuffer_headers
|
||||||
|
COMMENT "Generating flatbuffer headers"
|
||||||
|
DEPENDS ${FLATBUFFER_SOURCES}
|
||||||
|
BYPRODUCTS ${FLATBUFFER_GENERATED_HEADERS}
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
COMMAND flatc --cpp --cpp-std "c++17" ${FLATBUFFER_SOURCES}
|
||||||
|
VERBATIM
|
||||||
|
)
|
||||||
12
include/ikarus/models/blueprint.fbs
Normal file
12
include/ikarus/models/blueprint.fbs
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
include "property.fbs";
|
||||||
|
|
||||||
|
namespace Ikarus;
|
||||||
|
|
||||||
|
table Blueprint {
|
||||||
|
id: int64;
|
||||||
|
name: string;
|
||||||
|
description: string;
|
||||||
|
tags: [string];
|
||||||
|
}
|
||||||
|
|
||||||
|
root_type Blueprint;
|
||||||
153
include/ikarus/models/blueprint_generated.h
Normal file
153
include/ikarus/models/blueprint_generated.h
Normal file
|
|
@ -0,0 +1,153 @@
|
||||||
|
// automatically generated by the FlatBuffers compiler, do not modify
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef FLATBUFFERS_GENERATED_BLUEPRINT_IKARUS_H_
|
||||||
|
#define FLATBUFFERS_GENERATED_BLUEPRINT_IKARUS_H_
|
||||||
|
|
||||||
|
#include "flatbuffers/flatbuffers.h"
|
||||||
|
|
||||||
|
// Ensure the included flatbuffers.h is the same version as when this file was
|
||||||
|
// generated, otherwise it may not be compatible.
|
||||||
|
static_assert(FLATBUFFERS_VERSION_MAJOR == 24 &&
|
||||||
|
FLATBUFFERS_VERSION_MINOR == 3 &&
|
||||||
|
FLATBUFFERS_VERSION_REVISION == 25,
|
||||||
|
"Non-compatible flatbuffers version included");
|
||||||
|
|
||||||
|
#include "property_generated.h"
|
||||||
|
|
||||||
|
namespace Ikarus {
|
||||||
|
|
||||||
|
struct Blueprint;
|
||||||
|
struct BlueprintBuilder;
|
||||||
|
|
||||||
|
struct Blueprint FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||||
|
typedef BlueprintBuilder Builder;
|
||||||
|
struct Traits;
|
||||||
|
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||||
|
VT_ID = 4,
|
||||||
|
VT_NAME = 6,
|
||||||
|
VT_DESCRIPTION = 8,
|
||||||
|
VT_TAGS = 10
|
||||||
|
};
|
||||||
|
int64_t id() const {
|
||||||
|
return GetField<int64_t>(VT_ID, 0);
|
||||||
|
}
|
||||||
|
const ::flatbuffers::String *name() const {
|
||||||
|
return GetPointer<const ::flatbuffers::String *>(VT_NAME);
|
||||||
|
}
|
||||||
|
const ::flatbuffers::String *description() const {
|
||||||
|
return GetPointer<const ::flatbuffers::String *>(VT_DESCRIPTION);
|
||||||
|
}
|
||||||
|
const ::flatbuffers::Vector<::flatbuffers::Offset<::flatbuffers::String>> *tags() const {
|
||||||
|
return GetPointer<const ::flatbuffers::Vector<::flatbuffers::Offset<::flatbuffers::String>> *>(VT_TAGS);
|
||||||
|
}
|
||||||
|
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||||
|
return VerifyTableStart(verifier) &&
|
||||||
|
VerifyField<int64_t>(verifier, VT_ID, 8) &&
|
||||||
|
VerifyOffset(verifier, VT_NAME) &&
|
||||||
|
verifier.VerifyString(name()) &&
|
||||||
|
VerifyOffset(verifier, VT_DESCRIPTION) &&
|
||||||
|
verifier.VerifyString(description()) &&
|
||||||
|
VerifyOffset(verifier, VT_TAGS) &&
|
||||||
|
verifier.VerifyVector(tags()) &&
|
||||||
|
verifier.VerifyVectorOfStrings(tags()) &&
|
||||||
|
verifier.EndTable();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct BlueprintBuilder {
|
||||||
|
typedef Blueprint Table;
|
||||||
|
::flatbuffers::FlatBufferBuilder &fbb_;
|
||||||
|
::flatbuffers::uoffset_t start_;
|
||||||
|
void add_id(int64_t id) {
|
||||||
|
fbb_.AddElement<int64_t>(Blueprint::VT_ID, id, 0);
|
||||||
|
}
|
||||||
|
void add_name(::flatbuffers::Offset<::flatbuffers::String> name) {
|
||||||
|
fbb_.AddOffset(Blueprint::VT_NAME, name);
|
||||||
|
}
|
||||||
|
void add_description(::flatbuffers::Offset<::flatbuffers::String> description) {
|
||||||
|
fbb_.AddOffset(Blueprint::VT_DESCRIPTION, description);
|
||||||
|
}
|
||||||
|
void add_tags(::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset<::flatbuffers::String>>> tags) {
|
||||||
|
fbb_.AddOffset(Blueprint::VT_TAGS, tags);
|
||||||
|
}
|
||||||
|
explicit BlueprintBuilder(::flatbuffers::FlatBufferBuilder &_fbb)
|
||||||
|
: fbb_(_fbb) {
|
||||||
|
start_ = fbb_.StartTable();
|
||||||
|
}
|
||||||
|
::flatbuffers::Offset<Blueprint> Finish() {
|
||||||
|
const auto end = fbb_.EndTable(start_);
|
||||||
|
auto o = ::flatbuffers::Offset<Blueprint>(end);
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
inline ::flatbuffers::Offset<Blueprint> CreateBlueprint(
|
||||||
|
::flatbuffers::FlatBufferBuilder &_fbb,
|
||||||
|
int64_t id = 0,
|
||||||
|
::flatbuffers::Offset<::flatbuffers::String> name = 0,
|
||||||
|
::flatbuffers::Offset<::flatbuffers::String> description = 0,
|
||||||
|
::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset<::flatbuffers::String>>> tags = 0) {
|
||||||
|
BlueprintBuilder builder_(_fbb);
|
||||||
|
builder_.add_id(id);
|
||||||
|
builder_.add_tags(tags);
|
||||||
|
builder_.add_description(description);
|
||||||
|
builder_.add_name(name);
|
||||||
|
return builder_.Finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Blueprint::Traits {
|
||||||
|
using type = Blueprint;
|
||||||
|
static auto constexpr Create = CreateBlueprint;
|
||||||
|
};
|
||||||
|
|
||||||
|
inline ::flatbuffers::Offset<Blueprint> CreateBlueprintDirect(
|
||||||
|
::flatbuffers::FlatBufferBuilder &_fbb,
|
||||||
|
int64_t id = 0,
|
||||||
|
const char *name = nullptr,
|
||||||
|
const char *description = nullptr,
|
||||||
|
const std::vector<::flatbuffers::Offset<::flatbuffers::String>> *tags = nullptr) {
|
||||||
|
auto name__ = name ? _fbb.CreateString(name) : 0;
|
||||||
|
auto description__ = description ? _fbb.CreateString(description) : 0;
|
||||||
|
auto tags__ = tags ? _fbb.CreateVector<::flatbuffers::Offset<::flatbuffers::String>>(*tags) : 0;
|
||||||
|
return Ikarus::CreateBlueprint(
|
||||||
|
_fbb,
|
||||||
|
id,
|
||||||
|
name__,
|
||||||
|
description__,
|
||||||
|
tags__);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const Ikarus::Blueprint *GetBlueprint(const void *buf) {
|
||||||
|
return ::flatbuffers::GetRoot<Ikarus::Blueprint>(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const Ikarus::Blueprint *GetSizePrefixedBlueprint(const void *buf) {
|
||||||
|
return ::flatbuffers::GetSizePrefixedRoot<Ikarus::Blueprint>(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool VerifyBlueprintBuffer(
|
||||||
|
::flatbuffers::Verifier &verifier) {
|
||||||
|
return verifier.VerifyBuffer<Ikarus::Blueprint>(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool VerifySizePrefixedBlueprintBuffer(
|
||||||
|
::flatbuffers::Verifier &verifier) {
|
||||||
|
return verifier.VerifySizePrefixedBuffer<Ikarus::Blueprint>(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void FinishBlueprintBuffer(
|
||||||
|
::flatbuffers::FlatBufferBuilder &fbb,
|
||||||
|
::flatbuffers::Offset<Ikarus::Blueprint> root) {
|
||||||
|
fbb.Finish(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void FinishSizePrefixedBlueprintBuffer(
|
||||||
|
::flatbuffers::FlatBufferBuilder &fbb,
|
||||||
|
::flatbuffers::Offset<Ikarus::Blueprint> root) {
|
||||||
|
fbb.FinishSizePrefixed(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Ikarus
|
||||||
|
|
||||||
|
#endif // FLATBUFFERS_GENERATED_BLUEPRINT_IKARUS_H_
|
||||||
26
include/ikarus/models/entity.fbs
Normal file
26
include/ikarus/models/entity.fbs
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
include "value.fbs";
|
||||||
|
include "property.fbs";
|
||||||
|
include "blueprint.fbs";
|
||||||
|
|
||||||
|
namespace Ikarus;
|
||||||
|
|
||||||
|
table NamedValue {
|
||||||
|
name: string (key);
|
||||||
|
value: Ikarus.Value.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
table PropertyValue {
|
||||||
|
property_id: int64 (key);
|
||||||
|
data: Ikarus.Value.Data;
|
||||||
|
}
|
||||||
|
|
||||||
|
table Entity {
|
||||||
|
id: int64;
|
||||||
|
name: string;
|
||||||
|
description: string;
|
||||||
|
tags: [string];
|
||||||
|
values: [NamedValue];
|
||||||
|
property_values: [PropertyValue];
|
||||||
|
}
|
||||||
|
|
||||||
|
root_type Entity;
|
||||||
398
include/ikarus/models/entity_generated.h
Normal file
398
include/ikarus/models/entity_generated.h
Normal file
|
|
@ -0,0 +1,398 @@
|
||||||
|
// automatically generated by the FlatBuffers compiler, do not modify
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef FLATBUFFERS_GENERATED_ENTITY_IKARUS_H_
|
||||||
|
#define FLATBUFFERS_GENERATED_ENTITY_IKARUS_H_
|
||||||
|
|
||||||
|
#include "flatbuffers/flatbuffers.h"
|
||||||
|
|
||||||
|
// Ensure the included flatbuffers.h is the same version as when this file was
|
||||||
|
// generated, otherwise it may not be compatible.
|
||||||
|
static_assert(FLATBUFFERS_VERSION_MAJOR == 24 &&
|
||||||
|
FLATBUFFERS_VERSION_MINOR == 3 &&
|
||||||
|
FLATBUFFERS_VERSION_REVISION == 25,
|
||||||
|
"Non-compatible flatbuffers version included");
|
||||||
|
|
||||||
|
#include "blueprint_generated.h"
|
||||||
|
#include "property_generated.h"
|
||||||
|
#include "value_generated.h"
|
||||||
|
|
||||||
|
namespace Ikarus {
|
||||||
|
|
||||||
|
struct NamedValue;
|
||||||
|
struct NamedValueBuilder;
|
||||||
|
|
||||||
|
struct PropertyValue;
|
||||||
|
struct PropertyValueBuilder;
|
||||||
|
|
||||||
|
struct Entity;
|
||||||
|
struct EntityBuilder;
|
||||||
|
|
||||||
|
struct NamedValue FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||||
|
typedef NamedValueBuilder Builder;
|
||||||
|
struct Traits;
|
||||||
|
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||||
|
VT_NAME = 4,
|
||||||
|
VT_VALUE = 6
|
||||||
|
};
|
||||||
|
const ::flatbuffers::String *name() const {
|
||||||
|
return GetPointer<const ::flatbuffers::String *>(VT_NAME);
|
||||||
|
}
|
||||||
|
bool KeyCompareLessThan(const NamedValue * const o) const {
|
||||||
|
return *name() < *o->name();
|
||||||
|
}
|
||||||
|
int KeyCompareWithValue(const char *_name) const {
|
||||||
|
return strcmp(name()->c_str(), _name);
|
||||||
|
}
|
||||||
|
template<typename StringType>
|
||||||
|
int KeyCompareWithValue(const StringType& _name) const {
|
||||||
|
if (name()->c_str() < _name) return -1;
|
||||||
|
if (_name < name()->c_str()) return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
const Ikarus::Value::Value *value() const {
|
||||||
|
return GetPointer<const Ikarus::Value::Value *>(VT_VALUE);
|
||||||
|
}
|
||||||
|
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||||
|
return VerifyTableStart(verifier) &&
|
||||||
|
VerifyOffsetRequired(verifier, VT_NAME) &&
|
||||||
|
verifier.VerifyString(name()) &&
|
||||||
|
VerifyOffset(verifier, VT_VALUE) &&
|
||||||
|
verifier.VerifyTable(value()) &&
|
||||||
|
verifier.EndTable();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct NamedValueBuilder {
|
||||||
|
typedef NamedValue Table;
|
||||||
|
::flatbuffers::FlatBufferBuilder &fbb_;
|
||||||
|
::flatbuffers::uoffset_t start_;
|
||||||
|
void add_name(::flatbuffers::Offset<::flatbuffers::String> name) {
|
||||||
|
fbb_.AddOffset(NamedValue::VT_NAME, name);
|
||||||
|
}
|
||||||
|
void add_value(::flatbuffers::Offset<Ikarus::Value::Value> value) {
|
||||||
|
fbb_.AddOffset(NamedValue::VT_VALUE, value);
|
||||||
|
}
|
||||||
|
explicit NamedValueBuilder(::flatbuffers::FlatBufferBuilder &_fbb)
|
||||||
|
: fbb_(_fbb) {
|
||||||
|
start_ = fbb_.StartTable();
|
||||||
|
}
|
||||||
|
::flatbuffers::Offset<NamedValue> Finish() {
|
||||||
|
const auto end = fbb_.EndTable(start_);
|
||||||
|
auto o = ::flatbuffers::Offset<NamedValue>(end);
|
||||||
|
fbb_.Required(o, NamedValue::VT_NAME);
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
inline ::flatbuffers::Offset<NamedValue> CreateNamedValue(
|
||||||
|
::flatbuffers::FlatBufferBuilder &_fbb,
|
||||||
|
::flatbuffers::Offset<::flatbuffers::String> name = 0,
|
||||||
|
::flatbuffers::Offset<Ikarus::Value::Value> value = 0) {
|
||||||
|
NamedValueBuilder builder_(_fbb);
|
||||||
|
builder_.add_value(value);
|
||||||
|
builder_.add_name(name);
|
||||||
|
return builder_.Finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
struct NamedValue::Traits {
|
||||||
|
using type = NamedValue;
|
||||||
|
static auto constexpr Create = CreateNamedValue;
|
||||||
|
};
|
||||||
|
|
||||||
|
inline ::flatbuffers::Offset<NamedValue> CreateNamedValueDirect(
|
||||||
|
::flatbuffers::FlatBufferBuilder &_fbb,
|
||||||
|
const char *name = nullptr,
|
||||||
|
::flatbuffers::Offset<Ikarus::Value::Value> value = 0) {
|
||||||
|
auto name__ = name ? _fbb.CreateString(name) : 0;
|
||||||
|
return Ikarus::CreateNamedValue(
|
||||||
|
_fbb,
|
||||||
|
name__,
|
||||||
|
value);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct PropertyValue FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||||
|
typedef PropertyValueBuilder Builder;
|
||||||
|
struct Traits;
|
||||||
|
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||||
|
VT_PROPERTY_ID = 4,
|
||||||
|
VT_DATA_TYPE = 6,
|
||||||
|
VT_DATA = 8
|
||||||
|
};
|
||||||
|
int64_t property_id() const {
|
||||||
|
return GetField<int64_t>(VT_PROPERTY_ID, 0);
|
||||||
|
}
|
||||||
|
bool KeyCompareLessThan(const PropertyValue * const o) const {
|
||||||
|
return property_id() < o->property_id();
|
||||||
|
}
|
||||||
|
int KeyCompareWithValue(int64_t _property_id) const {
|
||||||
|
return static_cast<int>(property_id() > _property_id) - static_cast<int>(property_id() < _property_id);
|
||||||
|
}
|
||||||
|
Ikarus::Value::Data data_type() const {
|
||||||
|
return static_cast<Ikarus::Value::Data>(GetField<uint8_t>(VT_DATA_TYPE, 0));
|
||||||
|
}
|
||||||
|
const void *data() const {
|
||||||
|
return GetPointer<const void *>(VT_DATA);
|
||||||
|
}
|
||||||
|
template<typename T> const T *data_as() const;
|
||||||
|
const Ikarus::Value::ToggleDataPoint *data_as_ToggleDataPoint() const {
|
||||||
|
return data_type() == Ikarus::Value::Data::ToggleDataPoint ? static_cast<const Ikarus::Value::ToggleDataPoint *>(data()) : nullptr;
|
||||||
|
}
|
||||||
|
const Ikarus::Value::NumberDataPoint *data_as_NumberDataPoint() const {
|
||||||
|
return data_type() == Ikarus::Value::Data::NumberDataPoint ? static_cast<const Ikarus::Value::NumberDataPoint *>(data()) : nullptr;
|
||||||
|
}
|
||||||
|
const Ikarus::Value::TextDataPoint *data_as_TextDataPoint() const {
|
||||||
|
return data_type() == Ikarus::Value::Data::TextDataPoint ? static_cast<const Ikarus::Value::TextDataPoint *>(data()) : nullptr;
|
||||||
|
}
|
||||||
|
const Ikarus::Value::SimpleData *data_as_SimpleData() const {
|
||||||
|
return data_type() == Ikarus::Value::Data::SimpleData ? static_cast<const Ikarus::Value::SimpleData *>(data()) : nullptr;
|
||||||
|
}
|
||||||
|
const Ikarus::Value::CombinedData *data_as_CombinedData() const {
|
||||||
|
return data_type() == Ikarus::Value::Data::CombinedData ? static_cast<const Ikarus::Value::CombinedData *>(data()) : nullptr;
|
||||||
|
}
|
||||||
|
const Ikarus::Value::ListData *data_as_ListData() const {
|
||||||
|
return data_type() == Ikarus::Value::Data::ListData ? static_cast<const Ikarus::Value::ListData *>(data()) : nullptr;
|
||||||
|
}
|
||||||
|
const Ikarus::Value::ComplexData *data_as_ComplexData() const {
|
||||||
|
return data_type() == Ikarus::Value::Data::ComplexData ? static_cast<const Ikarus::Value::ComplexData *>(data()) : nullptr;
|
||||||
|
}
|
||||||
|
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||||
|
return VerifyTableStart(verifier) &&
|
||||||
|
VerifyField<int64_t>(verifier, VT_PROPERTY_ID, 8) &&
|
||||||
|
VerifyField<uint8_t>(verifier, VT_DATA_TYPE, 1) &&
|
||||||
|
VerifyOffset(verifier, VT_DATA) &&
|
||||||
|
VerifyData(verifier, data(), data_type()) &&
|
||||||
|
verifier.EndTable();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<> inline const Ikarus::Value::ToggleDataPoint *PropertyValue::data_as<Ikarus::Value::ToggleDataPoint>() const {
|
||||||
|
return data_as_ToggleDataPoint();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<> inline const Ikarus::Value::NumberDataPoint *PropertyValue::data_as<Ikarus::Value::NumberDataPoint>() const {
|
||||||
|
return data_as_NumberDataPoint();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<> inline const Ikarus::Value::TextDataPoint *PropertyValue::data_as<Ikarus::Value::TextDataPoint>() const {
|
||||||
|
return data_as_TextDataPoint();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<> inline const Ikarus::Value::SimpleData *PropertyValue::data_as<Ikarus::Value::SimpleData>() const {
|
||||||
|
return data_as_SimpleData();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<> inline const Ikarus::Value::CombinedData *PropertyValue::data_as<Ikarus::Value::CombinedData>() const {
|
||||||
|
return data_as_CombinedData();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<> inline const Ikarus::Value::ListData *PropertyValue::data_as<Ikarus::Value::ListData>() const {
|
||||||
|
return data_as_ListData();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<> inline const Ikarus::Value::ComplexData *PropertyValue::data_as<Ikarus::Value::ComplexData>() const {
|
||||||
|
return data_as_ComplexData();
|
||||||
|
}
|
||||||
|
|
||||||
|
struct PropertyValueBuilder {
|
||||||
|
typedef PropertyValue Table;
|
||||||
|
::flatbuffers::FlatBufferBuilder &fbb_;
|
||||||
|
::flatbuffers::uoffset_t start_;
|
||||||
|
void add_property_id(int64_t property_id) {
|
||||||
|
fbb_.AddElement<int64_t>(PropertyValue::VT_PROPERTY_ID, property_id, 0);
|
||||||
|
}
|
||||||
|
void add_data_type(Ikarus::Value::Data data_type) {
|
||||||
|
fbb_.AddElement<uint8_t>(PropertyValue::VT_DATA_TYPE, static_cast<uint8_t>(data_type), 0);
|
||||||
|
}
|
||||||
|
void add_data(::flatbuffers::Offset<void> data) {
|
||||||
|
fbb_.AddOffset(PropertyValue::VT_DATA, data);
|
||||||
|
}
|
||||||
|
explicit PropertyValueBuilder(::flatbuffers::FlatBufferBuilder &_fbb)
|
||||||
|
: fbb_(_fbb) {
|
||||||
|
start_ = fbb_.StartTable();
|
||||||
|
}
|
||||||
|
::flatbuffers::Offset<PropertyValue> Finish() {
|
||||||
|
const auto end = fbb_.EndTable(start_);
|
||||||
|
auto o = ::flatbuffers::Offset<PropertyValue>(end);
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
inline ::flatbuffers::Offset<PropertyValue> CreatePropertyValue(
|
||||||
|
::flatbuffers::FlatBufferBuilder &_fbb,
|
||||||
|
int64_t property_id = 0,
|
||||||
|
Ikarus::Value::Data data_type = Ikarus::Value::Data::NONE,
|
||||||
|
::flatbuffers::Offset<void> data = 0) {
|
||||||
|
PropertyValueBuilder builder_(_fbb);
|
||||||
|
builder_.add_property_id(property_id);
|
||||||
|
builder_.add_data(data);
|
||||||
|
builder_.add_data_type(data_type);
|
||||||
|
return builder_.Finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
struct PropertyValue::Traits {
|
||||||
|
using type = PropertyValue;
|
||||||
|
static auto constexpr Create = CreatePropertyValue;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Entity FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||||
|
typedef EntityBuilder Builder;
|
||||||
|
struct Traits;
|
||||||
|
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||||
|
VT_ID = 4,
|
||||||
|
VT_NAME = 6,
|
||||||
|
VT_DESCRIPTION = 8,
|
||||||
|
VT_TAGS = 10,
|
||||||
|
VT_VALUES = 12,
|
||||||
|
VT_PROPERTY_VALUES = 14
|
||||||
|
};
|
||||||
|
int64_t id() const {
|
||||||
|
return GetField<int64_t>(VT_ID, 0);
|
||||||
|
}
|
||||||
|
const ::flatbuffers::String *name() const {
|
||||||
|
return GetPointer<const ::flatbuffers::String *>(VT_NAME);
|
||||||
|
}
|
||||||
|
const ::flatbuffers::String *description() const {
|
||||||
|
return GetPointer<const ::flatbuffers::String *>(VT_DESCRIPTION);
|
||||||
|
}
|
||||||
|
const ::flatbuffers::Vector<::flatbuffers::Offset<::flatbuffers::String>> *tags() const {
|
||||||
|
return GetPointer<const ::flatbuffers::Vector<::flatbuffers::Offset<::flatbuffers::String>> *>(VT_TAGS);
|
||||||
|
}
|
||||||
|
const ::flatbuffers::Vector<::flatbuffers::Offset<Ikarus::NamedValue>> *values() const {
|
||||||
|
return GetPointer<const ::flatbuffers::Vector<::flatbuffers::Offset<Ikarus::NamedValue>> *>(VT_VALUES);
|
||||||
|
}
|
||||||
|
const ::flatbuffers::Vector<::flatbuffers::Offset<Ikarus::PropertyValue>> *property_values() const {
|
||||||
|
return GetPointer<const ::flatbuffers::Vector<::flatbuffers::Offset<Ikarus::PropertyValue>> *>(VT_PROPERTY_VALUES);
|
||||||
|
}
|
||||||
|
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||||
|
return VerifyTableStart(verifier) &&
|
||||||
|
VerifyField<int64_t>(verifier, VT_ID, 8) &&
|
||||||
|
VerifyOffset(verifier, VT_NAME) &&
|
||||||
|
verifier.VerifyString(name()) &&
|
||||||
|
VerifyOffset(verifier, VT_DESCRIPTION) &&
|
||||||
|
verifier.VerifyString(description()) &&
|
||||||
|
VerifyOffset(verifier, VT_TAGS) &&
|
||||||
|
verifier.VerifyVector(tags()) &&
|
||||||
|
verifier.VerifyVectorOfStrings(tags()) &&
|
||||||
|
VerifyOffset(verifier, VT_VALUES) &&
|
||||||
|
verifier.VerifyVector(values()) &&
|
||||||
|
verifier.VerifyVectorOfTables(values()) &&
|
||||||
|
VerifyOffset(verifier, VT_PROPERTY_VALUES) &&
|
||||||
|
verifier.VerifyVector(property_values()) &&
|
||||||
|
verifier.VerifyVectorOfTables(property_values()) &&
|
||||||
|
verifier.EndTable();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct EntityBuilder {
|
||||||
|
typedef Entity Table;
|
||||||
|
::flatbuffers::FlatBufferBuilder &fbb_;
|
||||||
|
::flatbuffers::uoffset_t start_;
|
||||||
|
void add_id(int64_t id) {
|
||||||
|
fbb_.AddElement<int64_t>(Entity::VT_ID, id, 0);
|
||||||
|
}
|
||||||
|
void add_name(::flatbuffers::Offset<::flatbuffers::String> name) {
|
||||||
|
fbb_.AddOffset(Entity::VT_NAME, name);
|
||||||
|
}
|
||||||
|
void add_description(::flatbuffers::Offset<::flatbuffers::String> description) {
|
||||||
|
fbb_.AddOffset(Entity::VT_DESCRIPTION, description);
|
||||||
|
}
|
||||||
|
void add_tags(::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset<::flatbuffers::String>>> tags) {
|
||||||
|
fbb_.AddOffset(Entity::VT_TAGS, tags);
|
||||||
|
}
|
||||||
|
void add_values(::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset<Ikarus::NamedValue>>> values) {
|
||||||
|
fbb_.AddOffset(Entity::VT_VALUES, values);
|
||||||
|
}
|
||||||
|
void add_property_values(::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset<Ikarus::PropertyValue>>> property_values) {
|
||||||
|
fbb_.AddOffset(Entity::VT_PROPERTY_VALUES, property_values);
|
||||||
|
}
|
||||||
|
explicit EntityBuilder(::flatbuffers::FlatBufferBuilder &_fbb)
|
||||||
|
: fbb_(_fbb) {
|
||||||
|
start_ = fbb_.StartTable();
|
||||||
|
}
|
||||||
|
::flatbuffers::Offset<Entity> Finish() {
|
||||||
|
const auto end = fbb_.EndTable(start_);
|
||||||
|
auto o = ::flatbuffers::Offset<Entity>(end);
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
inline ::flatbuffers::Offset<Entity> CreateEntity(
|
||||||
|
::flatbuffers::FlatBufferBuilder &_fbb,
|
||||||
|
int64_t id = 0,
|
||||||
|
::flatbuffers::Offset<::flatbuffers::String> name = 0,
|
||||||
|
::flatbuffers::Offset<::flatbuffers::String> description = 0,
|
||||||
|
::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset<::flatbuffers::String>>> tags = 0,
|
||||||
|
::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset<Ikarus::NamedValue>>> values = 0,
|
||||||
|
::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset<Ikarus::PropertyValue>>> property_values = 0) {
|
||||||
|
EntityBuilder builder_(_fbb);
|
||||||
|
builder_.add_id(id);
|
||||||
|
builder_.add_property_values(property_values);
|
||||||
|
builder_.add_values(values);
|
||||||
|
builder_.add_tags(tags);
|
||||||
|
builder_.add_description(description);
|
||||||
|
builder_.add_name(name);
|
||||||
|
return builder_.Finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Entity::Traits {
|
||||||
|
using type = Entity;
|
||||||
|
static auto constexpr Create = CreateEntity;
|
||||||
|
};
|
||||||
|
|
||||||
|
inline ::flatbuffers::Offset<Entity> CreateEntityDirect(
|
||||||
|
::flatbuffers::FlatBufferBuilder &_fbb,
|
||||||
|
int64_t id = 0,
|
||||||
|
const char *name = nullptr,
|
||||||
|
const char *description = nullptr,
|
||||||
|
const std::vector<::flatbuffers::Offset<::flatbuffers::String>> *tags = nullptr,
|
||||||
|
std::vector<::flatbuffers::Offset<Ikarus::NamedValue>> *values = nullptr,
|
||||||
|
std::vector<::flatbuffers::Offset<Ikarus::PropertyValue>> *property_values = nullptr) {
|
||||||
|
auto name__ = name ? _fbb.CreateString(name) : 0;
|
||||||
|
auto description__ = description ? _fbb.CreateString(description) : 0;
|
||||||
|
auto tags__ = tags ? _fbb.CreateVector<::flatbuffers::Offset<::flatbuffers::String>>(*tags) : 0;
|
||||||
|
auto values__ = values ? _fbb.CreateVectorOfSortedTables<Ikarus::NamedValue>(values) : 0;
|
||||||
|
auto property_values__ = property_values ? _fbb.CreateVectorOfSortedTables<Ikarus::PropertyValue>(property_values) : 0;
|
||||||
|
return Ikarus::CreateEntity(
|
||||||
|
_fbb,
|
||||||
|
id,
|
||||||
|
name__,
|
||||||
|
description__,
|
||||||
|
tags__,
|
||||||
|
values__,
|
||||||
|
property_values__);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const Ikarus::Entity *GetEntity(const void *buf) {
|
||||||
|
return ::flatbuffers::GetRoot<Ikarus::Entity>(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const Ikarus::Entity *GetSizePrefixedEntity(const void *buf) {
|
||||||
|
return ::flatbuffers::GetSizePrefixedRoot<Ikarus::Entity>(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool VerifyEntityBuffer(
|
||||||
|
::flatbuffers::Verifier &verifier) {
|
||||||
|
return verifier.VerifyBuffer<Ikarus::Entity>(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool VerifySizePrefixedEntityBuffer(
|
||||||
|
::flatbuffers::Verifier &verifier) {
|
||||||
|
return verifier.VerifySizePrefixedBuffer<Ikarus::Entity>(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void FinishEntityBuffer(
|
||||||
|
::flatbuffers::FlatBufferBuilder &fbb,
|
||||||
|
::flatbuffers::Offset<Ikarus::Entity> root) {
|
||||||
|
fbb.Finish(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void FinishSizePrefixedEntityBuffer(
|
||||||
|
::flatbuffers::FlatBufferBuilder &fbb,
|
||||||
|
::flatbuffers::Offset<Ikarus::Entity> root) {
|
||||||
|
fbb.FinishSizePrefixed(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Ikarus
|
||||||
|
|
||||||
|
#endif // FLATBUFFERS_GENERATED_ENTITY_IKARUS_H_
|
||||||
14
include/ikarus/models/property.fbs
Normal file
14
include/ikarus/models/property.fbs
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
include "value.fbs";
|
||||||
|
|
||||||
|
namespace Ikarus;
|
||||||
|
|
||||||
|
table Property {
|
||||||
|
id: int64;
|
||||||
|
name: string;
|
||||||
|
description: string;
|
||||||
|
tags: [string];
|
||||||
|
value_schema: Ikarus.Value.Schema;
|
||||||
|
default_value: Ikarus.Value.Data;
|
||||||
|
}
|
||||||
|
|
||||||
|
root_type Property;
|
||||||
289
include/ikarus/models/property_generated.h
Normal file
289
include/ikarus/models/property_generated.h
Normal file
|
|
@ -0,0 +1,289 @@
|
||||||
|
// automatically generated by the FlatBuffers compiler, do not modify
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef FLATBUFFERS_GENERATED_PROPERTY_IKARUS_H_
|
||||||
|
#define FLATBUFFERS_GENERATED_PROPERTY_IKARUS_H_
|
||||||
|
|
||||||
|
#include "flatbuffers/flatbuffers.h"
|
||||||
|
|
||||||
|
// Ensure the included flatbuffers.h is the same version as when this file was
|
||||||
|
// generated, otherwise it may not be compatible.
|
||||||
|
static_assert(FLATBUFFERS_VERSION_MAJOR == 24 &&
|
||||||
|
FLATBUFFERS_VERSION_MINOR == 3 &&
|
||||||
|
FLATBUFFERS_VERSION_REVISION == 25,
|
||||||
|
"Non-compatible flatbuffers version included");
|
||||||
|
|
||||||
|
#include "value_generated.h"
|
||||||
|
|
||||||
|
namespace Ikarus {
|
||||||
|
|
||||||
|
struct Property;
|
||||||
|
struct PropertyBuilder;
|
||||||
|
|
||||||
|
struct Property FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||||
|
typedef PropertyBuilder Builder;
|
||||||
|
struct Traits;
|
||||||
|
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||||
|
VT_ID = 4,
|
||||||
|
VT_NAME = 6,
|
||||||
|
VT_DESCRIPTION = 8,
|
||||||
|
VT_TAGS = 10,
|
||||||
|
VT_VALUE_SCHEMA_TYPE = 12,
|
||||||
|
VT_VALUE_SCHEMA = 14,
|
||||||
|
VT_DEFAULT_VALUE_TYPE = 16,
|
||||||
|
VT_DEFAULT_VALUE = 18
|
||||||
|
};
|
||||||
|
int64_t id() const {
|
||||||
|
return GetField<int64_t>(VT_ID, 0);
|
||||||
|
}
|
||||||
|
const ::flatbuffers::String *name() const {
|
||||||
|
return GetPointer<const ::flatbuffers::String *>(VT_NAME);
|
||||||
|
}
|
||||||
|
const ::flatbuffers::String *description() const {
|
||||||
|
return GetPointer<const ::flatbuffers::String *>(VT_DESCRIPTION);
|
||||||
|
}
|
||||||
|
const ::flatbuffers::Vector<::flatbuffers::Offset<::flatbuffers::String>> *tags() const {
|
||||||
|
return GetPointer<const ::flatbuffers::Vector<::flatbuffers::Offset<::flatbuffers::String>> *>(VT_TAGS);
|
||||||
|
}
|
||||||
|
Ikarus::Value::Schema value_schema_type() const {
|
||||||
|
return static_cast<Ikarus::Value::Schema>(GetField<uint8_t>(VT_VALUE_SCHEMA_TYPE, 0));
|
||||||
|
}
|
||||||
|
const void *value_schema() const {
|
||||||
|
return GetPointer<const void *>(VT_VALUE_SCHEMA);
|
||||||
|
}
|
||||||
|
template<typename T> const T *value_schema_as() const;
|
||||||
|
const Ikarus::Value::ConstantSchema *value_schema_as_ConstantSchema() const {
|
||||||
|
return value_schema_type() == Ikarus::Value::Schema::ConstantSchema ? static_cast<const Ikarus::Value::ConstantSchema *>(value_schema()) : nullptr;
|
||||||
|
}
|
||||||
|
const Ikarus::Value::SimpleSchema *value_schema_as_SimpleSchema() const {
|
||||||
|
return value_schema_type() == Ikarus::Value::Schema::SimpleSchema ? static_cast<const Ikarus::Value::SimpleSchema *>(value_schema()) : nullptr;
|
||||||
|
}
|
||||||
|
const Ikarus::Value::CombinedSchema *value_schema_as_CombinedSchema() const {
|
||||||
|
return value_schema_type() == Ikarus::Value::Schema::CombinedSchema ? static_cast<const Ikarus::Value::CombinedSchema *>(value_schema()) : nullptr;
|
||||||
|
}
|
||||||
|
const Ikarus::Value::ListSchema *value_schema_as_ListSchema() const {
|
||||||
|
return value_schema_type() == Ikarus::Value::Schema::ListSchema ? static_cast<const Ikarus::Value::ListSchema *>(value_schema()) : nullptr;
|
||||||
|
}
|
||||||
|
const Ikarus::Value::ComplexSchema *value_schema_as_ComplexSchema() const {
|
||||||
|
return value_schema_type() == Ikarus::Value::Schema::ComplexSchema ? static_cast<const Ikarus::Value::ComplexSchema *>(value_schema()) : nullptr;
|
||||||
|
}
|
||||||
|
Ikarus::Value::Data default_value_type() const {
|
||||||
|
return static_cast<Ikarus::Value::Data>(GetField<uint8_t>(VT_DEFAULT_VALUE_TYPE, 0));
|
||||||
|
}
|
||||||
|
const void *default_value() const {
|
||||||
|
return GetPointer<const void *>(VT_DEFAULT_VALUE);
|
||||||
|
}
|
||||||
|
template<typename T> const T *default_value_as() const;
|
||||||
|
const Ikarus::Value::ToggleDataPoint *default_value_as_ToggleDataPoint() const {
|
||||||
|
return default_value_type() == Ikarus::Value::Data::ToggleDataPoint ? static_cast<const Ikarus::Value::ToggleDataPoint *>(default_value()) : nullptr;
|
||||||
|
}
|
||||||
|
const Ikarus::Value::NumberDataPoint *default_value_as_NumberDataPoint() const {
|
||||||
|
return default_value_type() == Ikarus::Value::Data::NumberDataPoint ? static_cast<const Ikarus::Value::NumberDataPoint *>(default_value()) : nullptr;
|
||||||
|
}
|
||||||
|
const Ikarus::Value::TextDataPoint *default_value_as_TextDataPoint() const {
|
||||||
|
return default_value_type() == Ikarus::Value::Data::TextDataPoint ? static_cast<const Ikarus::Value::TextDataPoint *>(default_value()) : nullptr;
|
||||||
|
}
|
||||||
|
const Ikarus::Value::SimpleData *default_value_as_SimpleData() const {
|
||||||
|
return default_value_type() == Ikarus::Value::Data::SimpleData ? static_cast<const Ikarus::Value::SimpleData *>(default_value()) : nullptr;
|
||||||
|
}
|
||||||
|
const Ikarus::Value::CombinedData *default_value_as_CombinedData() const {
|
||||||
|
return default_value_type() == Ikarus::Value::Data::CombinedData ? static_cast<const Ikarus::Value::CombinedData *>(default_value()) : nullptr;
|
||||||
|
}
|
||||||
|
const Ikarus::Value::ListData *default_value_as_ListData() const {
|
||||||
|
return default_value_type() == Ikarus::Value::Data::ListData ? static_cast<const Ikarus::Value::ListData *>(default_value()) : nullptr;
|
||||||
|
}
|
||||||
|
const Ikarus::Value::ComplexData *default_value_as_ComplexData() const {
|
||||||
|
return default_value_type() == Ikarus::Value::Data::ComplexData ? static_cast<const Ikarus::Value::ComplexData *>(default_value()) : nullptr;
|
||||||
|
}
|
||||||
|
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||||
|
return VerifyTableStart(verifier) &&
|
||||||
|
VerifyField<int64_t>(verifier, VT_ID, 8) &&
|
||||||
|
VerifyOffset(verifier, VT_NAME) &&
|
||||||
|
verifier.VerifyString(name()) &&
|
||||||
|
VerifyOffset(verifier, VT_DESCRIPTION) &&
|
||||||
|
verifier.VerifyString(description()) &&
|
||||||
|
VerifyOffset(verifier, VT_TAGS) &&
|
||||||
|
verifier.VerifyVector(tags()) &&
|
||||||
|
verifier.VerifyVectorOfStrings(tags()) &&
|
||||||
|
VerifyField<uint8_t>(verifier, VT_VALUE_SCHEMA_TYPE, 1) &&
|
||||||
|
VerifyOffset(verifier, VT_VALUE_SCHEMA) &&
|
||||||
|
VerifySchema(verifier, value_schema(), value_schema_type()) &&
|
||||||
|
VerifyField<uint8_t>(verifier, VT_DEFAULT_VALUE_TYPE, 1) &&
|
||||||
|
VerifyOffset(verifier, VT_DEFAULT_VALUE) &&
|
||||||
|
VerifyData(verifier, default_value(), default_value_type()) &&
|
||||||
|
verifier.EndTable();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<> inline const Ikarus::Value::ConstantSchema *Property::value_schema_as<Ikarus::Value::ConstantSchema>() const {
|
||||||
|
return value_schema_as_ConstantSchema();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<> inline const Ikarus::Value::SimpleSchema *Property::value_schema_as<Ikarus::Value::SimpleSchema>() const {
|
||||||
|
return value_schema_as_SimpleSchema();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<> inline const Ikarus::Value::CombinedSchema *Property::value_schema_as<Ikarus::Value::CombinedSchema>() const {
|
||||||
|
return value_schema_as_CombinedSchema();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<> inline const Ikarus::Value::ListSchema *Property::value_schema_as<Ikarus::Value::ListSchema>() const {
|
||||||
|
return value_schema_as_ListSchema();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<> inline const Ikarus::Value::ComplexSchema *Property::value_schema_as<Ikarus::Value::ComplexSchema>() const {
|
||||||
|
return value_schema_as_ComplexSchema();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<> inline const Ikarus::Value::ToggleDataPoint *Property::default_value_as<Ikarus::Value::ToggleDataPoint>() const {
|
||||||
|
return default_value_as_ToggleDataPoint();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<> inline const Ikarus::Value::NumberDataPoint *Property::default_value_as<Ikarus::Value::NumberDataPoint>() const {
|
||||||
|
return default_value_as_NumberDataPoint();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<> inline const Ikarus::Value::TextDataPoint *Property::default_value_as<Ikarus::Value::TextDataPoint>() const {
|
||||||
|
return default_value_as_TextDataPoint();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<> inline const Ikarus::Value::SimpleData *Property::default_value_as<Ikarus::Value::SimpleData>() const {
|
||||||
|
return default_value_as_SimpleData();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<> inline const Ikarus::Value::CombinedData *Property::default_value_as<Ikarus::Value::CombinedData>() const {
|
||||||
|
return default_value_as_CombinedData();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<> inline const Ikarus::Value::ListData *Property::default_value_as<Ikarus::Value::ListData>() const {
|
||||||
|
return default_value_as_ListData();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<> inline const Ikarus::Value::ComplexData *Property::default_value_as<Ikarus::Value::ComplexData>() const {
|
||||||
|
return default_value_as_ComplexData();
|
||||||
|
}
|
||||||
|
|
||||||
|
struct PropertyBuilder {
|
||||||
|
typedef Property Table;
|
||||||
|
::flatbuffers::FlatBufferBuilder &fbb_;
|
||||||
|
::flatbuffers::uoffset_t start_;
|
||||||
|
void add_id(int64_t id) {
|
||||||
|
fbb_.AddElement<int64_t>(Property::VT_ID, id, 0);
|
||||||
|
}
|
||||||
|
void add_name(::flatbuffers::Offset<::flatbuffers::String> name) {
|
||||||
|
fbb_.AddOffset(Property::VT_NAME, name);
|
||||||
|
}
|
||||||
|
void add_description(::flatbuffers::Offset<::flatbuffers::String> description) {
|
||||||
|
fbb_.AddOffset(Property::VT_DESCRIPTION, description);
|
||||||
|
}
|
||||||
|
void add_tags(::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset<::flatbuffers::String>>> tags) {
|
||||||
|
fbb_.AddOffset(Property::VT_TAGS, tags);
|
||||||
|
}
|
||||||
|
void add_value_schema_type(Ikarus::Value::Schema value_schema_type) {
|
||||||
|
fbb_.AddElement<uint8_t>(Property::VT_VALUE_SCHEMA_TYPE, static_cast<uint8_t>(value_schema_type), 0);
|
||||||
|
}
|
||||||
|
void add_value_schema(::flatbuffers::Offset<void> value_schema) {
|
||||||
|
fbb_.AddOffset(Property::VT_VALUE_SCHEMA, value_schema);
|
||||||
|
}
|
||||||
|
void add_default_value_type(Ikarus::Value::Data default_value_type) {
|
||||||
|
fbb_.AddElement<uint8_t>(Property::VT_DEFAULT_VALUE_TYPE, static_cast<uint8_t>(default_value_type), 0);
|
||||||
|
}
|
||||||
|
void add_default_value(::flatbuffers::Offset<void> default_value) {
|
||||||
|
fbb_.AddOffset(Property::VT_DEFAULT_VALUE, default_value);
|
||||||
|
}
|
||||||
|
explicit PropertyBuilder(::flatbuffers::FlatBufferBuilder &_fbb)
|
||||||
|
: fbb_(_fbb) {
|
||||||
|
start_ = fbb_.StartTable();
|
||||||
|
}
|
||||||
|
::flatbuffers::Offset<Property> Finish() {
|
||||||
|
const auto end = fbb_.EndTable(start_);
|
||||||
|
auto o = ::flatbuffers::Offset<Property>(end);
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
inline ::flatbuffers::Offset<Property> CreateProperty(
|
||||||
|
::flatbuffers::FlatBufferBuilder &_fbb,
|
||||||
|
int64_t id = 0,
|
||||||
|
::flatbuffers::Offset<::flatbuffers::String> name = 0,
|
||||||
|
::flatbuffers::Offset<::flatbuffers::String> description = 0,
|
||||||
|
::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset<::flatbuffers::String>>> tags = 0,
|
||||||
|
Ikarus::Value::Schema value_schema_type = Ikarus::Value::Schema::NONE,
|
||||||
|
::flatbuffers::Offset<void> value_schema = 0,
|
||||||
|
Ikarus::Value::Data default_value_type = Ikarus::Value::Data::NONE,
|
||||||
|
::flatbuffers::Offset<void> default_value = 0) {
|
||||||
|
PropertyBuilder builder_(_fbb);
|
||||||
|
builder_.add_id(id);
|
||||||
|
builder_.add_default_value(default_value);
|
||||||
|
builder_.add_value_schema(value_schema);
|
||||||
|
builder_.add_tags(tags);
|
||||||
|
builder_.add_description(description);
|
||||||
|
builder_.add_name(name);
|
||||||
|
builder_.add_default_value_type(default_value_type);
|
||||||
|
builder_.add_value_schema_type(value_schema_type);
|
||||||
|
return builder_.Finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Property::Traits {
|
||||||
|
using type = Property;
|
||||||
|
static auto constexpr Create = CreateProperty;
|
||||||
|
};
|
||||||
|
|
||||||
|
inline ::flatbuffers::Offset<Property> CreatePropertyDirect(
|
||||||
|
::flatbuffers::FlatBufferBuilder &_fbb,
|
||||||
|
int64_t id = 0,
|
||||||
|
const char *name = nullptr,
|
||||||
|
const char *description = nullptr,
|
||||||
|
const std::vector<::flatbuffers::Offset<::flatbuffers::String>> *tags = nullptr,
|
||||||
|
Ikarus::Value::Schema value_schema_type = Ikarus::Value::Schema::NONE,
|
||||||
|
::flatbuffers::Offset<void> value_schema = 0,
|
||||||
|
Ikarus::Value::Data default_value_type = Ikarus::Value::Data::NONE,
|
||||||
|
::flatbuffers::Offset<void> default_value = 0) {
|
||||||
|
auto name__ = name ? _fbb.CreateString(name) : 0;
|
||||||
|
auto description__ = description ? _fbb.CreateString(description) : 0;
|
||||||
|
auto tags__ = tags ? _fbb.CreateVector<::flatbuffers::Offset<::flatbuffers::String>>(*tags) : 0;
|
||||||
|
return Ikarus::CreateProperty(
|
||||||
|
_fbb,
|
||||||
|
id,
|
||||||
|
name__,
|
||||||
|
description__,
|
||||||
|
tags__,
|
||||||
|
value_schema_type,
|
||||||
|
value_schema,
|
||||||
|
default_value_type,
|
||||||
|
default_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const Ikarus::Property *GetProperty(const void *buf) {
|
||||||
|
return ::flatbuffers::GetRoot<Ikarus::Property>(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const Ikarus::Property *GetSizePrefixedProperty(const void *buf) {
|
||||||
|
return ::flatbuffers::GetSizePrefixedRoot<Ikarus::Property>(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool VerifyPropertyBuffer(
|
||||||
|
::flatbuffers::Verifier &verifier) {
|
||||||
|
return verifier.VerifyBuffer<Ikarus::Property>(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool VerifySizePrefixedPropertyBuffer(
|
||||||
|
::flatbuffers::Verifier &verifier) {
|
||||||
|
return verifier.VerifySizePrefixedBuffer<Ikarus::Property>(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void FinishPropertyBuffer(
|
||||||
|
::flatbuffers::FlatBufferBuilder &fbb,
|
||||||
|
::flatbuffers::Offset<Ikarus::Property> root) {
|
||||||
|
fbb.Finish(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void FinishSizePrefixedPropertyBuffer(
|
||||||
|
::flatbuffers::FlatBufferBuilder &fbb,
|
||||||
|
::flatbuffers::Offset<Ikarus::Property> root) {
|
||||||
|
fbb.FinishSizePrefixed(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Ikarus
|
||||||
|
|
||||||
|
#endif // FLATBUFFERS_GENERATED_PROPERTY_IKARUS_H_
|
||||||
85
include/ikarus/models/value.fbs
Normal file
85
include/ikarus/models/value.fbs
Normal file
|
|
@ -0,0 +1,85 @@
|
||||||
|
namespace Ikarus.Value;
|
||||||
|
|
||||||
|
table ToggleDataPoint {
|
||||||
|
data: [bool];
|
||||||
|
}
|
||||||
|
|
||||||
|
table NumberDataPoint {
|
||||||
|
data: [double];
|
||||||
|
}
|
||||||
|
|
||||||
|
table TextDataPoint {
|
||||||
|
data: [string];
|
||||||
|
}
|
||||||
|
|
||||||
|
union Data {
|
||||||
|
ToggleDataPoint,
|
||||||
|
NumberDataPoint,
|
||||||
|
TextDataPoint,
|
||||||
|
SimpleData,
|
||||||
|
CombinedData,
|
||||||
|
ListData,
|
||||||
|
ComplexData
|
||||||
|
}
|
||||||
|
|
||||||
|
union Schema {
|
||||||
|
ConstantSchema,
|
||||||
|
SimpleSchema,
|
||||||
|
CombinedSchema,
|
||||||
|
ListSchema,
|
||||||
|
ComplexSchema
|
||||||
|
}
|
||||||
|
|
||||||
|
table ConstantSchema {
|
||||||
|
sub_schema: Schema;
|
||||||
|
data: Data;
|
||||||
|
}
|
||||||
|
|
||||||
|
table SimpleSchema {
|
||||||
|
sub_schema: Schema;
|
||||||
|
}
|
||||||
|
|
||||||
|
table SimpleData {
|
||||||
|
data: Data;
|
||||||
|
}
|
||||||
|
|
||||||
|
table CombinedSchema {
|
||||||
|
schemas: [Schema];
|
||||||
|
}
|
||||||
|
|
||||||
|
table CombinedData {
|
||||||
|
data: [Data];
|
||||||
|
}
|
||||||
|
|
||||||
|
table ListSchema {
|
||||||
|
schema: Schema;
|
||||||
|
}
|
||||||
|
|
||||||
|
table ListData {
|
||||||
|
data: [Data];
|
||||||
|
}
|
||||||
|
|
||||||
|
table NamedSchema {
|
||||||
|
name: string;
|
||||||
|
schema: Schema;
|
||||||
|
}
|
||||||
|
|
||||||
|
table ComplexSchema {
|
||||||
|
schemas: [NamedSchema];
|
||||||
|
}
|
||||||
|
|
||||||
|
table NamedData {
|
||||||
|
name: string;
|
||||||
|
data: Data;
|
||||||
|
}
|
||||||
|
|
||||||
|
table ComplexData {
|
||||||
|
data: [NamedData];
|
||||||
|
}
|
||||||
|
|
||||||
|
table Value {
|
||||||
|
schema: Schema;
|
||||||
|
data: Data;
|
||||||
|
}
|
||||||
|
|
||||||
|
root_type Value;
|
||||||
1719
include/ikarus/models/value_generated.h
Normal file
1719
include/ikarus/models/value_generated.h
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -4,7 +4,6 @@
|
||||||
/// \author Folling <folling@ikarus.world>
|
/// \author Folling <folling@ikarus.world>
|
||||||
|
|
||||||
#include <ikarus/errors.h>
|
#include <ikarus/errors.h>
|
||||||
#include <ikarus/id.h>
|
|
||||||
#include <ikarus/macros.h>
|
#include <ikarus/macros.h>
|
||||||
#include <ikarus/stdtypes.h>
|
#include <ikarus/stdtypes.h>
|
||||||
|
|
||||||
|
|
@ -14,9 +13,10 @@
|
||||||
|
|
||||||
IKARUS_BEGIN_HEADER
|
IKARUS_BEGIN_HEADER
|
||||||
|
|
||||||
/// \brief A blueprint object.
|
/// \brief Blueprints are templates for managing common properties of entities.
|
||||||
/// \details A blueprint is a collection of properties which can be linked to entities.
|
/// \details A blueprint is a collection of properties which can be linked to entities.
|
||||||
/// Each entity the blueprint is linked to will have values for the blueprints properties.q
|
/// Each entity the blueprint is linked to will have values for the blueprints
|
||||||
|
/// properties. Changes in blueprints will be reflected in all linked entities.
|
||||||
struct IkarusBlueprint;
|
struct IkarusBlueprint;
|
||||||
|
|
||||||
/// \brief Creates a blueprint.
|
/// \brief Creates a blueprint.
|
||||||
|
|
@ -25,19 +25,24 @@ struct IkarusBlueprint;
|
||||||
/// \pre \li Must exist.
|
/// \pre \li Must exist.
|
||||||
/// \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 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.
|
||||||
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 a blueprint.
|
||||||
/// \param blueprint The blueprint to delete.
|
/// \param blueprint The blueprint to delete.
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
/// \pre \li Must exist.
|
/// \pre \li Must exist.
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \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 ID of a blueprint.
|
/// \brief Gets the ID of a blueprint.
|
||||||
/// \param blueprint The blueprint to get the ID of.
|
/// \param blueprint The blueprint to get the ID of.
|
||||||
|
|
@ -45,23 +50,32 @@ IKA_API void ikarus_blueprint_delete(IkarusBlueprint * blueprint, IkarusErrorDat
|
||||||
/// \pre \li Must exist.
|
/// \pre \li Must exist.
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \return The ID of the blueprint or 0 if an error occurs.
|
/// \return The ID of the blueprint or 0 if an error occurs.
|
||||||
IKA_API IkarusId ikarus_blueprint_get_id(IkarusBlueprint const * blueprint, IkarusErrorData * error_out);
|
IKA_API int64_t ikarus_blueprint_get_id(
|
||||||
|
IkarusBlueprint const * blueprint,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
);
|
||||||
|
|
||||||
/// \brief Gets the project a blueprint is part of.
|
/// \brief Gets the project a blueprint is part of.
|
||||||
/// \param blueprint The blueprint to get the project of.
|
/// \param blueprint The blueprint to get the project of.
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
/// \pre \li Must exist.
|
/// \pre \li Must exist.
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \return The project the blueprint is part of or null if an error occurs.
|
/// \return The project or null if an error occurs.
|
||||||
IKA_API IkarusProject * ikarus_blueprint_get_project(IkarusBlueprint const * blueprint, IkarusErrorData * error_out);
|
IKA_API IkarusProject * ikarus_blueprint_get_project(
|
||||||
|
IkarusBlueprint const * blueprint,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
);
|
||||||
|
|
||||||
/// \brief Gets the name of a blueprint.
|
/// \brief Gets the name of a blueprint.
|
||||||
/// \param blueprint The blueprint to get the name of.
|
/// \param blueprint The blueprint to get the name of.
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
/// \pre \li Must exist.
|
/// \pre \li Must exist.
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \return The name of the blueprint or null if an error occurs.
|
/// \return The name or null if an error occurs.
|
||||||
IKA_API char const * ikarus_blueprint_get_name(IkarusBlueprint const * blueprint, IkarusErrorData * error_out);
|
IKA_API char const * ikarus_blueprint_get_name(
|
||||||
|
IkarusBlueprint const * blueprint,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
);
|
||||||
|
|
||||||
/// \brief Sets the name of a blueprint.
|
/// \brief Sets the name of a blueprint.
|
||||||
/// \param blueprint The blueprint to set the name of.
|
/// \param blueprint The blueprint to set the name of.
|
||||||
|
|
@ -69,10 +83,12 @@ IKA_API char const * ikarus_blueprint_get_name(IkarusBlueprint const * blueprint
|
||||||
/// \pre \li Must exist.
|
/// \pre \li Must exist.
|
||||||
/// \param name The new name of the blueprint.
|
/// \param name The new 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 be unique among all blueprints in the project.
|
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
IKA_API void ikarus_blueprint_set_name(IkarusBlueprint * blueprint, char const * name, IkarusErrorData * error_out);
|
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.
|
||||||
|
|
@ -96,7 +112,10 @@ IKA_API void ikarus_blueprint_get_properties(
|
||||||
/// \pre \li Must exist.
|
/// \pre \li Must exist.
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \return The number of properties or undefined if an error occurs.
|
/// \return The number of properties or undefined if an error occurs.
|
||||||
IKA_API size_t ikarus_blueprint_get_property_count(IkarusBlueprint const * blueprint, IkarusErrorData * error_out);
|
IKA_API size_t ikarus_blueprint_get_property_count(
|
||||||
|
IkarusBlueprint const * blueprint,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
);
|
||||||
|
|
||||||
/// \brief Gets the entities linked to a blueprint.
|
/// \brief Gets the entities linked to a blueprint.
|
||||||
/// \param blueprint The blueprint to get the linked entities of.
|
/// \param blueprint The blueprint to get the linked entities of.
|
||||||
|
|
@ -120,7 +139,10 @@ IKA_API void ikarus_blueprint_get_linked_entities(
|
||||||
/// \pre \li Must exist.
|
/// \pre \li Must exist.
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \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
|
||||||
|
);
|
||||||
|
|
||||||
IKARUS_END_HEADER
|
IKARUS_END_HEADER
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <ikarus/errors.h>
|
#include <ikarus/errors.h>
|
||||||
#include <ikarus/id.h>
|
|
||||||
#include <ikarus/macros.h>
|
#include <ikarus/macros.h>
|
||||||
#include <ikarus/stdtypes.h>
|
#include <ikarus/stdtypes.h>
|
||||||
|
|
||||||
|
|
@ -14,25 +13,20 @@
|
||||||
IKARUS_BEGIN_HEADER
|
IKARUS_BEGIN_HEADER
|
||||||
|
|
||||||
/// \brief Entities are the core building blocks of Ikarus.
|
/// \brief Entities are the core building blocks of Ikarus.
|
||||||
/// \detials Blueprints and Properties define the structure of the data.
|
/// \details Entities store two data: A name and a set of values.
|
||||||
/// Entities define the data itself.
|
/// The name identifies the entity but does not have to be unique. The values
|
||||||
|
/// are the actual information of the entity.
|
||||||
///
|
///
|
||||||
/// Properties can be associated with Entities in two ways:
|
/// For documentation on the types and layout of values \see Values.h.
|
||||||
/// - Directly: The property is linked to the entity.
|
|
||||||
/// - Indirectly: The property is linked to a blueprint the entity is linked to.
|
|
||||||
///
|
///
|
||||||
/// For each property an entity is linked to, it has a value. These values depend on the property's type.
|
/// Entities can be linked to blueprints.
|
||||||
/// For more information on the types see the property documentation.
|
/// The entity has a (possibly uninitialized) value for each property of all
|
||||||
|
/// blueprints it is linked to. \see Property.h \see Blueprint.h.
|
||||||
///
|
///
|
||||||
/// Values are the core type of data within Ikarus.
|
/// We distinguish between `EntityValues` and `EntityPropertyValues`.
|
||||||
/// Each value is associated with one page and one property.
|
/// `EntityValues` are a direct part of the entity.
|
||||||
///
|
/// `EntityPropertyValues` are an indirect part of the entity, linked to them
|
||||||
/// \remark Values are typed, the type of a value is specified by its associated property.
|
/// via a blueprint.
|
||||||
/// For more information on the types see the property documentation.
|
|
||||||
///
|
|
||||||
/// \remark Values are guaranteed to be in valid format for a given type
|
|
||||||
/// but not guaranteed to be valid under the settings of the property.
|
|
||||||
/// This is because changing the settings can invalidate existing values without resetting them.
|
|
||||||
struct IkarusEntity;
|
struct IkarusEntity;
|
||||||
|
|
||||||
/// \brief Creates an entity.
|
/// \brief Creates an entity.
|
||||||
|
|
@ -41,11 +35,13 @@ struct IkarusEntity;
|
||||||
/// \pre \li Must exist.
|
/// \pre \li Must exist.
|
||||||
/// \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 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.
|
||||||
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.
|
||||||
/// \param entity The entity to delete.
|
/// \param entity The entity to delete.
|
||||||
|
|
@ -53,15 +49,17 @@ IKA_API IkarusEntity * ikarus_entity_create(struct IkarusProject * project, char
|
||||||
/// \pre \li Must exist.
|
/// \pre \li Must exist.
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \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 ID of an entity.
|
/// \brief Gets the id of an entity.
|
||||||
/// \param entity The entity to get the ID of.
|
/// \param entity The entity to get the id of.
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
/// \pre \li Must exist.
|
/// \pre \li Must exist.
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \return The ID of the entity or 0 if an error occurs.
|
/// \return The id of the entity or 0 if an error occurs.
|
||||||
IKA_API IkarusId ikarus_entity_get_id(IkarusEntity const * entity, IkarusErrorData * error_out);
|
IKA_API int64_t
|
||||||
|
ikarus_entity_get_id(IkarusEntity const * entity, IkarusErrorData * error_out);
|
||||||
|
|
||||||
/// \brief Gets the project an entity is part of.
|
/// \brief Gets the project an entity is part of.
|
||||||
/// \param entity The entity to get the project of.
|
/// \param entity The entity to get the project of.
|
||||||
|
|
@ -69,7 +67,10 @@ IKA_API IkarusId ikarus_entity_get_id(IkarusEntity const * entity, IkarusErrorDa
|
||||||
/// \pre \li Must exist.
|
/// \pre \li Must exist.
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \return The project the entity is part of or null if an error occurs.
|
/// \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);
|
IKA_API IkarusProject * ikarus_entity_get_project(
|
||||||
|
IkarusEntity const * entity,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
);
|
||||||
|
|
||||||
/// \brief Gets the name of an entity.
|
/// \brief Gets the name of an entity.
|
||||||
/// \param entity The entity to get the name of.
|
/// \param entity The entity to get the name of.
|
||||||
|
|
@ -77,7 +78,10 @@ IKA_API IkarusProject * ikarus_entity_get_project(IkarusEntity const * entity, I
|
||||||
/// \pre \li Must exist.
|
/// \pre \li Must exist.
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \return The name of the entity or null if an error occurs.
|
/// \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);
|
IKA_API char const * ikarus_entity_get_name(
|
||||||
|
IkarusEntity const * entity,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
);
|
||||||
|
|
||||||
/// \brief Sets the name of an entity.
|
/// \brief Sets the name of an entity.
|
||||||
/// \param entity The entity to set the name of.
|
/// \param entity The entity to set the name of.
|
||||||
|
|
@ -85,10 +89,12 @@ IKA_API char const * ikarus_entity_get_name(IkarusEntity const * entity, IkarusE
|
||||||
/// \pre \li Must exist.
|
/// \pre \li Must exist.
|
||||||
/// \param name The new name of the entity.
|
/// \param name The new 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 be unique among all entities in the project.
|
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
IKA_API void ikarus_entity_set_name(IkarusEntity * entity, char const * name, IkarusErrorData * error_out);
|
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.
|
||||||
|
|
@ -99,8 +105,11 @@ IKA_API void ikarus_entity_set_name(IkarusEntity * entity, char const * name, Ik
|
||||||
/// \pre \li Must exist.
|
/// \pre \li Must exist.
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \return True if the entity is linked to the blueprint, false otherwise.
|
/// \return True if the entity is linked to the blueprint, false otherwise.
|
||||||
IKA_API bool
|
IKA_API bool ikarus_entity_is_linked_to_blueprint(
|
||||||
ikarus_entity_is_linked_to_blueprint(IkarusEntity const * entity, struct IkarusBlueprint const * blueprint, IkarusErrorData * error_out);
|
IkarusEntity const * entity,
|
||||||
|
struct IkarusBlueprint const * blueprint,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
);
|
||||||
|
|
||||||
/// \brief Links an entity to a blueprint.
|
/// \brief Links an entity to a blueprint.
|
||||||
/// \param entity The entity to link.
|
/// \param entity The entity to link.
|
||||||
|
|
@ -111,10 +120,14 @@ ikarus_entity_is_linked_to_blueprint(IkarusEntity const * entity, struct IkarusB
|
||||||
/// \pre \li Must exist.
|
/// \pre \li Must exist.
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \remark No-op if the entity is already linked to the blueprint.
|
/// \remark No-op if the entity is already linked to the blueprint.
|
||||||
IKA_API void ikarus_entity_link_to_blueprint(IkarusEntity * entity, struct IkarusBlueprint * blueprint, IkarusErrorData * error_out);
|
IKA_API void ikarus_entity_link_to_blueprint(
|
||||||
|
IkarusEntity * entity,
|
||||||
|
struct IkarusBlueprint * blueprint,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
);
|
||||||
|
|
||||||
/// \brief Unlinks an entity from a blueprint. All values of the properties of the blueprint the entity is linked with
|
/// \brief Unlinks an entity from a blueprint.
|
||||||
/// will be deleted.
|
/// All values of the blueprints' properties will be deleted.
|
||||||
/// \param entity The entity to unlink.
|
/// \param entity The entity to unlink.
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
/// \pre \li Must exist.
|
/// \pre \li Must exist.
|
||||||
|
|
@ -123,9 +136,13 @@ IKA_API void ikarus_entity_link_to_blueprint(IkarusEntity * entity, struct Ikaru
|
||||||
/// \pre \li Must exist.
|
/// \pre \li Must exist.
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \remark No-op if the entity is not linked to the blueprint.
|
/// \remark No-op if the entity is not linked to the blueprint.
|
||||||
IKA_API void ikarus_entity_unlink_from_blueprint(IkarusEntity * entity, struct IkarusBlueprint * blueprint, IkarusErrorData * error_out);
|
IKA_API void ikarus_entity_unlink_from_blueprint(
|
||||||
|
IkarusEntity * entity,
|
||||||
|
struct IkarusBlueprint * blueprint,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
);
|
||||||
|
|
||||||
/// \brief Gets the blueprints an entity is linked to.
|
/// \brief Gets all blueprints an entity is linked to.
|
||||||
/// \param entity The entity to get the blueprints of.
|
/// \param entity The entity to get the blueprints of.
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
/// \pre \li Must exist.
|
/// \pre \li Must exist.
|
||||||
|
|
@ -142,14 +159,80 @@ IKA_API void ikarus_entity_get_linked_blueprints(
|
||||||
);
|
);
|
||||||
|
|
||||||
/// \brief Gets the number of blueprints an entity is linked to.
|
/// \brief Gets the number of blueprints an entity is linked to.
|
||||||
/// \param entity The entity to get the number of blueprints of.
|
/// \param entity The entity to get the number of linked blueprints of.
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
/// \pre \li Must exist.
|
/// \pre \li Must exist.
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \return The number of blueprints or undefined if an error occurs.
|
/// \return The number of blueprints or undefined if an error occurs.
|
||||||
IKA_API size_t ikarus_entity_get_linked_blueprint_count(IkarusEntity const * entity, IkarusErrorData * error_out);
|
IKA_API size_t ikarus_entity_get_linked_blueprint_count(
|
||||||
|
IkarusEntity const * entity,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
);
|
||||||
|
|
||||||
/// \brief Checks if an entity has a specific property.
|
/// \brief Checks if an entity has a value with a given name.
|
||||||
|
/// \param entity The entity to check.
|
||||||
|
/// \pre \li Must not be null.
|
||||||
|
/// \pre \li Must exist.
|
||||||
|
/// \param name The name of the value to check.
|
||||||
|
/// \pre \li Must not be null.
|
||||||
|
/// \param error_out \see errors.h
|
||||||
|
/// \return False if the entity does not have a value associated with
|
||||||
|
/// the name or if an error occurs, true otherwise.
|
||||||
|
IKA_API bool ikarus_entity_has_value(
|
||||||
|
IkarusEntity const * entity,
|
||||||
|
char const * name,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
);
|
||||||
|
|
||||||
|
/// \brief Gets the value of an entity.
|
||||||
|
/// \param entity The entity to get the value of.
|
||||||
|
/// \pre \li Must not be null.
|
||||||
|
/// \pre \li Must exist.
|
||||||
|
/// \param name The name of the value to get.
|
||||||
|
/// \pre \li Must not be null.
|
||||||
|
/// \pre \li Must be an existing value of the entity.
|
||||||
|
/// \param error_out \see errors.h
|
||||||
|
/// \return The value of the entity or null if an error occurs.
|
||||||
|
IKA_API struct IkarusValue * ikarus_entity_get_value(
|
||||||
|
IkarusEntity const * entity,
|
||||||
|
char const * name,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
);
|
||||||
|
|
||||||
|
/// \brief Sets the value of an entity.
|
||||||
|
/// If the entity does not have a value associated with the name, it is created.
|
||||||
|
/// \remark Types are overwritten if the value already exists.
|
||||||
|
/// \param entity The entity to set the value of.
|
||||||
|
/// \pre \li Must not be null.
|
||||||
|
/// \pre \li Must exist.
|
||||||
|
/// \param name The name of the value to set.
|
||||||
|
/// \pre \li Must not be null.
|
||||||
|
/// \pre \li Must exist.
|
||||||
|
/// \param value The new value of the entity.
|
||||||
|
/// \pre \li Must not be null.
|
||||||
|
/// \param error_out \see errors.h
|
||||||
|
IKA_API void ikarus_entity_set_value(
|
||||||
|
IkarusEntity * entity,
|
||||||
|
char const * name,
|
||||||
|
struct IkarusValue const * value,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
);
|
||||||
|
|
||||||
|
/// \brief Removes a value from an entity.
|
||||||
|
/// \pre \li The value must exist.
|
||||||
|
/// \param entity The entity to delete the value of.
|
||||||
|
/// \pre \li Must not be null.
|
||||||
|
/// \pre \li Must exist.
|
||||||
|
/// \param name The name of the value to delete.
|
||||||
|
/// \pre \li Must not be null.
|
||||||
|
/// \param error_out \see errors.h
|
||||||
|
IKA_API void ikarus_entity_remove_value(
|
||||||
|
IkarusEntity * entity,
|
||||||
|
char const * name,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
);
|
||||||
|
|
||||||
|
/// \brief Checks if a property is linked to an entity.
|
||||||
/// \param entity The entity to check.
|
/// \param entity The entity to check.
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
/// \pre \li Must exist.
|
/// \pre \li Must exist.
|
||||||
|
|
@ -157,14 +240,19 @@ IKA_API size_t ikarus_entity_get_linked_blueprint_count(IkarusEntity const * ent
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
/// \pre \li Must exist.
|
/// \pre \li Must exist.
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \return False if an error occurs or the entity does not have the property, true otherwise.
|
/// \return False if an error occurs or the entity does not have the property,
|
||||||
IKA_API bool ikarus_entity_has_property(IkarusEntity const * entity, struct IkarusProperty const * property, IkarusErrorData * error_out);
|
/// true otherwise.
|
||||||
|
IKA_API bool ikarus_entity_has_property(
|
||||||
|
IkarusEntity const * entity,
|
||||||
|
struct IkarusProperty const * property,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
);
|
||||||
|
|
||||||
/// \brief Gets the properties of an entity.
|
/// \brief Gets the properties an entity is linked to.
|
||||||
/// \param entity The entity to get the properties of.
|
/// \param entity The entity to get the linked properties of.
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
/// \pre \li Must exist.
|
/// \pre \li Must exist.
|
||||||
/// \param properties_out The buffer to write the properties to.
|
/// \param properties_out The buffer to write the linked properties to.
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \param properties_out_size The size of the buffer.
|
/// \param properties_out_size The size of the buffer.
|
||||||
|
|
@ -176,30 +264,37 @@ IKA_API void ikarus_entity_get_properties(
|
||||||
IkarusErrorData * error_out
|
IkarusErrorData * error_out
|
||||||
);
|
);
|
||||||
|
|
||||||
/// \brief Gets the number of properties of an entity.
|
/// \brief Gets the number of properties an entity is linked to.
|
||||||
/// \param entity The entity to get the number of properties of.
|
/// \param entity The entity to get the number of linked properties of.
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
/// \pre \li Must exist.
|
/// \pre \li Must exist.
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \return The number of properties or undefined if an error occurs.
|
/// \return The number of properties or undefined if an error occurs.
|
||||||
IKA_API size_t ikarus_entity_get_property_count(IkarusEntity const * entity, IkarusErrorData * error_out);
|
IKA_API size_t ikarus_entity_get_property_count(
|
||||||
|
IkarusEntity const * entity,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
);
|
||||||
|
|
||||||
/// \brief Gets the value of a property of an entity.
|
/// \brief Gets the value of a property of an entity.
|
||||||
/// \details If the entity has never set the value of the property, the default value is returned (which may be undefined).
|
/// \details If the entity has never set the value of the property,
|
||||||
|
/// the property's default value is returned.
|
||||||
/// \param entity The entity to get the value of.
|
/// \param entity The entity to get the value of.
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
/// \pre \li Must exist.
|
/// \pre \li Must exist.
|
||||||
/// \param property The property to get the value of.
|
/// \param property The property to get the value of.
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
/// \pre \li Must exist.
|
/// \pre \li Must exist.
|
||||||
|
/// \pre \li Must be linked to the entity.
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \return The value of the property or null if the entity does not have the property or an error occurs.
|
/// \return The value of the property or null if an error occurs.
|
||||||
/// \remark Must be freed using #ikarus_free.
|
IKA_API struct IkarusValue * ikarus_entity_get_property_value(
|
||||||
IKA_API struct IkarusEntityPropertyValue *
|
IkarusEntity const * entity,
|
||||||
ikarus_entity_get_value(IkarusEntity const * entity, struct IkarusProperty const * property, IkarusErrorData * error_out);
|
struct IkarusProperty const * property,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
);
|
||||||
|
|
||||||
/// \brief Sets the value of a property of an entity.
|
/// \brief Sets the value of a property of an entity.
|
||||||
/// \param entity The entity to set the value of.
|
/// \param entity The entity to set the property value of.
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
/// \pre \li Must exist.
|
/// \pre \li Must exist.
|
||||||
/// \param property The property to set the value of.
|
/// \param property The property to set the value of.
|
||||||
|
|
@ -211,7 +306,7 @@ ikarus_entity_get_value(IkarusEntity const * entity, struct IkarusProperty const
|
||||||
/// \pre \li Must be valid for the property's settings.
|
/// \pre \li Must be valid for the property's settings.
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \remark If the entity does not have the property, this function fails.
|
/// \remark If the entity does not have the property, this function fails.
|
||||||
IKA_API void ikarus_entity_set_value(
|
IKA_API void ikarus_entity_set_property_value(
|
||||||
IkarusEntity * entity,
|
IkarusEntity * entity,
|
||||||
struct IkarusProperty const * property,
|
struct IkarusProperty const * property,
|
||||||
struct IkarusValue const * value,
|
struct IkarusValue const * value,
|
||||||
|
|
|
||||||
|
|
@ -1,50 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
/// \file object.h
|
|
||||||
/// \author Folling <folling@ikarus.world>
|
|
||||||
|
|
||||||
#include <ikarus/errors.h>
|
|
||||||
#include <ikarus/macros.h>
|
|
||||||
|
|
||||||
/// \defgroup object Objects
|
|
||||||
/// \brief Objects are a compound type of all types of objects in the database.
|
|
||||||
/// \details The following objects currently exist:
|
|
||||||
/// - \ref blueprint.h "Blueprints"
|
|
||||||
/// - \ref property.h "Properties"
|
|
||||||
/// - \ref entity.h "Entities"
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
IKARUS_BEGIN_HEADER
|
|
||||||
|
|
||||||
/// \brief A generic object. Wraps all types of objects, including folders.
|
|
||||||
struct IkarusObject;
|
|
||||||
|
|
||||||
/// \brief Visits an object. Calling the appropriate function for the object's type.
|
|
||||||
/// \param object The object to visit.
|
|
||||||
/// \param blueprint_visitor The function to call if the object is a blueprint. Skipped if null.
|
|
||||||
/// \param property_visitor The function to call if the object is a property. Skipped if null.
|
|
||||||
/// \param entity_visitor The function to call if the object is an entity. Skipped if null.
|
|
||||||
/// \param data The data passed to the visitor functions.
|
|
||||||
/// \param error_out \see errors.h
|
|
||||||
IKA_API 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
|
|
||||||
);
|
|
||||||
|
|
||||||
/// \see ikarus_object_visit
|
|
||||||
IKA_API 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_END_HEADER
|
|
||||||
|
|
||||||
/// @}
|
|
||||||
|
|
@ -1,34 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
/// \file object_type.h
|
|
||||||
/// \author Folling <folling@ikarus.world>
|
|
||||||
|
|
||||||
#include <ikarus/errors.h>
|
|
||||||
#include <ikarus/macros.h>
|
|
||||||
|
|
||||||
/// \addtogroup objects Objects
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
IKARUS_BEGIN_HEADER
|
|
||||||
|
|
||||||
/// \brief The type of an object.
|
|
||||||
enum IkarusObjectType {
|
|
||||||
/// \brief Not an object or no object.
|
|
||||||
IkarusObjectType_None = 0,
|
|
||||||
/// \brief An IkarusEntity.
|
|
||||||
IkarusObjectType_Entity = 0b00000001,
|
|
||||||
/// \brief An IkarusBlueprint.
|
|
||||||
IkarusObjectType_Blueprint = 0b00000010,
|
|
||||||
/// \brief An IkarusProperty.
|
|
||||||
IkarusObjectType_Property = 0b00000011,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// \brief Converts an IkarusObjectType to a string.
|
|
||||||
/// \param type The type to convert.
|
|
||||||
/// \return The string representation of the type.
|
|
||||||
/// \remark The returned string must not be freed.
|
|
||||||
char const * ikarus_object_type_to_string(IkarusObjectType type);
|
|
||||||
|
|
||||||
IKARUS_END_HEADER
|
|
||||||
|
|
||||||
/// @}
|
|
||||||
|
|
@ -20,7 +20,6 @@ struct IkarusNumberProperty;
|
||||||
/// \pre \li Must exist.
|
/// \pre \li Must exist.
|
||||||
/// \param name The name of the property.
|
/// \param name The name of the property.
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
/// \pre \li Must not be empty.
|
|
||||||
/// \param property_source The property source to create the property for.
|
/// \param property_source The property source to create the property for.
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
/// \pre \li Must exist.
|
/// \pre \li Must exist.
|
||||||
|
|
@ -36,31 +35,6 @@ IKA_API IkarusNumberProperty * ikarus_number_property_create(
|
||||||
IkarusErrorData * error_out
|
IkarusErrorData * error_out
|
||||||
);
|
);
|
||||||
|
|
||||||
/// \brief Sets the default value for a number property.
|
|
||||||
/// \param property The number property.
|
|
||||||
/// \pre \li Must not be null.
|
|
||||||
/// \pre \li Must exist.
|
|
||||||
/// \param error_out \see errors.h
|
|
||||||
/// \return The default value or null if an error occurs.
|
|
||||||
IKA_API struct IkarusNumberValue *
|
|
||||||
ikarus_number_property_get_default_value(struct IkarusNumberProperty * property, IkarusErrorData * error_out);
|
|
||||||
|
|
||||||
/// \brief Sets the default value for a number property.
|
|
||||||
/// \param property The number property.
|
|
||||||
/// \pre \li Must not be null.
|
|
||||||
/// \pre \li Must exist.
|
|
||||||
/// \param new_default_value The default value.
|
|
||||||
/// \pre \li Must not be null.
|
|
||||||
/// \pre \li Must be a valid value for the property.
|
|
||||||
/// \param error_out \see errors.h
|
|
||||||
/// \remark Please see \ref property.h "the property documentation" for more information on the interplay between
|
|
||||||
/// default values and other settings.
|
|
||||||
IKA_API void ikarus_number_property_set_default_value(
|
|
||||||
struct IkarusNumberProperty * property,
|
|
||||||
struct IkarusNumberValue * new_default_value,
|
|
||||||
IkarusErrorData * error_out
|
|
||||||
);
|
|
||||||
|
|
||||||
IKARUS_END_HEADER
|
IKARUS_END_HEADER
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,10 @@
|
||||||
/// \author Folling <folling@ikarus.world>
|
/// \author Folling <folling@ikarus.world>
|
||||||
|
|
||||||
#include <ikarus/errors.h>
|
#include <ikarus/errors.h>
|
||||||
#include <ikarus/id.h>
|
|
||||||
#include <ikarus/macros.h>
|
#include <ikarus/macros.h>
|
||||||
#include <ikarus/objects/properties/property_type.h>
|
|
||||||
#include <ikarus/stdtypes.h>
|
#include <ikarus/stdtypes.h>
|
||||||
|
#include <ikarus/values/value_cardinality.h>
|
||||||
|
#include <ikarus/values/value_type.h>
|
||||||
|
|
||||||
/// \defgroup properties Properties
|
/// \defgroup properties Properties
|
||||||
/// \brief Properties define the structure and types of data.
|
/// \brief Properties define the structure and types of data.
|
||||||
|
|
@ -15,9 +15,10 @@
|
||||||
|
|
||||||
IKARUS_BEGIN_HEADER
|
IKARUS_BEGIN_HEADER
|
||||||
|
|
||||||
/// \brief Properties are the placeholders of values for entities.
|
/// \brief Properties define the structure of blueprints.
|
||||||
/// \details Each entity can have any number of properties.
|
/// \details Each blueprint can have any number of properties.
|
||||||
/// Every property has a type that identifies the kind of data that can be put in.
|
/// Every property has a type that identifies the kind of data that can be put in.
|
||||||
|
/// This is the "base class" of properties. See the derived types (e.g. IkarusToggleProperty) for more information.
|
||||||
///
|
///
|
||||||
/// The following types currently exist:
|
/// The following types currently exist:
|
||||||
/// - Toggle: A true/false boolean-like value
|
/// - Toggle: A true/false boolean-like value
|
||||||
|
|
@ -29,32 +30,10 @@ IKARUS_BEGIN_HEADER
|
||||||
/// - Age (Number)
|
/// - Age (Number)
|
||||||
/// - ISBN (Text)
|
/// - ISBN (Text)
|
||||||
///
|
///
|
||||||
/// Every property has settings which can be used to customise the property further.
|
|
||||||
/// Two settings that are shared among all properties are the following:
|
|
||||||
/// - List
|
|
||||||
/// - May be undefined
|
|
||||||
///
|
|
||||||
/// Additionally, each property has a default value. If no default value is provided, a sensible default is chosen.
|
|
||||||
/// Setting a default value that isn't valid for the property is an error. Changing settings so that the current default
|
|
||||||
/// value becomes invalid is valid but unsets the custom default value.
|
|
||||||
///
|
|
||||||
/// The former transforms a property into a list. Instead of one number, you could then specify a series of numbers.
|
|
||||||
/// The latter allows you to specify an "unknown" value for a property.
|
|
||||||
/// It might not be known if a character is dead or not for example.
|
|
||||||
///
|
|
||||||
/// Each entity associated with the property has a value for it.
|
/// Each entity associated with the property has a value for it.
|
||||||
///
|
///
|
||||||
/// Properties can also be added to blueprints in which case they are available for all entities associated with the
|
/// \remark Values for properties are lazily created to save space.
|
||||||
/// blueprint.
|
|
||||||
///
|
|
||||||
/// We call properties within entities "Entity Properties" and properties within blueprints "Blueprint Properties".
|
|
||||||
///
|
|
||||||
///
|
|
||||||
/// \remark Properties are scoped to the blueprint or entity they are associated with.
|
|
||||||
/// \remark Values for properties are lazily created as space saving measure.
|
|
||||||
/// Fetching the value for some property of some entity will return the property's default value if none is specified.
|
/// Fetching the value for some property of some entity will return the property's default value if none is specified.
|
||||||
/// This default value is specified when the property is created and can be updated later.
|
|
||||||
/// \remark Properties' tree structures are scoped to the entity or blueprint they are associated with.
|
|
||||||
struct IkarusProperty;
|
struct IkarusProperty;
|
||||||
|
|
||||||
/// \brief Deletes a property.
|
/// \brief Deletes a property.
|
||||||
|
|
@ -71,7 +50,7 @@ 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 ID of the property or 0 if an error occurs.
|
/// \return The ID of the property or 0 if an error occurs.
|
||||||
IKA_API IkarusId ikarus_property_get_id(IkarusProperty const * property, IkarusErrorData * error_out);
|
IKA_API int64_t ikarus_property_get_id(IkarusProperty const * property, IkarusErrorData * error_out);
|
||||||
|
|
||||||
/// \brief Gets the project of a property.
|
/// \brief Gets the project of a property.
|
||||||
/// \param property The property to get the project of.
|
/// \param property The property to get the project of.
|
||||||
|
|
@ -81,31 +60,66 @@ IKA_API IkarusId ikarus_property_get_id(IkarusProperty const * property, IkarusE
|
||||||
/// \return The project of the property or null if an error occurs.
|
/// \return The project of the property or null if an error occurs.
|
||||||
IKA_API struct IkarusProject * ikarus_property_get_project(IkarusProperty const * property, IkarusErrorData * error_out);
|
IKA_API struct IkarusProject * ikarus_property_get_project(IkarusProperty const * property, IkarusErrorData * error_out);
|
||||||
|
|
||||||
|
/// \brief Gets the name of an property.
|
||||||
|
/// \param entity The property 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 property or null if an error occurs.
|
||||||
|
IKA_API char const * ikarus_property_get_name(IkarusProperty const * entity, IkarusErrorData * error_out);
|
||||||
|
|
||||||
|
/// \brief Sets the name of an property.
|
||||||
|
/// \param entity The property to set the name of.
|
||||||
|
/// \pre \li Must not be null.
|
||||||
|
/// \pre \li Must exist.
|
||||||
|
/// \param name The new name of the property.
|
||||||
|
/// \pre \li Must not be null.
|
||||||
|
/// \param error_out \see errors.h
|
||||||
|
IKA_API void ikarus_property_set_name(IkarusProperty * entity, char const * name, IkarusErrorData * error_out);
|
||||||
|
|
||||||
/// \brief Gets the type info of a property.
|
/// \brief Gets the type info of a property.
|
||||||
/// \param property The property to get the type info of.
|
/// \param property The property to get the type info of.
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
/// \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.
|
||||||
IKA_API IkarusPropertyType ikarus_property_get_type(IkarusProperty const * property, IkarusErrorData * error_out);
|
/// \remark Changing the type of a property is not supported. This is because the property would need to change
|
||||||
|
IKA_API IkarusValueType ikarus_property_get_type(IkarusProperty const * property, IkarusErrorData * error_out);
|
||||||
|
|
||||||
/// \brief Gets the source of a property.
|
// there is no `set_type` as we encode type information in the underlying datatype
|
||||||
|
|
||||||
|
/// \briefs Gets a property's cardinality.
|
||||||
|
/// \param property The property to get the cardinality of.
|
||||||
|
/// \pre \li Must not be null.
|
||||||
|
/// \pre \li Must exist.
|
||||||
|
/// \param error_out \see errors.h
|
||||||
|
/// \return The cardinality of the property or false if an error occurs.
|
||||||
|
IKA_API IkarusValueCardinality ikarus_property_get_cardinality(IkarusProperty const * property, IkarusErrorData * error_out);
|
||||||
|
|
||||||
|
/// \briefs Sets a property's default value.
|
||||||
|
/// \param property The property to set the cardinality of.
|
||||||
|
/// \pre \li Must not be null.
|
||||||
|
/// \pre \li Must exist.
|
||||||
|
/// \\param cardinality The new cardinality of the property.
|
||||||
|
/// \param error_out \see errors.h
|
||||||
|
IKA_API void
|
||||||
|
ikarus_property_set_cardinality(IkarusProperty * property, IkarusValueCardinality cardinality, IkarusErrorData * error_out);
|
||||||
|
|
||||||
|
/// \briefs Gets a property's default value.
|
||||||
|
/// \param property The property to get the default value of.
|
||||||
|
/// \pre \li Must not be null.
|
||||||
|
/// \pre \li Must exist.
|
||||||
|
/// \param error_out \see errors.h
|
||||||
|
/// \return The default value of the property or null if an error occurs.
|
||||||
|
IKA_API struct IkarusValue * ikarus_property_get_default_value(IkarusProperty const * property, IkarusErrorData * error_out);
|
||||||
|
|
||||||
|
/// \brief Gets the source blueprint of a property.
|
||||||
/// \param property The property to get the source of.
|
/// \param property The property to get the source of.
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
/// \pre \li Must exist.
|
/// \pre \li Must exist.
|
||||||
/// \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.
|
IKA_API struct IkarusBlueprint * ikarus_property_get_blueprint(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.
|
|
||||||
/// \param property The property to get the type info of.
|
|
||||||
/// \pre \li Must not be null.
|
|
||||||
/// \pre \li Must exist.
|
|
||||||
/// \param error_out \see errors.h
|
|
||||||
/// \return The default value of the property or null if an error occurs.
|
|
||||||
/// \remark Must be freed using #ikarus_free.
|
|
||||||
IKA_API struct IkarusValue * ikarus_property_get_default_value(IkarusProperty const * property, IkarusErrorData * error_out);
|
|
||||||
|
|
||||||
/// \brief Visits a property. Calling the appropriate function for the property's type.
|
/// \brief Visits a property. Calling the appropriate function for the property's type.
|
||||||
/// \param property The property to visit.
|
/// \param property The property to visit.
|
||||||
|
|
@ -125,28 +139,6 @@ IKA_API void ikarus_property_visit(
|
||||||
IkarusErrorData * error_out
|
IkarusErrorData * error_out
|
||||||
);
|
);
|
||||||
|
|
||||||
/// \see ikarus_property_visit
|
|
||||||
IKA_API void ikarus_property_visit_const(
|
|
||||||
IkarusProperty const * property,
|
|
||||||
void (*toggle_property_visitor)(struct IkarusToggleProperty const *, void *),
|
|
||||||
void (*number_property_visitor)(struct IkarusNumberProperty const *, void *),
|
|
||||||
void (*text_property_visitor)(struct IkarusTextProperty const *, void *),
|
|
||||||
void * data,
|
|
||||||
IkarusErrorData * error_out
|
|
||||||
);
|
|
||||||
|
|
||||||
/// \brief Casts a property to an object.
|
|
||||||
/// \param property The property to cast.
|
|
||||||
/// \pre \li Must not be null.
|
|
||||||
/// \pre \li Must exist.
|
|
||||||
/// \param error_out \see errors.h
|
|
||||||
/// \return The property 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_property_to_object(IkarusProperty * property, IkarusErrorData * error_out);
|
|
||||||
|
|
||||||
/// \see ikarus_property_to_object
|
|
||||||
IKA_API struct IkarusObject const * ikarus_property_to_object_const(IkarusProperty const * property, IkarusErrorData * error_out);
|
|
||||||
|
|
||||||
IKARUS_END_HEADER
|
IKARUS_END_HEADER
|
||||||
|
|
||||||
// @}
|
// @}
|
||||||
|
|
|
||||||
|
|
@ -1,62 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
/// \file property_source.h
|
|
||||||
/// \author Folling <folling@ikarus.world>
|
|
||||||
|
|
||||||
#include <ikarus/errors.h>
|
|
||||||
#include <ikarus/macros.h>
|
|
||||||
|
|
||||||
/// \addtogroup properties Properties
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
IKARUS_BEGIN_HEADER
|
|
||||||
|
|
||||||
struct IkarusPropertyScope;
|
|
||||||
|
|
||||||
/// \brief Creates an blueprint property source.
|
|
||||||
/// \param blueprint The blueprint to create the property source for.
|
|
||||||
/// \pre \li Must not be null.
|
|
||||||
/// \pre \li Must exist.
|
|
||||||
/// \param error_out \see errors.h
|
|
||||||
/// \return The created property source or null if an error occurs.
|
|
||||||
/// \remark Must be freed using #ikarus_free.
|
|
||||||
IKA_API struct IkarusPropertyScope *
|
|
||||||
ikarus_property_source_create_blueprint(struct IkarusBlueprint * blueprint, IkarusErrorData * error_out);
|
|
||||||
|
|
||||||
/// \brief Creates an entity property source.
|
|
||||||
/// \param entity The entity to create the property source for.
|
|
||||||
/// \pre \li Must not be null.
|
|
||||||
/// \pre \li Must exist.
|
|
||||||
/// \param error_out \see errors.h
|
|
||||||
/// \return The created property source or null if an error occurs.
|
|
||||||
/// \remark Must be freed using #ikarus_free.
|
|
||||||
IKA_API struct IkarusPropertyScope * ikarus_property_source_create_entity(struct IkarusEntity * entity, IkarusErrorData * error_out);
|
|
||||||
|
|
||||||
/// \brief Visits a property source, calling the appropriate callback.
|
|
||||||
/// \param property_source The property source to visit.
|
|
||||||
/// \pre \li Must not be null.
|
|
||||||
/// \pre \li Must exist.
|
|
||||||
/// \param blueprint_visitor The callback to call if the source is a blueprint, skipped if null.
|
|
||||||
/// \param entity_visitor The callback to call if the source is an entity, skipped if null.
|
|
||||||
/// \param user_data User data to pass to the callbacks.
|
|
||||||
/// \param error_out \see errors.h
|
|
||||||
IKA_API void ikarus_property_source_visit(
|
|
||||||
struct IkarusPropertyScope * property_source,
|
|
||||||
void (*blueprint_visitor)(struct IkarusBlueprint *, void *),
|
|
||||||
void (*entity_visitor)(struct IkarusEntity *, void *),
|
|
||||||
void * user_data,
|
|
||||||
IkarusErrorData * error_out
|
|
||||||
);
|
|
||||||
|
|
||||||
/// \see ikarus_property_source_visit
|
|
||||||
IKA_API void ikarus_property_source_visit_const(
|
|
||||||
struct IkarusPropertyScope const * property_source,
|
|
||||||
void (*blueprint_visitor)(struct IkarusBlueprint const *, void *),
|
|
||||||
void (*entity_visitor)(struct IkarusEntity const *, void *),
|
|
||||||
void * user_data,
|
|
||||||
IkarusErrorData * error_out
|
|
||||||
);
|
|
||||||
|
|
||||||
IKARUS_END_HEADER
|
|
||||||
|
|
||||||
/// @}
|
|
||||||
|
|
@ -1,27 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
/// \file property_type.h
|
|
||||||
/// \author Folling <folling@ikarus.world>
|
|
||||||
|
|
||||||
#include <ikarus/macros.h>
|
|
||||||
|
|
||||||
/// \addtogroup properties Properties
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
IKARUS_BEGIN_HEADER
|
|
||||||
|
|
||||||
/// \brief The type of a property.
|
|
||||||
/// \details Designates the type of data stored by the property as well as which settings are
|
|
||||||
/// available.
|
|
||||||
enum IkarusPropertyType {
|
|
||||||
/// \brief A true/false boolean-esque value.
|
|
||||||
IkarusPropertyType_Toggle = 0x10000000,
|
|
||||||
/// \brief A numeric value, limited to IEEE 80 bit floating point numbers.
|
|
||||||
IkarusPropertyType_Number = 0x20000000,
|
|
||||||
/// \brief An arbitrary UTF-8 textual value.
|
|
||||||
IkarusPropertyType_Text = 0x30000000,
|
|
||||||
};
|
|
||||||
|
|
||||||
IKARUS_END_HEADER
|
|
||||||
|
|
||||||
/// @}
|
|
||||||
|
|
@ -20,7 +20,6 @@ struct IkarusTextProperty;
|
||||||
/// \pre \li Must exist.
|
/// \pre \li Must exist.
|
||||||
/// \param name The name of the property.
|
/// \param name The name of the property.
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
/// \pre \li Must not be empty.
|
|
||||||
/// \param property_source The property source to create the property for.
|
/// \param property_source The property source to create the property for.
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
/// \pre \li Must exist.
|
/// \pre \li Must exist.
|
||||||
|
|
@ -36,30 +35,6 @@ IKA_API IkarusTextProperty * ikarus_text_property_create(
|
||||||
IkarusErrorData * error_out
|
IkarusErrorData * error_out
|
||||||
);
|
);
|
||||||
|
|
||||||
/// \brief Sets the default value for a text property.
|
|
||||||
/// \param property The text property.
|
|
||||||
/// \pre \li Must not be null.
|
|
||||||
/// \pre \li Must exist.
|
|
||||||
/// \param error_out \see errors.h
|
|
||||||
/// \return The default value or null if an error occurs.
|
|
||||||
IKA_API struct IkarusTextValue * ikarus_text_property_get_default_value(struct IkarusTextProperty * property, IkarusErrorData * error_out);
|
|
||||||
|
|
||||||
/// \brief Sets the default value for a text property.
|
|
||||||
/// \param property The text property.
|
|
||||||
/// \pre \li Must not be null.
|
|
||||||
/// \pre \li Must exist.
|
|
||||||
/// \param new_default_value The default value.
|
|
||||||
/// \pre \li Must not be null.
|
|
||||||
/// \pre \li Must be a valid value for the property.
|
|
||||||
/// \param error_out \see errors.h
|
|
||||||
/// \remark Please see \ref property.h "the property documentation" for more information on the interplay between
|
|
||||||
/// default values and other settings.
|
|
||||||
IKA_API void ikarus_text_property_set_default_value(
|
|
||||||
struct IkarusTextProperty * property,
|
|
||||||
struct IkarusTextValue * new_default_value,
|
|
||||||
IkarusErrorData * error_out
|
|
||||||
);
|
|
||||||
|
|
||||||
IKARUS_END_HEADER
|
IKARUS_END_HEADER
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,11 @@
|
||||||
#include <ikarus/macros.h>
|
#include <ikarus/macros.h>
|
||||||
|
|
||||||
/// \addtogroup properties Properties
|
/// \addtogroup properties Properties
|
||||||
/// \brief Toggle properties store a value that can be either true or false. (e.g. "Is the character dead?")
|
|
||||||
/// @{
|
/// @{
|
||||||
|
|
||||||
IKARUS_BEGIN_HEADER
|
IKARUS_BEGIN_HEADER
|
||||||
|
|
||||||
|
/// \brief Toggle properties store a value that can be either true or false. (e.g. "Is the character dead?")
|
||||||
struct IkarusToggleProperty;
|
struct IkarusToggleProperty;
|
||||||
|
|
||||||
/// \brief Creates a toggle property.
|
/// \brief Creates a toggle property.
|
||||||
|
|
@ -20,44 +20,15 @@ struct IkarusToggleProperty;
|
||||||
/// \pre \li Must exist.
|
/// \pre \li Must exist.
|
||||||
/// \param name The name of the property.
|
/// \param name The name of the property.
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
/// \pre \li Must not be empty.
|
|
||||||
/// \param property_source The property source to create the property for.
|
/// \param property_source The property source to create the property for.
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
/// \pre \li Must exist.
|
/// \pre \li Must exist.
|
||||||
/// \param default_value The default value for the property.
|
|
||||||
/// \pre \li Must not be null.
|
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \return The created property or null if an error occurs.
|
/// \return The created property or null if an error occurs.
|
||||||
IKA_API IkarusToggleProperty * ikarus_toggle_property_create(
|
IKA_API IkarusToggleProperty * ikarus_toggle_property_create(
|
||||||
struct IkarusProject * project,
|
struct IkarusProject * project,
|
||||||
char const * name,
|
char const * name,
|
||||||
struct IkarusPropertySource * property_source,
|
struct IkarusPropertySource * property_source,
|
||||||
struct IkarusToggleValue * default_value,
|
|
||||||
IkarusErrorData * error_out
|
|
||||||
);
|
|
||||||
|
|
||||||
/// \brief Sets the default value for a toggle property.
|
|
||||||
/// \param property The toggle property.
|
|
||||||
/// \pre \li Must not be null.
|
|
||||||
/// \pre \li Must exist.
|
|
||||||
/// \param error_out \see errors.h
|
|
||||||
/// \return The default value or null if an error occurs.
|
|
||||||
IKA_API struct IkarusToggleValue *
|
|
||||||
ikarus_toggle_property_get_default_value(struct IkarusToggleProperty * property, IkarusErrorData * error_out);
|
|
||||||
|
|
||||||
/// \brief Sets the default value for a toggle property.
|
|
||||||
/// \param property The toggle property.
|
|
||||||
/// \pre \li Must not be null.
|
|
||||||
/// \pre \li Must exist.
|
|
||||||
/// \param new_default_value The default value.
|
|
||||||
/// \pre \li Must not be null.
|
|
||||||
/// \pre \li Must be a valid value for the property.
|
|
||||||
/// \param error_out \see errors.h
|
|
||||||
/// \remark Please see \ref property.h "the property documentation" for more information on the interplay between
|
|
||||||
/// default values and other settings.
|
|
||||||
IKA_API void ikarus_toggle_property_set_default_value(
|
|
||||||
struct IkarusToggleProperty * property,
|
|
||||||
struct IkarusToggleValue * new_default_value,
|
|
||||||
IkarusErrorData * error_out
|
IkarusErrorData * error_out
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,11 @@ struct IkarusProject;
|
||||||
/// \return The created project or null if an error occurs.
|
/// \return The created project or null if an error occurs.
|
||||||
/// \remark Must be freed using #ikarus_free. Freeing does not delete the project from the filesystem. For that, use
|
/// \remark Must be freed using #ikarus_free. Freeing does not delete the project from the filesystem. For that, use
|
||||||
/// ikarus_project_delete
|
/// ikarus_project_delete
|
||||||
IKA_API IkarusProject * ikarus_project_create(char const * path, char const * name, IkarusErrorData * error_out);
|
IKA_API IkarusProject * ikarus_project_create(
|
||||||
|
char const * path,
|
||||||
|
char const * name,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
);
|
||||||
|
|
||||||
/// \brief Creates a project in memory.
|
/// \brief Creates a project in memory.
|
||||||
/// \param name The name of the project. Must neither be null nor empty.
|
/// \param name The name of the project. Must neither be null nor empty.
|
||||||
|
|
@ -40,7 +44,8 @@ IKA_API IkarusProject * ikarus_project_create(char const * path, char const * na
|
||||||
/// \return The created project or null if an error occurs.
|
/// \return The created project or null if an error occurs.
|
||||||
/// \remark Must be freed using #ikarus_free. Freeing does not delete the project from the filesystem. For that, use
|
/// \remark Must be freed using #ikarus_free. Freeing does not delete the project from the filesystem. For that, use
|
||||||
/// ikarus_project_delete
|
/// ikarus_project_delete
|
||||||
IKA_API IkarusProject * ikarus_project_create_in_memory(char const * name, IkarusErrorData * error_out);
|
IKA_API IkarusProject *
|
||||||
|
ikarus_project_create_in_memory(char const * name, IkarusErrorData * error_out);
|
||||||
|
|
||||||
/// \brief Opens an existing project.
|
/// \brief Opens an existing project.
|
||||||
/// \param path The path to the project.
|
/// \param path The path to the project.
|
||||||
|
|
@ -50,7 +55,8 @@ IKA_API IkarusProject * ikarus_project_create_in_memory(char const * name, Ikaru
|
||||||
/// \return The opened project or null if an error occurs.
|
/// \return The opened project or null if an error occurs.
|
||||||
/// \remark Must be freed using ikarus_free. Freeing does not delete the project from the filesystem. For that, use
|
/// \remark Must be freed using ikarus_free. Freeing does not delete the project from the filesystem. For that, use
|
||||||
/// ikarus_project_delete
|
/// ikarus_project_delete
|
||||||
IKA_API IkarusProject * ikarus_project_open(char const * path, IkarusErrorData * error_out);
|
IKA_API IkarusProject *
|
||||||
|
ikarus_project_open(char const * path, IkarusErrorData * error_out);
|
||||||
|
|
||||||
/// \brief Gets the name of a project.
|
/// \brief Gets the name of a project.
|
||||||
/// \param project The project to get the name of.
|
/// \param project The project to get the name of.
|
||||||
|
|
@ -59,7 +65,10 @@ IKA_API IkarusProject * ikarus_project_open(char const * path, IkarusErrorData *
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \return The name of the project.
|
/// \return The name of the project.
|
||||||
/// \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_name(IkarusProject const * project, IkarusErrorData * error_out);
|
IKA_API char const * ikarus_project_get_name(
|
||||||
|
IkarusProject const * project,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
);
|
||||||
|
|
||||||
/// \brief Sets the name of a project.
|
/// \brief Sets the name of a project.
|
||||||
/// \param project The project to set the name of.
|
/// \param project The project to set the name of.
|
||||||
|
|
@ -69,7 +78,11 @@ IKA_API char const * ikarus_project_get_name(IkarusProject const * project, Ikar
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
/// \pre \li Must not be empty.
|
/// \pre \li Must not be empty.
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
IKA_API void ikarus_project_set_name(IkarusProject * project, char const * new_name, IkarusErrorData * error_out);
|
IKA_API void ikarus_project_set_name(
|
||||||
|
IkarusProject * project,
|
||||||
|
char const * new_name,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
);
|
||||||
|
|
||||||
/// \brief Gets the path of a project.
|
/// \brief Gets the path of a project.
|
||||||
/// \param project The project to get the path of.
|
/// \param project The project to get the path of.
|
||||||
|
|
@ -78,7 +91,10 @@ IKA_API void ikarus_project_set_name(IkarusProject * project, char const * new_n
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \return The path of the project.
|
/// \return The path of the project.
|
||||||
/// \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 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.
|
||||||
|
|
@ -101,7 +117,10 @@ IKA_API void ikarus_project_get_entities(
|
||||||
/// \pre \li Must exist.
|
/// \pre \li Must exist.
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \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 const * project, IkarusErrorData * error_out);
|
IKA_API size_t ikarus_project_get_entity_count(
|
||||||
|
IkarusProject const * project,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
);
|
||||||
|
|
||||||
/// \brief Gets the blueprints of a project.
|
/// \brief Gets the blueprints of a project.
|
||||||
/// \param project The project to get the blueprints of.
|
/// \param project The project to get the blueprints of.
|
||||||
|
|
@ -124,51 +143,11 @@ IKA_API void ikarus_project_get_blueprints(
|
||||||
/// \pre \li Must exist.
|
/// \pre \li Must exist.
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \return The number of blueprints or undefined if an error occurs.
|
/// \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);
|
IKA_API size_t ikarus_project_get_blueprint_count(
|
||||||
|
IkarusProject const * project,
|
||||||
/// \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 * ikarus_project_get_entity_by_name(IkarusProject * 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 * ikarus_project_get_property_by_name_and_scope(
|
|
||||||
IkarusProject * project,
|
|
||||||
struct IkarusPropertyScope * scope,
|
|
||||||
char const * name,
|
|
||||||
IkarusErrorData * error_out
|
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 *
|
|
||||||
ikarus_project_get_blueprint_by_name(IkarusProject * project, char const * name, IkarusErrorData * error_out);
|
|
||||||
|
|
||||||
IKARUS_END_HEADER
|
IKARUS_END_HEADER
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
|
|
||||||
|
|
@ -1,46 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
/// \file entity_property_value.h
|
|
||||||
/// \author Folling <folling@ikarus.world>
|
|
||||||
|
|
||||||
/// \defgroup entity_property_values EntityPropertyValue
|
|
||||||
/// \brief Values in relation to an entity and one of its properties.
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
#include <ikarus/errors.h>
|
|
||||||
#include <ikarus/macros.h>
|
|
||||||
#include <ikarus/values/entity_property_value.h>
|
|
||||||
|
|
||||||
IKARUS_BEGIN_HEADER
|
|
||||||
|
|
||||||
/// \brief Like an \ref value.h "IkarusValue", but in relation to an entity and one of its properties
|
|
||||||
struct IkarusEntityPropertyValue;
|
|
||||||
|
|
||||||
/// \brief Fetches the entity of an entity property value.
|
|
||||||
/// \param value The entity property value.
|
|
||||||
/// \pre \li Must not be null.
|
|
||||||
/// \param error_out \see errors.h
|
|
||||||
/// \return The entity of the entity property value.
|
|
||||||
/// \remark This value is owned by the entity property value and must not be freed directly.
|
|
||||||
struct IkarusEntity const * ikarus_entity_property_value_get_entity(IkarusEntityPropertyValue const * value, IkarusErrorData * error_out);
|
|
||||||
|
|
||||||
/// \brief Fetches the property of an entity property value.
|
|
||||||
/// \param value The entity property value.
|
|
||||||
/// \pre \li Must not be null.
|
|
||||||
/// \param error_out \see errors.h
|
|
||||||
/// \return The property of the entity property value.
|
|
||||||
/// \remark This value is owned by the entity property value and must not be freed directly.
|
|
||||||
struct IkarusProperty const *
|
|
||||||
ikarus_entity_property_value_get_property(IkarusEntityPropertyValue const * value, IkarusErrorData * error_out);
|
|
||||||
|
|
||||||
/// \brief Fetches the value of an entity property value.
|
|
||||||
/// \param value The entity property value.
|
|
||||||
/// \pre \li Must not be null.
|
|
||||||
/// \param error_out \see errors.h
|
|
||||||
/// \return The value of the entity property value.
|
|
||||||
/// \remark This value is owned by the entity property value and must not be freed directly.
|
|
||||||
struct IkarusValue const * ikarus_entity_property_value_get_value(IkarusEntityPropertyValue const * value, IkarusErrorData * error_out);
|
|
||||||
|
|
||||||
IKARUS_END_HEADER
|
|
||||||
|
|
||||||
/// @}
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
#include <ikarus/errors.h>
|
#include <ikarus/errors.h>
|
||||||
#include <ikarus/macros.h>
|
#include <ikarus/macros.h>
|
||||||
|
#include <ikarus/values/value_cardinality.h>
|
||||||
|
|
||||||
/// \addtogroup values Values
|
/// \addtogroup values Values
|
||||||
/// @{
|
/// @{
|
||||||
|
|
@ -15,10 +16,11 @@ IKARUS_BEGIN_HEADER
|
||||||
struct IkarusNumberValue;
|
struct IkarusNumberValue;
|
||||||
|
|
||||||
/// \brief Creates an empty number value.
|
/// \brief Creates an empty number value.
|
||||||
|
/// \details If the cardinality is "Single", the value will be initialized with 0.0.
|
||||||
|
/// \param cardinality The cardinality of the value.
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \return The value or null if an error occurs.
|
/// \return The value or null if an error occurs.
|
||||||
/// \remark Must be freed with #ikarus_free.
|
IKA_API IkarusNumberValue * ikarus_number_value_create(IkarusValueCardinality cardinality, IkarusErrorData * error_out);
|
||||||
IKA_API IkarusNumberValue * ikarus_number_value_create(IkarusErrorData * error_out);
|
|
||||||
|
|
||||||
/// \brief Fetches the underlying data of a number value at a specific index.
|
/// \brief Fetches the underlying data of a number value at a specific index.
|
||||||
/// \param value The number value.
|
/// \param value The number value.
|
||||||
|
|
@ -26,14 +28,14 @@ IKA_API IkarusNumberValue * ikarus_number_value_create(IkarusErrorData * error_o
|
||||||
/// \param idx The index of the data to fetch.
|
/// \param idx The index of the data to fetch.
|
||||||
/// \pre \li Must be less than the size of the value.
|
/// \pre \li Must be less than the size of the value.
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \return The underlying data or NaN if an error occurs or the value is undefined.
|
/// \return The underlying data or NaN if an error occurs.
|
||||||
IKA_API double ikarus_number_value_get(IkarusNumberValue const * value, size_t idx, IkarusErrorData * error_out);
|
IKA_API double ikarus_number_value_get(IkarusNumberValue const * value, size_t idx, IkarusErrorData * error_out);
|
||||||
|
|
||||||
/// \brief Fetches the size of the underlying data of a number value.
|
/// \brief Fetches the size of the underlying data of a number value.
|
||||||
/// \param value The number value.
|
/// \param value The number value.
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \return The size of the underlying data or 0 if an error occurs or the value is undefined.
|
/// \return The size of the underlying data or 0 if an error occurs.
|
||||||
IKA_API size_t ikarus_number_value_get_size(IkarusNumberValue const * value, IkarusErrorData * error_out);
|
IKA_API size_t ikarus_number_value_get_size(IkarusNumberValue const * value, IkarusErrorData * error_out);
|
||||||
|
|
||||||
/// \brief Sets the data of a number value at a specific index.
|
/// \brief Sets the data of a number value at a specific index.
|
||||||
|
|
@ -45,53 +47,37 @@ IKA_API size_t ikarus_number_value_get_size(IkarusNumberValue const * value, Ika
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
IKA_API void ikarus_number_value_set(IkarusNumberValue * value, size_t idx, double new_data, IkarusErrorData * error_out);
|
IKA_API void ikarus_number_value_set(IkarusNumberValue * value, size_t idx, double new_data, IkarusErrorData * error_out);
|
||||||
|
|
||||||
/// \brief Removes a data from a number value.
|
|
||||||
/// \param value The number value.
|
|
||||||
/// \pre \li Must not be null.
|
|
||||||
/// \param idx The index of the data to remove.
|
|
||||||
/// \pre \li Must be less than the size of the value.
|
|
||||||
/// \param error_out \see errors.h
|
|
||||||
IKA_API void ikarus_number_value_remove(IkarusNumberValue * value, size_t idx, IkarusErrorData * error_out);
|
|
||||||
|
|
||||||
/// \brief Inserts a data into a number value.
|
/// \brief Inserts a data into a number value.
|
||||||
/// \param value The number value.
|
/// \param value The number value.
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
|
/// \pre \li Cardinality must be "Multiple".
|
||||||
/// \param idx The index of the data to insert.
|
/// \param idx The index of the data to insert.
|
||||||
/// \pre \li Must be less than or equal to the size of the value.
|
/// \pre \li Must be less than or equal to the size of the value.
|
||||||
/// \param new_data The new data.
|
/// \param new_data The new data.
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
IKA_API void ikarus_number_value_insert(IkarusNumberValue * value, size_t idx, double new_data, IkarusErrorData * error_out);
|
IKA_API void ikarus_number_value_insert(IkarusNumberValue * value, size_t idx, double new_data, IkarusErrorData * error_out);
|
||||||
|
|
||||||
|
/// \brief Removes a data from a number value.
|
||||||
|
/// \param value The number value.
|
||||||
|
/// \pre \li Must not be null.
|
||||||
|
/// \pre \li Cardinality must be "Multiple".
|
||||||
|
/// \param idx The index of the data to remove.
|
||||||
|
/// \pre \li Must be less than the size of the value.
|
||||||
|
/// \param error_out \see errors.h
|
||||||
|
IKA_API void ikarus_number_value_remove(IkarusNumberValue * value, size_t idx, IkarusErrorData * error_out);
|
||||||
|
|
||||||
/// \brief Clears a number value.
|
/// \brief Clears a number value.
|
||||||
/// \param value The number value.
|
/// \param value The number value.
|
||||||
|
/// \pre \li Cardinality must be "Multiple".
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \remark Noop if the value is undefined.
|
|
||||||
IKA_API void ikarus_number_value_clear(IkarusNumberValue * value, IkarusErrorData * error_out);
|
IKA_API void ikarus_number_value_clear(IkarusNumberValue * value, IkarusErrorData * error_out);
|
||||||
|
|
||||||
/// \brief Checks if a number value is undefined.
|
|
||||||
/// \param value The number value.
|
|
||||||
/// \pre \li Must not be null.
|
|
||||||
/// \param error_out \see errors.h
|
|
||||||
/// \return True if the value is undefined, false otherwise.
|
|
||||||
IKA_API bool ikarus_number_value_is_undefined(IkarusNumberValue const * value, IkarusErrorData * error_out);
|
|
||||||
|
|
||||||
/// \brief Changes a number value's undefined state.
|
|
||||||
/// \param value The number value.
|
|
||||||
/// \pre \li Must not be null.
|
|
||||||
/// \param undefined The new undefined state.
|
|
||||||
/// \param error_out \see errors.h
|
|
||||||
/// \remark Noop if the value is already undefined.
|
|
||||||
/// \remark If the value is set to undefined, all data will be cleared.
|
|
||||||
/// \remark If the value is set to not undefined, the value is as if newly created.
|
|
||||||
IKA_API void ikarus_number_value_set_undefined(IkarusNumberValue * value, bool undefined, IkarusErrorData * error_out);
|
|
||||||
|
|
||||||
/// \brief Converts a number value to a string.
|
/// \brief Converts a number value to a string.
|
||||||
/// \param value The number value to convert.
|
/// \param value The number value to convert.
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \return The converted string.
|
/// \return The converted string.
|
||||||
/// \remark Must be freed with #ikarus_free.
|
/// \remark Must be freed with #ikarus_free.
|
||||||
/// \remark Undefined if the value is undefined.
|
|
||||||
IKA_API char const * ikarus_number_value_to_string(IkarusNumberValue const * value, IkarusErrorData * error_out);
|
IKA_API char const * ikarus_number_value_to_string(IkarusNumberValue const * value, IkarusErrorData * error_out);
|
||||||
|
|
||||||
/// \brief Checks if two values are equal.
|
/// \brief Checks if two values are equal.
|
||||||
|
|
@ -108,7 +94,6 @@ IKA_API bool ikarus_number_value_is_equal(IkarusNumberValue const * lhs, IkarusN
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \return The copied value.
|
/// \return The copied value.
|
||||||
/// \remark Must be freed with #ikarus_free.
|
|
||||||
IKA_API IkarusNumberValue * ikarus_number_value_copy(IkarusNumberValue const * value, IkarusErrorData * error_out);
|
IKA_API IkarusNumberValue * ikarus_number_value_copy(IkarusNumberValue const * value, IkarusErrorData * error_out);
|
||||||
|
|
||||||
/// \brief Converts a number value to an entity value.
|
/// \brief Converts a number value to an entity value.
|
||||||
|
|
@ -117,10 +102,7 @@ IKA_API IkarusNumberValue * ikarus_number_value_copy(IkarusNumberValue const * v
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \return The converted entity value.
|
/// \return The converted entity value.
|
||||||
/// \remark This is the same pointer, so freeing it implies freeing the original value.
|
/// \remark This is the same pointer, so freeing it implies freeing the original value.
|
||||||
IKA_API struct IkarusValue * ikarus_number_value_to_value(IkarusNumberValue * value, IkarusErrorData * error_out);
|
IKA_API struct IkarusValueData * ikarus_number_value_to_value(IkarusNumberValue * value, IkarusErrorData * error_out);
|
||||||
|
|
||||||
/// \see ikarus_toggle_value_to_value
|
|
||||||
IKA_API struct IkarusValue const * ikarus_number_value_to_value_const(IkarusNumberValue const * value, IkarusErrorData * error_out);
|
|
||||||
|
|
||||||
IKARUS_END_HEADER
|
IKARUS_END_HEADER
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,36 +5,37 @@
|
||||||
|
|
||||||
#include <ikarus/errors.h>
|
#include <ikarus/errors.h>
|
||||||
#include <ikarus/macros.h>
|
#include <ikarus/macros.h>
|
||||||
#include <ikarus/stdtypes.h>
|
#include <ikarus/values/value_cardinality.h>
|
||||||
|
|
||||||
/// \addtogroup values Values
|
/// \addtogroup values Values
|
||||||
/// @{
|
/// @{
|
||||||
|
|
||||||
IKARUS_BEGIN_HEADER
|
IKARUS_BEGIN_HEADER
|
||||||
|
|
||||||
/// \brief A textual value. For example "Surname" or "Description"
|
/// \brief A numeric value. For example "Age" or "Height".
|
||||||
struct IkarusTextValue;
|
struct IkarusTextValue;
|
||||||
|
|
||||||
/// \brief Creates an empty text value.
|
/// \brief Creates an empty text value.
|
||||||
|
/// \details If the cardinality is "Single", the value will be initialized with 0.0.
|
||||||
|
/// \param cardinality The cardinality of the value.
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \return The value or null if an error occurs.
|
/// \return The value or null if an error occurs.
|
||||||
/// \remark Must be freed with #ikarus_free.
|
IKA_API IkarusTextValue * ikarus_text_value_create(IkarusValueCardinality cardinality, IkarusErrorData * error_out);
|
||||||
IKA_API IkarusTextValue * ikarus_text_value_create(IkarusErrorData * error_out);
|
|
||||||
|
|
||||||
/// \brief Fetches the underlying data of a number value at a specific index.
|
/// \brief Fetches the underlying data of a text value at a specific index.
|
||||||
/// \param value The number value.
|
/// \param value The text value.
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
/// \param idx The index of the data to fetch.
|
/// \param idx The index of the data to fetch.
|
||||||
/// \pre \li Must be less than the size of the value.
|
/// \pre \li Must be less than the size of the value.
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \return The underlying data or null if an error occurs or the value is undefined.
|
/// \return The underlying data or NaN if an error occurs.
|
||||||
IKA_API char const * const * ikarus_text_value_get(IkarusTextValue const * value, size_t idx, IkarusErrorData * error_out);
|
IKA_API char const * ikarus_text_value_get(IkarusTextValue const * value, size_t idx, IkarusErrorData * error_out);
|
||||||
|
|
||||||
/// \brief Fetches the size of the underlying data of a text value.
|
/// \brief Fetches the size of the underlying data of a text value.
|
||||||
/// \param value The text value.
|
/// \param value The text value.
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \return The size of the underlying data or 0 if an error occurs or the value is undefined.
|
/// \return The size of the underlying data or 0 if an error occurs.
|
||||||
IKA_API size_t ikarus_text_value_get_size(IkarusTextValue const * value, IkarusErrorData * error_out);
|
IKA_API size_t ikarus_text_value_get_size(IkarusTextValue const * value, IkarusErrorData * error_out);
|
||||||
|
|
||||||
/// \brief Sets the data of a text value at a specific index.
|
/// \brief Sets the data of a text value at a specific index.
|
||||||
|
|
@ -42,59 +43,41 @@ IKA_API size_t ikarus_text_value_get_size(IkarusTextValue const * value, IkarusE
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
/// \param idx The index of the data to set.
|
/// \param idx The index of the data to set.
|
||||||
/// \pre \li Must be less than the size of the value.
|
/// \pre \li Must be less than the size of the value.
|
||||||
/// \param new_data The new data. Ownership remains with the caller.
|
/// \param new_data The new data.
|
||||||
/// \pre \li Must not be null.
|
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
IKA_API void ikarus_text_value_set(IkarusTextValue * value, size_t idx, char const * new_data, IkarusErrorData * error_out);
|
IKA_API void ikarus_text_value_set(IkarusTextValue * value, size_t idx, char const * new_data, IkarusErrorData * error_out);
|
||||||
|
|
||||||
|
/// \brief Inserts a data into a text value.
|
||||||
|
/// \param value The text value.
|
||||||
|
/// \pre \li Must not be null.
|
||||||
|
/// \pre \li Cardinality must be "Multiple".
|
||||||
|
/// \param idx The index of the data to insert.
|
||||||
|
/// \pre \li Must be less than or equal to the size of the value.
|
||||||
|
/// \param new_data The new data.
|
||||||
|
/// \param error_out \see errors.h
|
||||||
|
IKA_API void ikarus_text_value_insert(IkarusTextValue * value, size_t idx, char const * new_data, IkarusErrorData * error_out);
|
||||||
|
|
||||||
/// \brief Removes a data from a text value.
|
/// \brief Removes a data from a text value.
|
||||||
/// \param value The text value.
|
/// \param value The text value.
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
|
/// \pre \li Cardinality must be "Multiple".
|
||||||
/// \param idx The index of the data to remove.
|
/// \param idx The index of the data to remove.
|
||||||
/// \pre \li Must be less than the size of the value.
|
/// \pre \li Must be less than the size of the value.
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
IKA_API void ikarus_text_value_remove(IkarusTextValue * value, size_t idx, IkarusErrorData * error_out);
|
IKA_API void ikarus_text_value_remove(IkarusTextValue * value, size_t idx, IkarusErrorData * error_out);
|
||||||
|
|
||||||
/// \brief Inserts a data into a text value.
|
|
||||||
/// \param value The text value.
|
|
||||||
/// \pre \li Must not be null.
|
|
||||||
/// \param idx The index of the data to insert.
|
|
||||||
/// \pre \li Must be less than or equal to the size of the value.
|
|
||||||
/// \param new_data The new data. Ownership remains with the caller.
|
|
||||||
/// \pre \li Must not be null.
|
|
||||||
/// \param error_out \see errors.h
|
|
||||||
IKA_API void ikarus_text_value_insert(IkarusTextValue * value, size_t idx, char const * new_data, IkarusErrorData * error_out);
|
|
||||||
|
|
||||||
/// \brief Clears a text value.
|
/// \brief Clears a text value.
|
||||||
/// \param value The text value.
|
/// \param value The text value.
|
||||||
|
/// \pre \li Cardinality must be "Multiple".
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \remark Noop if the value is undefined.
|
|
||||||
IKA_API void ikarus_text_value_clear(IkarusTextValue * value, IkarusErrorData * error_out);
|
IKA_API void ikarus_text_value_clear(IkarusTextValue * value, IkarusErrorData * error_out);
|
||||||
|
|
||||||
/// \brief Checks if a text value is undefined.
|
|
||||||
/// \param value The text value.
|
|
||||||
/// \pre \li Must not be null.
|
|
||||||
/// \param error_out \see errors.h
|
|
||||||
/// \return True if the value is undefined, false otherwise.
|
|
||||||
IKA_API bool ikarus_text_value_is_undefined(IkarusTextValue const * value, IkarusErrorData * error_out);
|
|
||||||
|
|
||||||
/// \brief Changes a text value's undefined state.
|
|
||||||
/// \param value The text value.
|
|
||||||
/// \pre \li Must not be null.
|
|
||||||
/// \param undefined The new undefined state.
|
|
||||||
/// \param error_out \see errors.h
|
|
||||||
/// \remark Noop if the value is already undefined.
|
|
||||||
/// \remark If the value is set to undefined, all data will be cleared.
|
|
||||||
/// \remark If the value is set to not undefined, the value is as if newly created.
|
|
||||||
IKA_API void ikarus_text_value_set_undefined(IkarusTextValue * value, bool undefined, IkarusErrorData * error_out);
|
|
||||||
|
|
||||||
/// \brief Converts a text value to a string.
|
/// \brief Converts a text value to a string.
|
||||||
/// \param value The text value to convert.
|
/// \param value The text value to convert.
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \return The converted string.
|
/// \return The converted string.
|
||||||
/// \remark Must be freed with #ikarus_free.
|
/// \remark Must be freed with #ikarus_free.
|
||||||
/// \remark Undefined if the value is undefined.
|
|
||||||
IKA_API char const * ikarus_text_value_to_string(IkarusTextValue const * value, IkarusErrorData * error_out);
|
IKA_API char const * ikarus_text_value_to_string(IkarusTextValue const * value, IkarusErrorData * error_out);
|
||||||
|
|
||||||
/// \brief Checks if two values are equal.
|
/// \brief Checks if two values are equal.
|
||||||
|
|
@ -111,7 +94,6 @@ IKA_API bool ikarus_text_value_is_equal(IkarusTextValue const * lhs, IkarusTextV
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \return The copied value.
|
/// \return The copied value.
|
||||||
/// \remark Must be freed with #ikarus_free.
|
|
||||||
IKA_API IkarusTextValue * ikarus_text_value_copy(IkarusTextValue const * value, IkarusErrorData * error_out);
|
IKA_API IkarusTextValue * ikarus_text_value_copy(IkarusTextValue const * value, IkarusErrorData * error_out);
|
||||||
|
|
||||||
/// \brief Converts a text value to an entity value.
|
/// \brief Converts a text value to an entity value.
|
||||||
|
|
@ -120,10 +102,7 @@ IKA_API IkarusTextValue * ikarus_text_value_copy(IkarusTextValue const * value,
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \return The converted entity value.
|
/// \return The converted entity value.
|
||||||
/// \remark This is the same pointer, so freeing it implies freeing the original value.
|
/// \remark This is the same pointer, so freeing it implies freeing the original value.
|
||||||
IKA_API struct IkarusValue * ikarus_text_value_to_value(IkarusTextValue * value, IkarusErrorData * error_out);
|
IKA_API struct IkarusValueData * ikarus_text_value_to_value(IkarusTextValue * value, IkarusErrorData * error_out);
|
||||||
|
|
||||||
/// \see ikarus_text_value_to_value
|
|
||||||
IKA_API struct IkarusValue const * ikarus_text_value_to_value_const(IkarusTextValue const * value, IkarusErrorData * error_out);
|
|
||||||
|
|
||||||
IKARUS_END_HEADER
|
IKARUS_END_HEADER
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,36 +5,37 @@
|
||||||
|
|
||||||
#include <ikarus/errors.h>
|
#include <ikarus/errors.h>
|
||||||
#include <ikarus/macros.h>
|
#include <ikarus/macros.h>
|
||||||
#include <ikarus/stdtypes.h>
|
#include <ikarus/values/value_cardinality.h>
|
||||||
|
|
||||||
/// \addtogroup values Values
|
/// \addtogroup values Values
|
||||||
/// @{
|
/// @{
|
||||||
|
|
||||||
IKARUS_BEGIN_HEADER
|
IKARUS_BEGIN_HEADER
|
||||||
|
|
||||||
/// \brief A true/false boolean-esque value. For example "Is Dead".
|
/// \brief A numeric value. For example "Age" or "Height".
|
||||||
struct IkarusToggleValue;
|
struct IkarusToggleValue;
|
||||||
|
|
||||||
/// \brief Creates an empty toggle value.
|
/// \brief Creates an empty toggle value.
|
||||||
|
/// \details If the cardinality is "Single", the value will be initialized with 0.0.
|
||||||
|
/// \param cardinality The cardinality of the value.
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \return The value or null if an error occurs.
|
/// \return The value or null if an error occurs.
|
||||||
/// \remark Must be freed with #ikarus_free.
|
IKA_API IkarusToggleValue * ikarus_toggle_value_create(IkarusValueCardinality cardinality, IkarusErrorData * error_out);
|
||||||
IKA_API IkarusToggleValue * ikarus_toggle_value_create(IkarusErrorData * error_out);
|
|
||||||
|
|
||||||
/// \brief Fetches the underlying data of a number value at a specific index.
|
/// \brief Fetches the underlying data of a toggle value at a specific index.
|
||||||
/// \param value The number value.
|
/// \param value The toggle value.
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
/// \param idx The index of the data to fetch.
|
/// \param idx The index of the data to fetch.
|
||||||
/// \pre \li Must be less than the size of the value.
|
/// \pre \li Must be less than the size of the value.
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \return The underlying data or null if an error occurs or the value is undefined.
|
/// \return The underlying data or NaN if an error occurs.
|
||||||
IKA_API bool const * ikarus_toggle_value_get(IkarusToggleValue const * value, size_t idx, IkarusErrorData * error_out);
|
IKA_API bool ikarus_toggle_value_get(IkarusToggleValue const * value, size_t idx, IkarusErrorData * error_out);
|
||||||
|
|
||||||
/// \brief Fetches the size of the underlying data of a toggle value.
|
/// \brief Fetches the size of the underlying data of a toggle value.
|
||||||
/// \param value The toggle value.
|
/// \param value The toggle value.
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \return The size of the underlying data or 0 if an error occurs or the value is undefined.
|
/// \return The size of the underlying data or 0 if an error occurs.
|
||||||
IKA_API size_t ikarus_toggle_value_get_size(IkarusToggleValue const * value, IkarusErrorData * error_out);
|
IKA_API size_t ikarus_toggle_value_get_size(IkarusToggleValue const * value, IkarusErrorData * error_out);
|
||||||
|
|
||||||
/// \brief Sets the data of a toggle value at a specific index.
|
/// \brief Sets the data of a toggle value at a specific index.
|
||||||
|
|
@ -46,53 +47,37 @@ IKA_API size_t ikarus_toggle_value_get_size(IkarusToggleValue const * value, Ika
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
IKA_API void ikarus_toggle_value_set(IkarusToggleValue * value, size_t idx, bool new_data, IkarusErrorData * error_out);
|
IKA_API void ikarus_toggle_value_set(IkarusToggleValue * value, size_t idx, bool new_data, IkarusErrorData * error_out);
|
||||||
|
|
||||||
/// \brief Removes a data from a toggle value.
|
|
||||||
/// \param value The toggle value.
|
|
||||||
/// \pre \li Must not be null.
|
|
||||||
/// \param idx The index of the data to remove.
|
|
||||||
/// \pre \li Must be less than the size of the value.
|
|
||||||
/// \param error_out \see errors.h
|
|
||||||
IKA_API void ikarus_toggle_value_remove(IkarusToggleValue * value, size_t idx, IkarusErrorData * error_out);
|
|
||||||
|
|
||||||
/// \brief Inserts a data into a toggle value.
|
/// \brief Inserts a data into a toggle value.
|
||||||
/// \param value The toggle value.
|
/// \param value The toggle value.
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
|
/// \pre \li Cardinality must be "Multiple".
|
||||||
/// \param idx The index of the data to insert.
|
/// \param idx The index of the data to insert.
|
||||||
/// \pre \li Must be less than or equal to the size of the value.
|
/// \pre \li Must be less than or equal to the size of the value.
|
||||||
/// \param new_data The new data.
|
/// \param new_data The new data.
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
IKA_API void ikarus_toggle_value_insert(IkarusToggleValue * value, size_t idx, bool new_data, IkarusErrorData * error_out);
|
IKA_API void ikarus_toggle_value_insert(IkarusToggleValue * value, size_t idx, bool new_data, IkarusErrorData * error_out);
|
||||||
|
|
||||||
|
/// \brief Removes a data from a toggle value.
|
||||||
|
/// \param value The toggle value.
|
||||||
|
/// \pre \li Must not be null.
|
||||||
|
/// \pre \li Cardinality must be "Multiple".
|
||||||
|
/// \param idx The index of the data to remove.
|
||||||
|
/// \pre \li Must be less than the size of the value.
|
||||||
|
/// \param error_out \see errors.h
|
||||||
|
IKA_API void ikarus_toggle_value_remove(IkarusToggleValue * value, size_t idx, IkarusErrorData * error_out);
|
||||||
|
|
||||||
/// \brief Clears a toggle value.
|
/// \brief Clears a toggle value.
|
||||||
/// \param value The toggle value.
|
/// \param value The toggle value.
|
||||||
|
/// \pre \li Cardinality must be "Multiple".
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \remark Noop if the value is undefined.
|
|
||||||
IKA_API void ikarus_toggle_value_clear(IkarusToggleValue * value, IkarusErrorData * error_out);
|
IKA_API void ikarus_toggle_value_clear(IkarusToggleValue * value, IkarusErrorData * error_out);
|
||||||
|
|
||||||
/// \brief Checks if a toggle value is undefined.
|
|
||||||
/// \param value The toggle value.
|
|
||||||
/// \pre \li Must not be null.
|
|
||||||
/// \param error_out \see errors.h
|
|
||||||
/// \return True if the value is undefined, false otherwise.
|
|
||||||
IKA_API bool ikarus_toggle_value_is_undefined(IkarusToggleValue const * value, IkarusErrorData * error_out);
|
|
||||||
|
|
||||||
/// \brief Changes a toggle value's undefined state.
|
|
||||||
/// \param value The toggle value.
|
|
||||||
/// \pre \li Must not be null.
|
|
||||||
/// \param undefined The new undefined state.
|
|
||||||
/// \param error_out \see errors.h
|
|
||||||
/// \remark Noop if the value is already undefined.
|
|
||||||
/// \remark If the value is set to undefined, all data will be cleared.
|
|
||||||
/// \remark If the value is set to not undefined, the value is as if newly created.
|
|
||||||
IKA_API void ikarus_toggle_value_set_undefined(IkarusToggleValue * value, bool undefined, IkarusErrorData * error_out);
|
|
||||||
|
|
||||||
/// \brief Converts a toggle value to a string.
|
/// \brief Converts a toggle value to a string.
|
||||||
/// \param value The toggle value to convert.
|
/// \param value The toggle value to convert.
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \return The converted string.
|
/// \return The converted string.
|
||||||
/// \remark Must be freed with #ikarus_free.
|
/// \remark Must be freed with #ikarus_free.
|
||||||
/// \remark Undefined if the value is undefined.
|
|
||||||
IKA_API char const * ikarus_toggle_value_to_string(IkarusToggleValue const * value, IkarusErrorData * error_out);
|
IKA_API char const * ikarus_toggle_value_to_string(IkarusToggleValue const * value, IkarusErrorData * error_out);
|
||||||
|
|
||||||
/// \brief Checks if two values are equal.
|
/// \brief Checks if two values are equal.
|
||||||
|
|
@ -109,7 +94,6 @@ IKA_API bool ikarus_toggle_value_is_equal(IkarusToggleValue const * lhs, IkarusT
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \return The copied value.
|
/// \return The copied value.
|
||||||
/// \remark Must be freed with #ikarus_free.
|
|
||||||
IKA_API IkarusToggleValue * ikarus_toggle_value_copy(IkarusToggleValue const * value, IkarusErrorData * error_out);
|
IKA_API IkarusToggleValue * ikarus_toggle_value_copy(IkarusToggleValue const * value, IkarusErrorData * error_out);
|
||||||
|
|
||||||
/// \brief Converts a toggle value to an entity value.
|
/// \brief Converts a toggle value to an entity value.
|
||||||
|
|
@ -118,10 +102,7 @@ IKA_API IkarusToggleValue * ikarus_toggle_value_copy(IkarusToggleValue const * v
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
/// \return The converted entity value.
|
/// \return The converted entity value.
|
||||||
/// \remark This is the same pointer, so freeing it implies freeing the original value.
|
/// \remark This is the same pointer, so freeing it implies freeing the original value.
|
||||||
IKA_API struct IkarusValue * ikarus_toggle_value_to_value(IkarusToggleValue * value, IkarusErrorData * error_out);
|
IKA_API struct IkarusValueData * ikarus_toggle_value_to_value(IkarusToggleValue * value, IkarusErrorData * error_out);
|
||||||
|
|
||||||
/// \see ikarus_toggle_value_to_value
|
|
||||||
IKA_API struct IkarusValue const * ikarus_toggle_value_to_value_const(IkarusToggleValue const * value, IkarusErrorData * error_out);
|
|
||||||
|
|
||||||
IKARUS_END_HEADER
|
IKARUS_END_HEADER
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,14 +4,27 @@
|
||||||
/// \author Folling <folling@ikarus.world>
|
/// \author Folling <folling@ikarus.world>
|
||||||
|
|
||||||
/// \defgroup values Values
|
/// \defgroup values Values
|
||||||
/// \brief The values of properties.
|
/// \brief Values are data in entities.
|
||||||
/// \details Each entity has a value for each property it is associated with.
|
/// \details An entity is made up of any number of values.
|
||||||
/// These value classes represent plain objects. They are not associated with any entity.
|
/// Each value defines a certain aspect of an entity.
|
||||||
/// Each value may be undefined. \see IkarusProperty
|
/// Values have a name, a type, and some data.
|
||||||
/// Values are stored as lists. If a property is "singular" then its value is a list of size 1.
|
/// Examples of values would be:
|
||||||
/// Values are typed, with types existing for each of the corresponding property types. The data of values starts with the index 0.
|
/// - Is Dead (Toggle)
|
||||||
/// When setting values for a property the type must match the property type and the value must be valid under the
|
/// - Age (Number)
|
||||||
/// property's settings. \see PropertyType
|
/// - ISBN (Text)
|
||||||
|
///
|
||||||
|
/// Values are either single or multiple.
|
||||||
|
/// We call this property "Cardinality" (\see IkarusValueCardinality)
|
||||||
|
/// because it's really hard to find a simpler name.
|
||||||
|
/// Each piece of data within a value is called a "datapoint".
|
||||||
|
/// Single values have exactly one datapoint, multiple values have any number of
|
||||||
|
/// datapoints. For example "Age" would be singular, while "Nicknames" would be
|
||||||
|
/// multiple. The type is unaffected by this. A pendant in programming languages
|
||||||
|
/// would be a List<T>. Note that all values are stored as a list of items,
|
||||||
|
/// even if the value is singular. Single values effectively act as a list with
|
||||||
|
/// one element. This is enforced by the API at runtime.
|
||||||
|
///
|
||||||
|
/// For a comprehensive list of value types, see \ref IkarusValueType.
|
||||||
/// @{
|
/// @{
|
||||||
|
|
||||||
#include <ikarus/errors.h>
|
#include <ikarus/errors.h>
|
||||||
|
|
@ -19,15 +32,19 @@
|
||||||
|
|
||||||
IKARUS_BEGIN_HEADER
|
IKARUS_BEGIN_HEADER
|
||||||
|
|
||||||
/// \brief The common type for all values.
|
/// \brief The common type for all value data.
|
||||||
struct IkarusValue;
|
struct IkarusValue;
|
||||||
|
|
||||||
/// \brief Visits an entity value, calling the appropriate function for the value's type.
|
/// \brief Visits an entity value,
|
||||||
|
/// calling the appropriate function for the value's type.
|
||||||
/// \param value The entity value to visit.
|
/// \param value The entity value to visit.
|
||||||
/// \pre \li Must not be null.
|
/// \pre \li Must not be null.
|
||||||
/// \param toggle_visitor The function to call if the value is a toggle value. Skipped if null.
|
/// \param toggle_visitor The function to call if the value is a toggle value.
|
||||||
/// \param number_visitor The function to call if the value is a number value. Skipped if null.
|
/// \remark Skipped if null.
|
||||||
/// \param text_visitor The function to call if the value is a text value. Skipped if null.
|
/// \param number_visitor The function to call if the value is a number value.
|
||||||
|
/// \remark Skipped if null.
|
||||||
|
/// \param text_visitor The function to call if the value is a text value.
|
||||||
|
/// \remark Skipped if null.
|
||||||
/// \param data The data passed to the visitor functions.
|
/// \param data The data passed to the visitor functions.
|
||||||
/// \param error_out \see errors.h
|
/// \param error_out \see errors.h
|
||||||
IKA_API void ikarus_value_visit(
|
IKA_API void ikarus_value_visit(
|
||||||
|
|
@ -39,16 +56,6 @@ IKA_API void ikarus_value_visit(
|
||||||
IkarusErrorData * error_out
|
IkarusErrorData * error_out
|
||||||
);
|
);
|
||||||
|
|
||||||
/// \see ikarus_value_visit
|
|
||||||
IKA_API void ikarus_value_visit_const(
|
|
||||||
IkarusValue const * value,
|
|
||||||
void (*toggle_visitor)(struct IkarusToggleValue const *, void *),
|
|
||||||
void (*number_visitor)(struct IkarusNumberValue const *, void *),
|
|
||||||
void (*text_visitor)(struct IkarusTextValue const *, void *),
|
|
||||||
void * data,
|
|
||||||
IkarusErrorData * error_out
|
|
||||||
);
|
|
||||||
|
|
||||||
IKARUS_END_HEADER
|
IKARUS_END_HEADER
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
|
|
||||||
23
include/ikarus/values/value_cardinality.h
Normal file
23
include/ikarus/values/value_cardinality.h
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
/// \file value_cardinality.h
|
||||||
|
/// \author Folling <folling@ikarus.world>
|
||||||
|
|
||||||
|
/// \addtogroup values Values
|
||||||
|
/// @{
|
||||||
|
|
||||||
|
#include <ikarus/macros.h>
|
||||||
|
|
||||||
|
IKARUS_BEGIN_HEADER
|
||||||
|
|
||||||
|
/// \brief The cardinality of a value.
|
||||||
|
enum IkarusValueCardinality {
|
||||||
|
/// \brief Only contains one datapoint
|
||||||
|
IkarusValueCardinality_Single,
|
||||||
|
/// \brief Contains any number of datapoints
|
||||||
|
IkarusValueCardinality_List
|
||||||
|
};
|
||||||
|
|
||||||
|
IKARUS_END_HEADER
|
||||||
|
|
||||||
|
/// @}
|
||||||
198
include/ikarus/values/value_type.h
Normal file
198
include/ikarus/values/value_type.h
Normal file
|
|
@ -0,0 +1,198 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
/// \file value_schema.h
|
||||||
|
/// \author Folling <folling@ikarus.world>
|
||||||
|
|
||||||
|
/// \addtogroup values Values
|
||||||
|
/// @{
|
||||||
|
|
||||||
|
#include <ikarus/errors.h>
|
||||||
|
#include <ikarus/macros.h>
|
||||||
|
#include <ikarus/stdtypes.h>
|
||||||
|
|
||||||
|
IKARUS_BEGIN_HEADER
|
||||||
|
|
||||||
|
/// \brief Layouts define the structure and constraints of values.
|
||||||
|
/// \details Ikarus lets you define any schema for values and add constraints to them.
|
||||||
|
/// These schemas are assembled hierarchical and are akin to JSON schemas.
|
||||||
|
/// Layouts may be arbitrarily nested and combined e.g.:
|
||||||
|
/// Combination<List<Text>, Number, Complex<"Foo":Toggle,"Bar":Text>
|
||||||
|
struct IkarusValueLayout;
|
||||||
|
/// \brief A fixed datapoint with a fixed layout.
|
||||||
|
/// Example: Age: Union<Number, Constant<Text, "Dead">>
|
||||||
|
struct IkarusValueLayoutConstant;
|
||||||
|
/// \brief A singular datapoint with one of a list of layouts.
|
||||||
|
/// Example: ChestReward: Combination<Item, Gold, Mimic>
|
||||||
|
struct IkarusValueLayoutCombination;
|
||||||
|
/// \brief A collection of datapoints with a homogenous layout.
|
||||||
|
/// Example: Friends: List<Character>
|
||||||
|
struct IkarusValueLayoutList;
|
||||||
|
/// \brief A collection of nameable datapoints with heterogeneous layouts.
|
||||||
|
/// Example: GeoLocation: Complex<"Latitude":Number, "Longitude":Number>
|
||||||
|
struct IkarusValueLayoutComplex;
|
||||||
|
|
||||||
|
/// \brief Defines the type of datapoints.
|
||||||
|
enum IkarusValueDataType {
|
||||||
|
/// \brief Boolean datapoints
|
||||||
|
/// Example: Is the character alive? Yes
|
||||||
|
Toggle,
|
||||||
|
/// \brief Numeric datapoints
|
||||||
|
/// Example: How much does the character weigh? 57kg
|
||||||
|
Number,
|
||||||
|
/// \brief Textual datapoints
|
||||||
|
/// Example: What is the character's maiden name? Sandra
|
||||||
|
Text,
|
||||||
|
/// \brief A colour datapoint
|
||||||
|
/// Example: What colours make up the nation's flag? White/Pink/Blue.
|
||||||
|
/// \remark Not yet implemented
|
||||||
|
Colour,
|
||||||
|
/// \brief A date/time datapoint, interfacing with the calendar and timeline feature.
|
||||||
|
/// Example: When was the city founded? 12th of January 233 at 2:11
|
||||||
|
/// \remark Not yet implemented
|
||||||
|
Time,
|
||||||
|
/// \brief A location datapoint, interfacing with the map feature.
|
||||||
|
/// Example: Where is the city situated? 12.345, 67.890
|
||||||
|
/// \remark Not yet implemented
|
||||||
|
Location,
|
||||||
|
/// \brief An enum-esque datapoint
|
||||||
|
/// Example: Of which rarity is the weapon? Normal/Rare/Legendary
|
||||||
|
/// \remark Not yet implemented
|
||||||
|
Choice,
|
||||||
|
/// \brief A datapoint linking to some other object in Ikarus
|
||||||
|
/// Example: Who wrote this hymn? Peter Parker
|
||||||
|
/// \remark Not yet implemented
|
||||||
|
Reference
|
||||||
|
};
|
||||||
|
|
||||||
|
/// \brief Stores either a schema or a datatype
|
||||||
|
struct IkarusValueSchema;
|
||||||
|
|
||||||
|
/// \see ikarus_value_schema_from_layout_const
|
||||||
|
IkarusValueSchema * ikarus_value_schema_from_layout(
|
||||||
|
IkarusValueLayout * layout,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
);
|
||||||
|
|
||||||
|
/// \brief Creates a value schema from a layout.
|
||||||
|
/// \param layout The layout to create the schema from.
|
||||||
|
/// \pre \li Must not be null.
|
||||||
|
/// \param error_out \see errors.h
|
||||||
|
/// \return The created schema or null if an error occurs.
|
||||||
|
IkarusValueSchema const * ikarus_value_schema_from_layout_const(
|
||||||
|
IkarusValueLayout const * layout,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
);
|
||||||
|
|
||||||
|
/// \brief Creates a value schema from a datatype.
|
||||||
|
/// \param type The datatype to create the schema from.
|
||||||
|
/// \param error_out \see errors.h
|
||||||
|
/// \return The created schema or null if an error occurs.
|
||||||
|
IkarusValueSchema * ikarus_value_schema_from_data_type(
|
||||||
|
IkarusValueDataType type,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
);
|
||||||
|
|
||||||
|
/// \brief Frees a value schema.
|
||||||
|
/// \param schema The schema to free.
|
||||||
|
/// \pre \li Must not be null.
|
||||||
|
/// \remark Must not be accessed after freeing.
|
||||||
|
void ikarus_value_schema_free(IkarusValueSchema * schema);
|
||||||
|
|
||||||
|
/// \see ikarus_value_schema_visit_const
|
||||||
|
void ikarus_value_schema_visit(
|
||||||
|
IkarusValueSchema * schema,
|
||||||
|
void (*layout_visitor)(IkarusValueLayout * layout),
|
||||||
|
void (*data_type_visitor)(IkarusValueDataType type),
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
);
|
||||||
|
|
||||||
|
/// \brief Visits a value schema.
|
||||||
|
/// \param schema The schema to visit.
|
||||||
|
/// \pre \li Must not be null.
|
||||||
|
/// \param layout_visitor The function to call if the schema is a layout. Skipped if null.
|
||||||
|
/// \param data_type_visitor The function to call if the schema is a datatype. Skipped if null.
|
||||||
|
void ikarus_value_schema_visit_const(
|
||||||
|
IkarusValueSchema const * schema,
|
||||||
|
void (*layout_visitor)(IkarusValueLayout const * layout),
|
||||||
|
void (*data_type_visitor)(IkarusValueDataType type),
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
);
|
||||||
|
|
||||||
|
/// \brief Creates a constant layout.
|
||||||
|
/// \param schema The schema of the value.
|
||||||
|
/// \pre \li Must not be null.
|
||||||
|
/// \param value The value of the constant.
|
||||||
|
/// \pre \li Must not be null.
|
||||||
|
/// \param error_out \see errors.h
|
||||||
|
IkarusValueLayoutConstant * ikarus_value_layout_constant_create(
|
||||||
|
IkarusValueSchema * schema,
|
||||||
|
struct IkarusValue * value,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
);
|
||||||
|
|
||||||
|
/// \brief Gets the underyling schema of a constant layout.
|
||||||
|
/// \param layout The layout to get the underyling schema of.
|
||||||
|
/// \pre \li Must not be null.
|
||||||
|
/// \param error_out \see errors.h
|
||||||
|
/// \return The underlying schema of the layout or null if an error occurs.
|
||||||
|
IkarusValueSchema const * ikarus_value_layout_constant_get_underyling_schema(
|
||||||
|
IkarusValueLayoutConstant const * layout,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
);
|
||||||
|
|
||||||
|
/// \brief Gets the underyling value of a constant layout.
|
||||||
|
/// \param layout The layout to get the underyling value of.
|
||||||
|
/// \pre \li Must not be null.
|
||||||
|
/// \param error_out \see errors.h
|
||||||
|
/// \return The underlying value of the layout or null if an error occurs.
|
||||||
|
struct IkarusValue const * ikarus_value_layout_constant_get_underlying_value(
|
||||||
|
IkarusValueLayoutConstant const * layout,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
);
|
||||||
|
|
||||||
|
/// \brief Creates a combination layout.
|
||||||
|
/// \param schemas The schemas of the values.
|
||||||
|
/// \pre \li Must not be null.
|
||||||
|
/// \param schemas_size The number of schemas.
|
||||||
|
/// \param error_out \see errors.h
|
||||||
|
/// \return The created layout or null if an error occurs.
|
||||||
|
/// \remark The schemas are copied.
|
||||||
|
IkarusValueLayoutCombination * ikarus_value_layout_combination_create(
|
||||||
|
IkarusValueSchema * schemas,
|
||||||
|
size_t schemas_size,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
);
|
||||||
|
|
||||||
|
void ikarus_value_layout_combination_get_schemas(
|
||||||
|
IkarusValueLayoutCombination const * layout,
|
||||||
|
IkarusValueSchema ** schemas_out,
|
||||||
|
size_t * schemas_size_out,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
);
|
||||||
|
|
||||||
|
size_t ikarus_value_layout_combination_get_schemas_count(
|
||||||
|
IkarusValueLayoutCombination const * layout,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
);
|
||||||
|
|
||||||
|
IkarusValueLayoutList * ikarus_value_layout_list_create(
|
||||||
|
IkarusValueSchema * schema,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
);
|
||||||
|
|
||||||
|
IkarusValueLayoutComplex * ikarus_value_layout_complex_create(
|
||||||
|
IkarusValueSchema * schemas,
|
||||||
|
size_t schemas_size,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
);
|
||||||
|
|
||||||
|
IkarusValueLayoutComplex * ikarus_value_layout_complex_create_named(
|
||||||
|
IkarusValueSchema * schemas,
|
||||||
|
char const ** names,
|
||||||
|
size_t schemas_size,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
);
|
||||||
|
|
||||||
|
IKARUS_END_HEADER
|
||||||
|
|
||||||
|
/// @}
|
||||||
|
|
@ -1,13 +1,5 @@
|
||||||
#include "ikarus/errors.h"
|
#include "ikarus/errors.h"
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include <ranges>
|
|
||||||
|
|
||||||
#include <fmt/format.h>
|
|
||||||
|
|
||||||
#include <cppbase/functional.hpp>
|
|
||||||
|
|
||||||
char const * ikarus_get_error_info_name(IkarusErrorInfo info) {
|
char const * ikarus_get_error_info_name(IkarusErrorInfo info) {
|
||||||
switch (info) {
|
switch (info) {
|
||||||
case IkarusErrorInfo_None: return "None";
|
case IkarusErrorInfo_None: return "None";
|
||||||
|
|
|
||||||
|
|
@ -78,16 +78,3 @@ inline void safe_strcpy(char * dest, std::string_view src, size_t dest_size) {
|
||||||
|
|
||||||
#define IKARUS_VTRYRV_OR_FAIL(value, ret, msg, err_info, ...) \
|
#define IKARUS_VTRYRV_OR_FAIL(value, ret, msg, err_info, ...) \
|
||||||
IKARUS_VTRYRV_OR_FAIL_IMPL(CPPBASE_UNIQUE_NAME(result), value, ret, msg, err_info, __VA_ARGS__);
|
IKARUS_VTRYRV_OR_FAIL_IMPL(CPPBASE_UNIQUE_NAME(result), value, ret, msg, err_info, __VA_ARGS__);
|
||||||
|
|
||||||
#define IKARUS_FAIL_IF_OBJECT_MISSING_IMPL(var_name, obj, ret) \
|
|
||||||
IKARUS_VTRYRV_OR_FAIL( \
|
|
||||||
bool const var_name, \
|
|
||||||
ret, \
|
|
||||||
"unable to check whether object exists: {}", \
|
|
||||||
IkarusErrorInfo_Database_QueryFailed, \
|
|
||||||
(obj)->project->db->template query_one<bool>("SELECT EXISTS(SELECT 1 FROM `objects` WHERE `id` = ?)", (obj)->id) \
|
|
||||||
) \
|
|
||||||
\
|
|
||||||
IKARUS_FAIL_IF(!(var_name), ret, "object does not exist", IkarusErrorInfo_Client_Misuse);
|
|
||||||
|
|
||||||
#define IKARUS_FAIL_IF_OBJECT_MISSING(obj, ret) IKARUS_FAIL_IF_OBJECT_MISSING_IMPL(CPPBASE_UNIQUE_NAME(exists), obj, ret);
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
#include "ikarus/global.h"
|
|
||||||
|
|
||||||
#include <cstdlib>
|
|
||||||
|
|
||||||
void ikarus_free(void * ptr) {
|
|
||||||
std::free(ptr);
|
|
||||||
}
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
#include "ikarus/id.h"
|
|
||||||
|
|
||||||
#include <ikarus/objects/object_type.h>
|
|
||||||
|
|
||||||
uint64_t IKARUS_ID_OBJECT_TYPE_BITS = 8;
|
|
||||||
uint64_t IKARUS_ID_OBJECT_RANDOM_BITS = sizeof(IkarusId) * 8 - IKARUS_ID_OBJECT_TYPE_BITS;
|
|
||||||
|
|
||||||
IkarusId ikarus_id_from_data_and_type(int64_t data, IkarusObjectType type) {
|
|
||||||
return data | (static_cast<IkarusId>(type) << IKARUS_ID_OBJECT_RANDOM_BITS);
|
|
||||||
}
|
|
||||||
|
|
||||||
IkarusObjectType ikarus_id_get_object_type(IkarusId id) {
|
|
||||||
return static_cast<IkarusObjectType>(id >> IKARUS_ID_OBJECT_RANDOM_BITS);
|
|
||||||
}
|
|
||||||
|
|
@ -11,24 +11,27 @@
|
||||||
#include <ikarus/objects/properties/property.hpp>
|
#include <ikarus/objects/properties/property.hpp>
|
||||||
#include <ikarus/objects/util.hpp>
|
#include <ikarus/objects/util.hpp>
|
||||||
#include <ikarus/persistence/project.hpp>
|
#include <ikarus/persistence/project.hpp>
|
||||||
|
#include <ikarus/values/value_type.h>
|
||||||
|
|
||||||
IkarusBlueprint::IkarusBlueprint(IkarusProject * project, IkarusId id):
|
IkarusBlueprint::IkarusBlueprint(IkarusProject * project, int64_t id):
|
||||||
IkarusObject{project, id} {}
|
IkarusObject{project, id} {}
|
||||||
|
|
||||||
|
std::string_view IkarusBlueprint::get_table_name() const noexcept {
|
||||||
|
return "blueprints";
|
||||||
|
}
|
||||||
|
|
||||||
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_NAME_INVALID_OR_DUPLICATE(name, project, static_cast<IkarusEntity const *>(nullptr), nullptr);
|
IKARUS_FAIL_IF_NAME_INVALID(name, nullptr);
|
||||||
|
|
||||||
IKARUS_VTRYRV_OR_FAIL(
|
IKARUS_VTRYRV_OR_FAIL(
|
||||||
IkarusId const id,
|
int64_t const id,
|
||||||
nullptr,
|
nullptr,
|
||||||
"failed to create blueprint: {}",
|
"failed to create blueprint: {}",
|
||||||
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<int64_t, sqlitecpp::TransactionError> {
|
||||||
TRY(db->execute("INSERT INTO `objects`(`type`) VALUES(?)", IkarusObjectType_Blueprint));
|
TRY(db->execute("INSERT INTO `blueprints`(`name`) VALUES(?)", name));
|
||||||
auto id = ikarus_id_from_data_and_type(db->last_insert_rowid(), IkarusObjectType_Blueprint);
|
return cppbase::ok(db->last_insert_rowid());
|
||||||
TRY(db->execute("INSERT INTO `blueprints`(`id`, `name`) VALUES(?, ?)", id, name));
|
|
||||||
return cppbase::ok(id);
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -43,13 +46,13 @@ void ikarus_blueprint_delete(IkarusBlueprint * blueprint, IkarusErrorData * erro
|
||||||
,
|
,
|
||||||
"unable to delete blueprint: {}",
|
"unable to delete blueprint: {}",
|
||||||
IkarusErrorInfo_Database_QueryFailed,
|
IkarusErrorInfo_Database_QueryFailed,
|
||||||
blueprint->project->db->execute("DELETE FROM `objects` WHERE `id` = ?", blueprint->id)
|
blueprint->project->db->execute("DELETE FROM `blueprints` WHERE `id` = ?", blueprint->id)
|
||||||
);
|
);
|
||||||
|
|
||||||
blueprint->project->uncache(blueprint);
|
blueprint->project->uncache(blueprint);
|
||||||
}
|
}
|
||||||
|
|
||||||
IkarusId ikarus_blueprint_get_id(IkarusBlueprint const * blueprint, IkarusErrorData * error_out) {
|
int64_t ikarus_blueprint_get_id(IkarusBlueprint const * blueprint, IkarusErrorData * error_out) {
|
||||||
return ikarus::util::object_get_id(blueprint, error_out);
|
return ikarus::util::object_get_id(blueprint, error_out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -79,14 +82,14 @@ void ikarus_blueprint_get_properties(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::tuple<IkarusId, IkarusPropertyType> ids_and_types[properties_out_size];
|
std::tuple<int64_t, IkarusValueType> ids_and_types[properties_out_size];
|
||||||
|
|
||||||
IKARUS_TRYRV_OR_FAIL(
|
IKARUS_TRYRV_OR_FAIL(
|
||||||
,
|
,
|
||||||
"unable to fetch blueprint properties from database: {}",
|
"unable to fetch blueprint properties from database: {}",
|
||||||
IkarusErrorInfo_Database_QueryFailed,
|
IkarusErrorInfo_Database_QueryFailed,
|
||||||
blueprint->project->db->query_many_buffered<IkarusId, IkarusPropertyType>(
|
blueprint->project->db->query_many_buffered<int64_t, IkarusValueType>(
|
||||||
"SELECT `id` FROM `properties` WHERE `source` = ?",
|
"SELECT `id` FROM `properties` WHERE `blueprint` = ?",
|
||||||
ids_and_types,
|
ids_and_types,
|
||||||
properties_out_size,
|
properties_out_size,
|
||||||
blueprint->id
|
blueprint->id
|
||||||
|
|
@ -109,7 +112,7 @@ size_t ikarus_blueprint_get_property_count(IkarusBlueprint const * blueprint, Ik
|
||||||
0,
|
0,
|
||||||
"unable to fetch blueprint property count from database: {}",
|
"unable to fetch blueprint property count from database: {}",
|
||||||
IkarusErrorInfo_Database_QueryFailed,
|
IkarusErrorInfo_Database_QueryFailed,
|
||||||
blueprint->project->db->query_one<int64_t>("SELECT COUNT(*) FROM `properties` WHERE `source` = ?", blueprint->id)
|
blueprint->project->db->query_one<int64_t>("SELECT COUNT(*) FROM `properties` WHERE `blueprint` = ?", blueprint->id)
|
||||||
);
|
);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
@ -129,13 +132,13 @@ void ikarus_blueprint_get_linked_entities(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
IkarusId ids[entities_out_size];
|
int64_t ids[entities_out_size];
|
||||||
|
|
||||||
IKARUS_TRYRV_OR_FAIL(
|
IKARUS_TRYRV_OR_FAIL(
|
||||||
,
|
,
|
||||||
"unable to fetch blueprint linked entities from database: {}",
|
"unable to fetch blueprint linked entities from database: {}",
|
||||||
IkarusErrorInfo_Database_QueryFailed,
|
IkarusErrorInfo_Database_QueryFailed,
|
||||||
blueprint->project->db->query_many_buffered<IkarusId>(
|
blueprint->project->db->query_many_buffered<int64_t>(
|
||||||
"SELECT `entity` FROM `entity_blueprint_links` WHERE `blueprint` = ?",
|
"SELECT `entity` FROM `entity_blueprint_links` WHERE `blueprint` = ?",
|
||||||
ids,
|
ids,
|
||||||
entities_out_size,
|
entities_out_size,
|
||||||
|
|
@ -157,7 +160,8 @@ size_t ikarus_blueprint_get_linked_entity_count(IkarusBlueprint const * blueprin
|
||||||
0,
|
0,
|
||||||
"unable to fetch blueprint linked entity count from database: {}",
|
"unable to fetch blueprint linked entity count from database: {}",
|
||||||
IkarusErrorInfo_Database_QueryFailed,
|
IkarusErrorInfo_Database_QueryFailed,
|
||||||
blueprint->project->db->query_one<int64_t>("SELECT COUNT(*) FROM `entity_blueprint_links` WHERE `blueprint` = ?", blueprint->id)
|
blueprint->project->db
|
||||||
|
->query_one<int64_t>("SELECT COUNT(`entity`) FROM `entity_blueprint_links` WHERE `blueprint` = ?", blueprint->id)
|
||||||
);
|
);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,9 @@
|
||||||
|
|
||||||
#include <ikarus/objects/object.hpp>
|
#include <ikarus/objects/object.hpp>
|
||||||
|
|
||||||
struct IkarusBlueprint : IkarusObject {
|
struct IkarusBlueprint : public IkarusObject {
|
||||||
public:
|
public:
|
||||||
IkarusBlueprint(struct IkarusProject * project, IkarusId id);
|
IkarusBlueprint(struct IkarusProject * project, int64_t id);
|
||||||
|
|
||||||
IkarusBlueprint(IkarusBlueprint const &) = default;
|
IkarusBlueprint(IkarusBlueprint const &) = default;
|
||||||
IkarusBlueprint(IkarusBlueprint &&) = default;
|
IkarusBlueprint(IkarusBlueprint &&) = default;
|
||||||
|
|
@ -15,7 +15,5 @@ public:
|
||||||
~IkarusBlueprint() override = default;
|
~IkarusBlueprint() override = default;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline std::string_view get_table_name() const noexcept override {
|
std::string_view get_table_name() const noexcept override;
|
||||||
return "blueprints";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -10,22 +10,38 @@
|
||||||
#include <ikarus/persistence/project.hpp>
|
#include <ikarus/persistence/project.hpp>
|
||||||
#include <ikarus/values/entity_property_value.hpp>
|
#include <ikarus/values/entity_property_value.hpp>
|
||||||
#include <ikarus/values/value.hpp>
|
#include <ikarus/values/value.hpp>
|
||||||
|
#include <ikarus/values/value_type.h>
|
||||||
|
|
||||||
IkarusEntity * ikarus_entity_create(struct IkarusProject * project, char const * name, IkarusErrorData * error_out) {
|
IkarusEntity::IkarusEntity(IkarusProject * project, int64_t id):
|
||||||
|
IkarusObject{project, id} {}
|
||||||
|
|
||||||
|
std::string_view IkarusEntity::get_table_name() const noexcept {
|
||||||
|
return "entities";
|
||||||
|
}
|
||||||
|
|
||||||
|
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_NAME_INVALID_OR_DUPLICATE(name, project, static_cast<IkarusEntity const *>(nullptr), nullptr);
|
IKARUS_FAIL_IF_NAME_INVALID(name, nullptr);
|
||||||
|
|
||||||
IKARUS_VTRYRV_OR_FAIL(
|
IKARUS_VTRYRV_OR_FAIL(
|
||||||
IkarusId const id,
|
int64_t const id,
|
||||||
nullptr,
|
nullptr,
|
||||||
"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(
|
||||||
TRY(db->execute("INSERT INTO `objects`(`type`) VALUES(?)", IkarusObjectType_Entity));
|
[name](auto * db
|
||||||
auto id = ikarus_id_from_data_and_type(db->last_insert_rowid(), IkarusObjectType_Entity);
|
) -> cppbase::Result<int64_t, sqlitecpp::TransactionError> {
|
||||||
TRY(db->execute("INSERT INTO `entities`(`id`, `name`) VALUES(?, ?)", id, name));
|
TRY(db->execute(
|
||||||
return cppbase::ok(id);
|
"INSERT INTO `entities`(`name`) VALUES(?, ?)",
|
||||||
})
|
name
|
||||||
|
));
|
||||||
|
return cppbase::ok(db->last_insert_rowid());
|
||||||
|
}
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
return project->get_entity(id);
|
return project->get_entity(id);
|
||||||
|
|
@ -39,25 +55,37 @@ void ikarus_entity_delete(IkarusEntity * entity, IkarusErrorData * error_out) {
|
||||||
,
|
,
|
||||||
"unable to delete entity: {}",
|
"unable to delete entity: {}",
|
||||||
IkarusErrorInfo_Database_QueryFailed,
|
IkarusErrorInfo_Database_QueryFailed,
|
||||||
entity->project->db->execute("DELETE FROM `objects` WHERE `id` = ?", entity->id)
|
entity->project->db
|
||||||
|
->execute("DELETE FROM `entities` WHERE `id` = ?", entity->id)
|
||||||
);
|
);
|
||||||
|
|
||||||
entity->project->uncache(entity);
|
entity->project->uncache(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
IkarusId ikarus_entity_get_id(IkarusEntity const * entity, IkarusErrorData * error_out) {
|
int64_t
|
||||||
|
ikarus_entity_get_id(IkarusEntity const * entity, IkarusErrorData * error_out) {
|
||||||
return ikarus::util::object_get_id(entity, error_out);
|
return ikarus::util::object_get_id(entity, error_out);
|
||||||
}
|
}
|
||||||
|
|
||||||
IkarusProject * ikarus_entity_get_project(IkarusEntity const * entity, IkarusErrorData * error_out) {
|
IkarusProject * ikarus_entity_get_project(
|
||||||
|
IkarusEntity const * entity,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
) {
|
||||||
return ikarus::util::object_get_project(entity, error_out);
|
return ikarus::util::object_get_project(entity, error_out);
|
||||||
}
|
}
|
||||||
|
|
||||||
char const * ikarus_entity_get_name(IkarusEntity const * entity, IkarusErrorData * error_out) {
|
char const * ikarus_entity_get_name(
|
||||||
|
IkarusEntity const * entity,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
) {
|
||||||
return ikarus::util::object_get_name(entity, error_out);
|
return ikarus::util::object_get_name(entity, error_out);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ikarus_entity_set_name(IkarusEntity * entity, char const * name, IkarusErrorData * error_out) {
|
void ikarus_entity_set_name(
|
||||||
|
IkarusEntity * entity,
|
||||||
|
char const * name,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
) {
|
||||||
ikarus::util::object_set_name(entity, name, error_out);
|
ikarus::util::object_set_name(entity, name, error_out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -77,7 +105,9 @@ bool ikarus_entity_is_linked_to_blueprint(
|
||||||
"unable to check whether entity is linked to blueprint",
|
"unable to check whether entity is linked to blueprint",
|
||||||
IkarusErrorInfo_Database_QueryFailed,
|
IkarusErrorInfo_Database_QueryFailed,
|
||||||
entity->project->db->query_one<bool>(
|
entity->project->db->query_one<bool>(
|
||||||
"SELECT EXISTS(SELECT 1 FROM `entity_blueprint_links` WHERE `entity` = ? AND `blueprint` = ?)",
|
"SELECT EXISTS(SELECT 1 FROM `entity_blueprint_links` WHERE "
|
||||||
|
"`entity` = ? AND "
|
||||||
|
"`blueprint` = ?)",
|
||||||
entity->id,
|
entity->id,
|
||||||
blueprint->id
|
blueprint->id
|
||||||
)
|
)
|
||||||
|
|
@ -86,7 +116,11 @@ bool ikarus_entity_is_linked_to_blueprint(
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ikarus_entity_link_to_blueprint(IkarusEntity * entity, struct IkarusBlueprint * blueprint, IkarusErrorData * error_out) {
|
void ikarus_entity_link_to_blueprint(
|
||||||
|
IkarusEntity * entity,
|
||||||
|
struct IkarusBlueprint * blueprint,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
) {
|
||||||
IKARUS_FAIL_IF_NULL(entity, );
|
IKARUS_FAIL_IF_NULL(entity, );
|
||||||
IKARUS_FAIL_IF_OBJECT_MISSING(entity, );
|
IKARUS_FAIL_IF_OBJECT_MISSING(entity, );
|
||||||
IKARUS_FAIL_IF_NULL(blueprint, );
|
IKARUS_FAIL_IF_NULL(blueprint, );
|
||||||
|
|
@ -97,14 +131,20 @@ void ikarus_entity_link_to_blueprint(IkarusEntity * entity, struct IkarusBluepri
|
||||||
"unable to link entity to blueprint: {}",
|
"unable to link entity to blueprint: {}",
|
||||||
IkarusErrorInfo_Database_QueryFailed,
|
IkarusErrorInfo_Database_QueryFailed,
|
||||||
entity->project->db->execute(
|
entity->project->db->execute(
|
||||||
"INSERT INTO `entity_blueprint_links`(`entity`, `blueprint`) VALUES(?, ?) ON CONFLICT(`entity`, `blueprint`) DO NOTHING",
|
"INSERT INTO `entity_blueprint_links`(`entity`, `blueprint`) "
|
||||||
|
"VALUES(?, ?) ON "
|
||||||
|
"CONFLICT(`entity`, `blueprint`) DO NOTHING",
|
||||||
entity->id,
|
entity->id,
|
||||||
blueprint->id
|
blueprint->id
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ikarus_entity_unlink_from_blueprint(IkarusEntity * entity, struct IkarusBlueprint * blueprint, IkarusErrorData * error_out) {
|
void ikarus_entity_unlink_from_blueprint(
|
||||||
|
IkarusEntity * entity,
|
||||||
|
struct IkarusBlueprint * blueprint,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
) {
|
||||||
IKARUS_FAIL_IF_NULL(entity, );
|
IKARUS_FAIL_IF_NULL(entity, );
|
||||||
IKARUS_FAIL_IF_OBJECT_MISSING(entity, );
|
IKARUS_FAIL_IF_OBJECT_MISSING(entity, );
|
||||||
IKARUS_FAIL_IF_NULL(blueprint, );
|
IKARUS_FAIL_IF_NULL(blueprint, );
|
||||||
|
|
@ -114,9 +154,26 @@ void ikarus_entity_unlink_from_blueprint(IkarusEntity * entity, struct IkarusBlu
|
||||||
,
|
,
|
||||||
"unable to unlink entity from blueprint: {}",
|
"unable to unlink entity from blueprint: {}",
|
||||||
IkarusErrorInfo_Database_QueryFailed,
|
IkarusErrorInfo_Database_QueryFailed,
|
||||||
entity->project->db
|
entity->project->db->execute(
|
||||||
->execute("DELETE FROM `entity_blueprint_links` WHERE `entity` = ? AND `blueprint` = ?", entity->id, blueprint->id)
|
"DELETE FROM `entity_blueprint_links` WHERE `entity` = ? AND "
|
||||||
|
"`blueprint` = ?",
|
||||||
|
entity->id,
|
||||||
|
blueprint->id
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
IKARUS_TRYRV_OR_FAIL(
|
||||||
|
,
|
||||||
|
"unable to remove entity property values: {}",
|
||||||
|
IkarusErrorInfo_Database_QueryFailed,
|
||||||
|
entity->project->db->execute(
|
||||||
|
"DELETE FROM `entity_property_values` WHERE `entity` = ? AND "
|
||||||
|
"`property` IN (SELECT "
|
||||||
|
"`id` FROM `properties` WHERE `blueprint` = ?)",
|
||||||
|
entity->id,
|
||||||
|
blueprint->id
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
void ikarus_entity_get_linked_blueprints(
|
void ikarus_entity_get_linked_blueprints(
|
||||||
|
|
@ -133,14 +190,15 @@ void ikarus_entity_get_linked_blueprints(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
IkarusId ids[blueprints_out_size];
|
int64_t ids[blueprints_out_size];
|
||||||
|
|
||||||
IKARUS_TRYRV_OR_FAIL(
|
IKARUS_TRYRV_OR_FAIL(
|
||||||
,
|
,
|
||||||
"unable to fetch entity linked blueprints from database: {}",
|
"unable to fetch entity linked blueprints from database: {}",
|
||||||
IkarusErrorInfo_Database_QueryFailed,
|
IkarusErrorInfo_Database_QueryFailed,
|
||||||
entity->project->db->query_many_buffered<IkarusId>(
|
entity->project->db->query_many_buffered<int64_t>(
|
||||||
"SELECT `blueprint` FROM `entity_blueprint_links` WHERE `entity` = ?",
|
"SELECT `blueprint` FROM `entity_blueprint_links` WHERE `entity` = "
|
||||||
|
"?",
|
||||||
ids,
|
ids,
|
||||||
blueprints_out_size,
|
blueprints_out_size,
|
||||||
entity->id
|
entity->id
|
||||||
|
|
@ -152,7 +210,10 @@ void ikarus_entity_get_linked_blueprints(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ikarus_entity_get_linked_blueprint_count(IkarusEntity const * entity, IkarusErrorData * error_out) {
|
size_t ikarus_entity_get_linked_blueprint_count(
|
||||||
|
IkarusEntity const * entity,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
) {
|
||||||
IKARUS_FAIL_IF_NULL(entity, 0);
|
IKARUS_FAIL_IF_NULL(entity, 0);
|
||||||
IKARUS_FAIL_IF_OBJECT_MISSING(entity, 0);
|
IKARUS_FAIL_IF_OBJECT_MISSING(entity, 0);
|
||||||
|
|
||||||
|
|
@ -161,31 +222,144 @@ size_t ikarus_entity_get_linked_blueprint_count(IkarusEntity const * entity, Ika
|
||||||
0,
|
0,
|
||||||
"unable to fetch entity linked blueprint count from database: {}",
|
"unable to fetch entity linked blueprint count from database: {}",
|
||||||
IkarusErrorInfo_Database_QueryFailed,
|
IkarusErrorInfo_Database_QueryFailed,
|
||||||
entity->project->db->query_one<int64_t>("SELECT COUNT(*) FROM `entity_blueprint_links` WHERE `entity` = ?", entity->id)
|
entity->project->db->query_one<int64_t>(
|
||||||
|
"SELECT COUNT(`blueprint`) FROM `entity_blueprint_links` WHERE "
|
||||||
|
"`entity` = ?",
|
||||||
|
entity->id
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ikarus_entity_has_property(IkarusEntity const * entity, struct IkarusProperty const * property, IkarusErrorData * error_out) {
|
bool ikarus_entity_has_value(
|
||||||
|
IkarusEntity const * entity,
|
||||||
|
char const * name,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
) {
|
||||||
|
IKARUS_FAIL_IF_NULL(entity, false);
|
||||||
|
IKARUS_FAIL_IF_OBJECT_MISSING(entity, false);
|
||||||
|
IKARUS_FAIL_IF_NAME_INVALID(name, false);
|
||||||
|
|
||||||
|
IKARUS_VTRYRV_OR_FAIL(
|
||||||
|
auto const has_value,
|
||||||
|
false,
|
||||||
|
"unable to check whether entity has value: {}",
|
||||||
|
IkarusErrorInfo_Database_QueryFailed,
|
||||||
|
entity->project->db->query_one<bool>(
|
||||||
|
"SELECT EXISTS(SELECT 1 FROM `entity_values` WHERE `entity` = ? "
|
||||||
|
"AND `name` = ?)",
|
||||||
|
entity->id,
|
||||||
|
name
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return has_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct IkarusValue * ikarus_entity_get_value(
|
||||||
|
IkarusEntity const * entity,
|
||||||
|
char const * name,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
) {
|
||||||
|
IKARUS_FAIL_IF_NULL(entity, nullptr);
|
||||||
|
IKARUS_FAIL_IF_OBJECT_MISSING(entity, nullptr);
|
||||||
|
IKARUS_FAIL_IF_VALUE_MISSING(entity, name, nullptr);
|
||||||
|
IKARUS_FAIL_IF_NAME_INVALID(name, nullptr);
|
||||||
|
|
||||||
|
auto * value = fetch_value_from_db(
|
||||||
|
entity->project,
|
||||||
|
error_out,
|
||||||
|
"SELECT `value` FROM `entity_values` WHERE `entity` = ? AND `name` = ?",
|
||||||
|
entity->id,
|
||||||
|
name
|
||||||
|
);
|
||||||
|
|
||||||
|
IKARUS_FAIL_IF_ERROR(nullptr);
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ikarus_entity_set_value(
|
||||||
|
IkarusEntity * entity,
|
||||||
|
char const * name,
|
||||||
|
struct IkarusValue const * value,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
) {
|
||||||
|
IKARUS_FAIL_IF_NULL(entity, );
|
||||||
|
IKARUS_FAIL_IF_OBJECT_MISSING(entity, );
|
||||||
|
IKARUS_FAIL_IF_NAME_INVALID(name, );
|
||||||
|
IKARUS_FAIL_IF_NULL(value, );
|
||||||
|
|
||||||
|
IKARUS_TRYRV_OR_FAIL(
|
||||||
|
,
|
||||||
|
"unable to set entity value: {}",
|
||||||
|
IkarusErrorInfo_Database_QueryFailed,
|
||||||
|
entity->project->db->execute(
|
||||||
|
"INSERT INTO `entity_values`(`entity`, `name`, `value`) VALUES(?1, "
|
||||||
|
"?2, ?3) ON "
|
||||||
|
"CONFLICT(`entity`, `name`) DO UPDATE SET `value` = ?3",
|
||||||
|
entity->id,
|
||||||
|
name,
|
||||||
|
boost::json::serialize(value->to_json())
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ikarus_entity_delete_value(
|
||||||
|
IkarusEntity * entity,
|
||||||
|
char const * name,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
) {
|
||||||
|
IKARUS_FAIL_IF_NULL(entity, );
|
||||||
|
IKARUS_FAIL_IF_OBJECT_MISSING(entity, );
|
||||||
|
IKARUS_FAIL_IF_VALUE_MISSING(entity, name, );
|
||||||
|
IKARUS_FAIL_IF_NAME_INVALID(name, );
|
||||||
|
|
||||||
|
IKARUS_TRYRV_OR_FAIL(
|
||||||
|
,
|
||||||
|
"unable to delete entity value: {}",
|
||||||
|
IkarusErrorInfo_Database_QueryFailed,
|
||||||
|
entity->project->db->execute(
|
||||||
|
"DELETE FROM `entity_values` WHERE `entity` = ? AND `name` = ?",
|
||||||
|
entity->id,
|
||||||
|
name
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ikarus_entity_has_property(
|
||||||
|
IkarusEntity const * entity,
|
||||||
|
struct IkarusProperty const * property,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
) {
|
||||||
IKARUS_FAIL_IF_NULL(entity, false);
|
IKARUS_FAIL_IF_NULL(entity, false);
|
||||||
IKARUS_FAIL_IF_OBJECT_MISSING(entity, false);
|
IKARUS_FAIL_IF_OBJECT_MISSING(entity, false);
|
||||||
IKARUS_FAIL_IF_NULL(property, false);
|
IKARUS_FAIL_IF_NULL(property, false);
|
||||||
IKARUS_FAIL_IF_OBJECT_MISSING(property, false);
|
IKARUS_FAIL_IF_OBJECT_MISSING(property, false);
|
||||||
|
|
||||||
|
// given that values are loaded lazily we can't just check
|
||||||
|
// `entity_property_values` here
|
||||||
IKARUS_VTRYRV_OR_FAIL(
|
IKARUS_VTRYRV_OR_FAIL(
|
||||||
auto const ret,
|
auto const has_property,
|
||||||
false,
|
false,
|
||||||
"unable to check whether entity has property: {}",
|
"unable to check whether entity has property: {}",
|
||||||
IkarusErrorInfo_Database_QueryFailed,
|
IkarusErrorInfo_Database_QueryFailed,
|
||||||
entity->project->db->query_one<bool>(
|
entity->project->db->query_one<bool>(
|
||||||
"SELECT EXISTS(SELECT 1 FROM `entity_properties` WHERE `entity` = ? AND `property` = ?)",
|
"SELECT EXISTS(\n"
|
||||||
|
" SELECT 1\n"
|
||||||
|
" FROM `entity_blueprint_links`\n"
|
||||||
|
" JOIN `properties` ON `properties`.`blueprint` = "
|
||||||
|
"`entity_blueprint_links`.`blueprint`\n"
|
||||||
|
" WHERE `entity_blueprint_links`.`entity` = ? AND "
|
||||||
|
"`properties`.`id` = ?\n"
|
||||||
|
")",
|
||||||
entity->id,
|
entity->id,
|
||||||
property->id
|
property->id
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
return ret;
|
return has_property;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ikarus_entity_get_properties(
|
void ikarus_entity_get_properties(
|
||||||
|
|
@ -202,19 +376,25 @@ void ikarus_entity_get_properties(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::tuple<IkarusId, IkarusPropertyType> ids_and_types[properties_out_size];
|
std::tuple<int64_t, IkarusValueType> ids_and_types[properties_out_size];
|
||||||
|
|
||||||
|
// given that values are loaded lazily we can't just check
|
||||||
|
// `entity_property_values` here
|
||||||
IKARUS_TRYRV_OR_FAIL(
|
IKARUS_TRYRV_OR_FAIL(
|
||||||
,
|
,
|
||||||
"unable to fetch entity properties from database: {}",
|
"unable to fetch properties from entity: {}",
|
||||||
IkarusErrorInfo_Database_QueryFailed,
|
IkarusErrorInfo_Database_QueryFailed,
|
||||||
entity->project->db->query_many_buffered<IkarusId, IkarusPropertyType>(
|
entity->project->db->query_many_buffered<int64_t, IkarusValueType>(
|
||||||
"SELECT `property`, `type` FROM `properties` WHERE `source` = ?",
|
"SELECT `properties`.`id`, `properties`.`type`\n"
|
||||||
|
"FROM `entity_blueprint_links`\n"
|
||||||
|
"JOIN `properties` ON `properties`.`blueprint` = "
|
||||||
|
"`entity_blueprint_links`.`blueprint`\n"
|
||||||
|
"WHERE `entity_blueprint_links`.`entity` = ?\n",
|
||||||
ids_and_types,
|
ids_and_types,
|
||||||
properties_out_size,
|
properties_out_size,
|
||||||
entity->id
|
entity->id
|
||||||
)
|
)
|
||||||
)
|
);
|
||||||
|
|
||||||
for (size_t i = 0; i < properties_out_size; ++i) {
|
for (size_t i = 0; i < properties_out_size; ++i) {
|
||||||
auto [id, type] = ids_and_types[i];
|
auto [id, type] = ids_and_types[i];
|
||||||
|
|
@ -222,23 +402,39 @@ void ikarus_entity_get_properties(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ikarus_entity_get_property_count(IkarusEntity const * entity, IkarusErrorData * error_out) {
|
size_t ikarus_entity_get_property_count(
|
||||||
|
IkarusEntity const * entity,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
) {
|
||||||
IKARUS_FAIL_IF_NULL(entity, 0);
|
IKARUS_FAIL_IF_NULL(entity, 0);
|
||||||
IKARUS_FAIL_IF_OBJECT_MISSING(entity, 0);
|
IKARUS_FAIL_IF_OBJECT_MISSING(entity, 0);
|
||||||
|
|
||||||
|
// given that values are loaded lazily we can't just check
|
||||||
|
// `entity_property_values` here
|
||||||
IKARUS_VTRYRV_OR_FAIL(
|
IKARUS_VTRYRV_OR_FAIL(
|
||||||
size_t const ret,
|
size_t const count,
|
||||||
0,
|
0,
|
||||||
"unable to fetch entity property count from database: {}",
|
"unable to fetch property count from entity: {}",
|
||||||
IkarusErrorInfo_Database_QueryFailed,
|
IkarusErrorInfo_Database_QueryFailed,
|
||||||
entity->project->db->query_one<int64_t>("SELECT COUNT(*) FROM `properties` WHERE `source` = ?", entity->id)
|
entity->project->db->query_one<int64_t>(
|
||||||
|
"SELECT COUNT(`properties`.`id`)\n"
|
||||||
|
"FROM `entity_blueprint_links`\n"
|
||||||
|
"JOIN `properties` ON `properties`.`blueprint` = "
|
||||||
|
"`entity_blueprint_links`.`blueprint`\n"
|
||||||
|
"WHERE `entity_blueprint_links`.`entity` = ?\n"
|
||||||
|
")",
|
||||||
|
entity->id
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
return ret;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct IkarusEntityPropertyValue *
|
struct IkarusValue * ikarus_entity_get_property_value(
|
||||||
ikarus_entity_get_value(IkarusEntity const * entity, struct IkarusProperty const * property, IkarusErrorData * error_out) {
|
IkarusEntity const * entity,
|
||||||
|
struct IkarusProperty const * property,
|
||||||
|
IkarusErrorData * error_out
|
||||||
|
) {
|
||||||
IKARUS_FAIL_IF_NULL(entity, nullptr);
|
IKARUS_FAIL_IF_NULL(entity, nullptr);
|
||||||
IKARUS_FAIL_IF_OBJECT_MISSING(entity, nullptr);
|
IKARUS_FAIL_IF_OBJECT_MISSING(entity, nullptr);
|
||||||
IKARUS_FAIL_IF_NULL(property, nullptr);
|
IKARUS_FAIL_IF_NULL(property, nullptr);
|
||||||
|
|
@ -247,25 +443,27 @@ ikarus_entity_get_value(IkarusEntity const * entity, struct IkarusProperty const
|
||||||
auto * value = fetch_value_from_db(
|
auto * value = fetch_value_from_db(
|
||||||
entity->project,
|
entity->project,
|
||||||
error_out,
|
error_out,
|
||||||
"SELECT IFNULL((SELECT `value` FROM `values` WHERE `entity` = ? AND `property` = ?), (SELECT `default_value` FROM `properties` WHERE `id` = ?))",
|
"SELECT IFNULL(\n"
|
||||||
|
" (\n"
|
||||||
|
" SELECT `value`\n"
|
||||||
|
" FROM `entity_property_values`\n"
|
||||||
|
" WHERE `entity` = ?1 AND `property` = ?2\n"
|
||||||
|
" ),\n"
|
||||||
|
" (SELECT `default_value` FROM `properties` WHERE `id` = ?2)\n"
|
||||||
|
")",
|
||||||
entity->id,
|
entity->id,
|
||||||
property->id,
|
|
||||||
property->id
|
property->id
|
||||||
);
|
);
|
||||||
|
|
||||||
IKARUS_FAIL_IF_ERROR(nullptr);
|
IKARUS_FAIL_IF_ERROR(nullptr);
|
||||||
|
|
||||||
return new IkarusEntityPropertyValue{
|
return value;
|
||||||
.entity = entity,
|
|
||||||
.property = property,
|
|
||||||
.value = value,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ikarus_entity_set_value(
|
void ikarus_entity_set_property_value(
|
||||||
IkarusEntity * entity,
|
IkarusEntity * entity,
|
||||||
struct IkarusProperty const * property,
|
struct IkarusProperty const * property,
|
||||||
struct IkarusEntityPropertyValue * value,
|
struct IkarusValue * value,
|
||||||
IkarusErrorData * error_out
|
IkarusErrorData * error_out
|
||||||
) {
|
) {
|
||||||
IKARUS_FAIL_IF_NULL(entity, );
|
IKARUS_FAIL_IF_NULL(entity, );
|
||||||
|
|
@ -274,18 +472,17 @@ void ikarus_entity_set_value(
|
||||||
IKARUS_FAIL_IF_OBJECT_MISSING(property, );
|
IKARUS_FAIL_IF_OBJECT_MISSING(property, );
|
||||||
IKARUS_FAIL_IF_NULL(value, );
|
IKARUS_FAIL_IF_NULL(value, );
|
||||||
|
|
||||||
auto value_json_str = boost::json::serialize(value->value->to_json());
|
|
||||||
|
|
||||||
IKARUS_TRYRV_OR_FAIL(
|
IKARUS_TRYRV_OR_FAIL(
|
||||||
,
|
,
|
||||||
"unable to set entity property value: {}",
|
"unable to set entity property value: {}",
|
||||||
IkarusErrorInfo_Database_QueryFailed,
|
IkarusErrorInfo_Database_QueryFailed,
|
||||||
entity->project->db->execute(
|
entity->project->db->execute(
|
||||||
"INSERT INTO `values`(`entity`, `property`, `value`) VALUES(?, ?, ?) ON CONFLICT(`entity`, `property`) DO UPDATE SET `value` = ?",
|
"INSERT INTO `entity_property_values`(`entity`, `property`, "
|
||||||
|
"`value`) VALUES(?1, ?2, "
|
||||||
|
"?3) ON CONFLICT(`entity`, `property`) DO UPDATE SET `value` = ?3",
|
||||||
entity->id,
|
entity->id,
|
||||||
property->id,
|
property->id,
|
||||||
value_json_str,
|
boost::json::serialize(value->to_json())
|
||||||
value_json_str
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,9 @@
|
||||||
|
|
||||||
#include <ikarus/objects/object.hpp>
|
#include <ikarus/objects/object.hpp>
|
||||||
|
|
||||||
struct IkarusEntity : IkarusObject {
|
struct IkarusEntity : public IkarusObject {
|
||||||
public:
|
public:
|
||||||
inline IkarusEntity(struct IkarusProject * project, IkarusId id):
|
inline IkarusEntity(struct IkarusProject * project, int64_t id);
|
||||||
IkarusObject{project, id} {}
|
|
||||||
|
|
||||||
IkarusEntity(IkarusEntity const &) = default;
|
IkarusEntity(IkarusEntity const &) = default;
|
||||||
IkarusEntity(IkarusEntity &&) = default;
|
IkarusEntity(IkarusEntity &&) = default;
|
||||||
|
|
@ -16,7 +15,5 @@ public:
|
||||||
~IkarusEntity() override = default;
|
~IkarusEntity() override = default;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline std::string_view get_table_name() const noexcept override {
|
std::string_view get_table_name() const noexcept override;
|
||||||
return "entities";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,93 +1,7 @@
|
||||||
#include "object.hpp"
|
#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>
|
#include <ikarus/persistence/project.hpp>
|
||||||
|
|
||||||
IkarusObject::IkarusObject(IkarusProject * project, IkarusId id):
|
IkarusObject::IkarusObject(IkarusProject * project, int64_t id):
|
||||||
project{project},
|
project{project},
|
||||||
id{id} {}
|
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()
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,9 @@
|
||||||
|
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
|
||||||
#include <ikarus/id.h>
|
class IkarusObject {
|
||||||
|
|
||||||
struct IkarusObject {
|
|
||||||
public:
|
public:
|
||||||
IkarusObject(struct IkarusProject * project, IkarusId id);
|
IkarusObject(struct IkarusProject * project, int64_t id);
|
||||||
|
|
||||||
IkarusObject(IkarusObject const &) = default;
|
IkarusObject(IkarusObject const &) = default;
|
||||||
IkarusObject(IkarusObject &&) = default;
|
IkarusObject(IkarusObject &&) = default;
|
||||||
|
|
@ -21,5 +19,18 @@ public:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
struct IkarusProject * project;
|
struct IkarusProject * project;
|
||||||
IkarusId id;
|
int64_t id;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define IKARUS_FAIL_IF_OBJECT_MISSING_IMPL(var_name, obj, ret) \
|
||||||
|
IKARUS_VTRYRV_OR_FAIL( \
|
||||||
|
bool const var_name, \
|
||||||
|
ret, \
|
||||||
|
"unable to check whether object exists: {}", \
|
||||||
|
IkarusErrorInfo_Database_QueryFailed, \
|
||||||
|
(obj)->project->db->template query_one<bool>("SELECT EXISTS(SELECT 1 FROM `objects` WHERE `id` = ?)", (obj)->id) \
|
||||||
|
) \
|
||||||
|
\
|
||||||
|
IKARUS_FAIL_IF(!(var_name), ret, "object does not exist", IkarusErrorInfo_Client_Misuse);
|
||||||
|
|
||||||
|
#define IKARUS_FAIL_IF_OBJECT_MISSING(obj, ret) IKARUS_FAIL_IF_OBJECT_MISSING_IMPL(CPPBASE_UNIQUE_NAME(exists), obj, ret);
|
||||||
|
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
#include "ikarus/objects/object_type.h"
|
|
||||||
|
|
||||||
char const * ikarus_object_type_to_string(IkarusObjectType type) {
|
|
||||||
switch (type) {
|
|
||||||
case IkarusObjectType_None: return "none";
|
|
||||||
case IkarusObjectType_Entity: return "entity";
|
|
||||||
case IkarusObjectType_Blueprint: return "blueprint";
|
|
||||||
case IkarusObjectType_Property: return "property";
|
|
||||||
}
|
|
||||||
|
|
||||||
return "unknown";
|
|
||||||
}
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
#include <ikarus/objects/properties/util.hpp>
|
#include <ikarus/objects/properties/util.hpp>
|
||||||
#include <ikarus/values/value.hpp>
|
#include <ikarus/values/value.hpp>
|
||||||
|
|
||||||
IkarusNumberProperty::IkarusNumberProperty(IkarusProject * project, IkarusId id):
|
IkarusNumberProperty::IkarusNumberProperty(IkarusProject * project, int64_t id):
|
||||||
IkarusProperty{project, id, this} {}
|
IkarusProperty{project, id, this} {}
|
||||||
|
|
||||||
IkarusNumberProperty * ikarus_number_property_create(
|
IkarusNumberProperty * ikarus_number_property_create(
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <ikarus/objects/properties/property.hpp>
|
#include <ikarus/objects/properties/property.hpp>
|
||||||
#include <ikarus/objects/properties/property_type.h>
|
|
||||||
#include <ikarus/values/number_value.hpp>
|
#include <ikarus/values/number_value.hpp>
|
||||||
|
#include <ikarus/values/value_type.h>
|
||||||
|
|
||||||
struct IkarusNumberProperty : IkarusProperty {
|
struct IkarusNumberProperty : public IkarusProperty {
|
||||||
public:
|
public:
|
||||||
using value_type = IkarusNumberValue;
|
using value_type = IkarusNumberValue;
|
||||||
constexpr auto static PropertyType = IkarusPropertyType_Number;
|
constexpr auto static PropertyType = IkarusValueType_Number;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
IkarusNumberProperty(struct IkarusProject * project, IkarusId id);
|
IkarusNumberProperty(struct IkarusProject * project, int64_t id);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,12 @@
|
||||||
#include <ikarus/errors.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_scope.hpp>
|
||||||
#include <ikarus/objects/properties/property_type.h>
|
#include <ikarus/values/value_type.h>
|
||||||
#include <ikarus/objects/util.hpp>
|
#include <ikarus/objects/util.hpp>
|
||||||
#include <ikarus/persistence/project.hpp>
|
#include <ikarus/persistence/project.hpp>
|
||||||
#include <ikarus/values/value.hpp>
|
#include <ikarus/values/value.hpp>
|
||||||
|
|
||||||
IkarusProperty::IkarusProperty(IkarusProject * project, IkarusId id, Data data):
|
IkarusProperty::IkarusProperty(IkarusProject * project, int64_t id, Data data):
|
||||||
IkarusObject{project, id},
|
IkarusObject{project, id},
|
||||||
data{data} {}
|
data{data} {}
|
||||||
|
|
||||||
|
|
@ -28,7 +28,7 @@ IKA_API void ikarus_property_delete(IkarusProperty * property, IkarusErrorData *
|
||||||
property->project->uncache(property);
|
property->project->uncache(property);
|
||||||
}
|
}
|
||||||
|
|
||||||
IkarusId ikarus_property_get_id(IkarusProperty const * property, IkarusErrorData * error_out) {
|
int64_t ikarus_property_get_id(IkarusProperty const * property, IkarusErrorData * error_out) {
|
||||||
return ikarus::util::object_get_id(property, error_out);
|
return ikarus::util::object_get_id(property, error_out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -44,19 +44,19 @@ void ikarus_property_set_name(IkarusProperty * property, char const * name, Ikar
|
||||||
ikarus::util::object_set_name(property, name, error_out);
|
ikarus::util::object_set_name(property, name, error_out);
|
||||||
}
|
}
|
||||||
|
|
||||||
IkarusPropertyType ikarus_property_get_type(IkarusProperty const * property, IkarusErrorData * error_out) {
|
IkarusValueType ikarus_property_get_type(IkarusProperty const * property, IkarusErrorData * error_out) {
|
||||||
IKARUS_FAIL_IF_NULL(property, IkarusPropertyType_Toggle);
|
IKARUS_FAIL_IF_NULL(property, IkarusValueType_Toggle);
|
||||||
IKARUS_FAIL_IF_OBJECT_MISSING(property, IkarusPropertyType_Toggle);
|
IKARUS_FAIL_IF_OBJECT_MISSING(property, IkarusValueType_Toggle);
|
||||||
|
|
||||||
IKARUS_VTRYRV_OR_FAIL(
|
IKARUS_VTRYRV_OR_FAIL(
|
||||||
auto const ret,
|
auto const ret,
|
||||||
IkarusPropertyType_Toggle,
|
IkarusValueType_Toggle,
|
||||||
"unable to fetch property type from database: {}",
|
"unable to fetch property type from database: {}",
|
||||||
IkarusErrorInfo_Database_QueryFailed,
|
IkarusErrorInfo_Database_QueryFailed,
|
||||||
property->project->db->query_one<int>("SELECT `type` FROM `properties` WHERE `id` = ?", property->id)
|
property->project->db->query_one<int>("SELECT `type` FROM `properties` WHERE `id` = ?", property->id)
|
||||||
);
|
);
|
||||||
|
|
||||||
return static_cast<IkarusPropertyType>(ret);
|
return static_cast<IkarusValueType>(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
IkarusPropertyScope const * ikarus_property_get_scope(IkarusProperty const * property, IkarusErrorData * error_out) {
|
IkarusPropertyScope const * ikarus_property_get_scope(IkarusProperty const * property, IkarusErrorData * error_out) {
|
||||||
|
|
@ -68,7 +68,7 @@ IkarusPropertyScope const * ikarus_property_get_scope(IkarusProperty const * pro
|
||||||
nullptr,
|
nullptr,
|
||||||
"unable to fetch property source from database: {}",
|
"unable to fetch property source from database: {}",
|
||||||
IkarusErrorInfo_Database_QueryFailed,
|
IkarusErrorInfo_Database_QueryFailed,
|
||||||
property->project->db->query_one<IkarusId>("SELECT `source` FROM `properties` WHERE `id` = ?", property->id)
|
property->project->db->query_one<int64_t>("SELECT `source` FROM `properties` WHERE `id` = ?", property->id)
|
||||||
);
|
);
|
||||||
|
|
||||||
switch (ikarus_id_get_object_type(source)) {
|
switch (ikarus_id_get_object_type(source)) {
|
||||||
|
|
@ -83,7 +83,7 @@ IkarusPropertyScope const * ikarus_property_get_scope(IkarusProperty const * pro
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IkarusValue * ikarus_property_get_default_value(IkarusProperty const * property, IkarusErrorData * error_out) {
|
IkarusValueData * ikarus_property_get_default_value(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);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,12 @@
|
||||||
|
|
||||||
#include <ikarus/objects/object.hpp>
|
#include <ikarus/objects/object.hpp>
|
||||||
|
|
||||||
struct IkarusProperty : IkarusObject {
|
struct IkarusProperty : public IkarusObject {
|
||||||
public:
|
public:
|
||||||
using Data = std::variant<struct IkarusToggleProperty *, struct IkarusNumberProperty *, struct IkarusTextProperty *>;
|
using Data = std::variant<struct IkarusToggleProperty *, struct IkarusNumberProperty *, struct IkarusTextProperty *>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
IkarusProperty(struct IkarusProject * project, IkarusId id, Data data);
|
IkarusProperty(struct IkarusProject * project, int64_t id, Data data);
|
||||||
|
|
||||||
IkarusProperty(IkarusProperty const &) = default;
|
IkarusProperty(IkarusProperty const &) = default;
|
||||||
IkarusProperty(IkarusProperty &&) = default;
|
IkarusProperty(IkarusProperty &&) = default;
|
||||||
|
|
|
||||||
|
|
@ -1,57 +0,0 @@
|
||||||
#include "property_scope.hpp"
|
|
||||||
|
|
||||||
#include <cppbase/templates.hpp>
|
|
||||||
|
|
||||||
#include <ikarus/objects/blueprint.hpp>
|
|
||||||
#include <ikarus/objects/entity.hpp>
|
|
||||||
|
|
||||||
IkarusPropertyScope::IkarusPropertyScope(Data data):
|
|
||||||
data{data} {}
|
|
||||||
|
|
||||||
IkarusId IkarusPropertyScope::get_id() const {
|
|
||||||
return std::visit(
|
|
||||||
cppbase::overloaded{
|
|
||||||
[](IkarusBlueprint const * blueprint) { return blueprint->id; },
|
|
||||||
[](IkarusEntity const * entity) { return entity->id; }
|
|
||||||
},
|
|
||||||
data
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
IkarusPropertyScope * ikarus_property_source_create_blueprint(IkarusBlueprint * blueprint) {
|
|
||||||
return new IkarusPropertyScope{blueprint};
|
|
||||||
}
|
|
||||||
|
|
||||||
IkarusPropertyScope * ikarus_property_source_create_entity(IkarusEntity * entity) {
|
|
||||||
return new IkarusPropertyScope{entity};
|
|
||||||
}
|
|
||||||
|
|
||||||
void ikarus_property_source_visit(
|
|
||||||
struct IkarusPropertyScope * property_source,
|
|
||||||
void (*blueprint_visitor)(struct IkarusBlueprint *, void *),
|
|
||||||
void (*entity_visitor)(struct IkarusEntity *, void *),
|
|
||||||
void * user_data
|
|
||||||
) {
|
|
||||||
std::visit(
|
|
||||||
cppbase::overloaded{
|
|
||||||
[blueprint_visitor, user_data](IkarusBlueprint * blueprint) { blueprint_visitor(blueprint, user_data); },
|
|
||||||
[entity_visitor, user_data](IkarusEntity * entity) { entity_visitor(entity, user_data); }
|
|
||||||
},
|
|
||||||
property_source->data
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ikarus_property_source_visit_const(
|
|
||||||
struct IkarusPropertyScope const * property_source,
|
|
||||||
void (*blueprint_visitor)(struct IkarusBlueprint const *, void *),
|
|
||||||
void (*entity_visitor)(struct IkarusEntity const *, void *),
|
|
||||||
void * user_data
|
|
||||||
) {
|
|
||||||
std::visit(
|
|
||||||
cppbase::overloaded{
|
|
||||||
[blueprint_visitor, user_data](IkarusBlueprint const * blueprint) { blueprint_visitor(blueprint, user_data); },
|
|
||||||
[entity_visitor, user_data](IkarusEntity const * entity) { entity_visitor(entity, user_data); }
|
|
||||||
},
|
|
||||||
property_source->data
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
#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;
|
|
||||||
};
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
#include <ikarus/objects/properties/util.hpp>
|
#include <ikarus/objects/properties/util.hpp>
|
||||||
#include <ikarus/values/value.hpp>
|
#include <ikarus/values/value.hpp>
|
||||||
|
|
||||||
IkarusTextProperty::IkarusTextProperty(IkarusProject * project, IkarusId id):
|
IkarusTextProperty::IkarusTextProperty(IkarusProject * project, int64_t id):
|
||||||
IkarusProperty{project, id, this} {}
|
IkarusProperty{project, id, this} {}
|
||||||
|
|
||||||
IkarusTextProperty * ikarus_text_property_create(
|
IkarusTextProperty * ikarus_text_property_create(
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <ikarus/objects/properties/property.hpp>
|
#include <ikarus/objects/properties/property.hpp>
|
||||||
#include <ikarus/objects/properties/property_type.h>
|
#include <ikarus/values/value_type.h>
|
||||||
#include <ikarus/values/text_value.hpp>
|
#include <ikarus/values/text_value.hpp>
|
||||||
|
|
||||||
struct IkarusTextProperty : IkarusProperty {
|
struct IkarusTextProperty : public IkarusProperty {
|
||||||
public:
|
public:
|
||||||
using value_type = IkarusTextValue;
|
using value_type = IkarusTextValue;
|
||||||
constexpr auto static PropertyType = IkarusPropertyType_Text;
|
constexpr auto static PropertyType = IkarusValueType_Text;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
IkarusTextProperty(struct IkarusProject * project, IkarusId id);
|
IkarusTextProperty(struct IkarusProject * project, int64_t id);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
#include <ikarus/objects/properties/util.hpp>
|
#include <ikarus/objects/properties/util.hpp>
|
||||||
#include <ikarus/values/value.hpp>
|
#include <ikarus/values/value.hpp>
|
||||||
|
|
||||||
IkarusToggleProperty::IkarusToggleProperty(IkarusProject * project, IkarusId id):
|
IkarusToggleProperty::IkarusToggleProperty(IkarusProject * project, int64_t id):
|
||||||
IkarusProperty{project, id, this} {}
|
IkarusProperty{project, id, this} {}
|
||||||
|
|
||||||
IkarusToggleProperty * ikarus_toggle_property_create(
|
IkarusToggleProperty * ikarus_toggle_property_create(
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,17 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <ikarus/objects/properties/property.hpp>
|
#include <ikarus/objects/properties/property.hpp>
|
||||||
#include <ikarus/objects/properties/property_type.h>
|
|
||||||
#include <ikarus/values/toggle_value.hpp>
|
#include <ikarus/values/toggle_value.hpp>
|
||||||
|
#include <ikarus/values/value_type.h>
|
||||||
|
|
||||||
struct IkarusToggleProperty : IkarusProperty {
|
struct IkarusToggleProperty {
|
||||||
public:
|
public:
|
||||||
using value_type = IkarusToggleValue;
|
using value_type = IkarusToggleValue;
|
||||||
constexpr auto static PropertyType = IkarusPropertyType_Toggle;
|
constexpr auto static PropertyType = IkarusValueType_Toggle;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
IkarusToggleProperty(struct IkarusProject * project, IkarusId id);
|
IkarusToggleProperty(struct IkarusProject * project, int64_t id);
|
||||||
|
|
||||||
|
public:
|
||||||
|
IkarusProperty * property;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -22,15 +22,14 @@ T * create_property(
|
||||||
) {
|
) {
|
||||||
IKARUS_FAIL_IF_NULL(project, nullptr);
|
IKARUS_FAIL_IF_NULL(project, nullptr);
|
||||||
IKARUS_FAIL_IF_NULL(property_scope, nullptr);
|
IKARUS_FAIL_IF_NULL(property_scope, nullptr);
|
||||||
IKARUS_FAIL_IF_PROPERTY_SCOPE_INVALID(property_scope, nullptr);
|
IKARUS_FAIL_IF_NAME_INVALID(name, nullptr);
|
||||||
IKARUS_FAIL_IF_NAME_INVALID_OR_DUPLICATE(name, project, property_scope, nullptr);
|
|
||||||
|
|
||||||
IKARUS_VTRYRV_OR_FAIL(
|
IKARUS_VTRYRV_OR_FAIL(
|
||||||
IkarusId const id,
|
int64_t const id,
|
||||||
nullptr,
|
nullptr,
|
||||||
"failed to create property: {}",
|
"failed to create property: {}",
|
||||||
IkarusErrorInfo_Database_QueryFailed,
|
IkarusErrorInfo_Database_QueryFailed,
|
||||||
project->db->transact([name, property_scope](auto * db) -> cppbase::Result<IkarusId, sqlitecpp::TransactionError> {
|
project->db->transact([name, property_scope](auto * db) -> cppbase::Result<int64_t, sqlitecpp::TransactionError> {
|
||||||
TRY(db->execute("INSERT INTO `objects`(`type`) VALUES(?)", IkarusObjectType_Property));
|
TRY(db->execute("INSERT INTO `objects`(`type`) VALUES(?)", IkarusObjectType_Property));
|
||||||
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(
|
||||||
|
|
|
||||||
|
|
@ -6,18 +6,12 @@
|
||||||
|
|
||||||
#include <ikarus/errors.h>
|
#include <ikarus/errors.h>
|
||||||
#include <ikarus/errors.hpp>
|
#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>
|
#include <ikarus/persistence/project.hpp>
|
||||||
|
|
||||||
namespace ikarus::util {
|
namespace ikarus::util {
|
||||||
|
|
||||||
template<typename O>
|
template<typename O>
|
||||||
[[nodiscard]] IkarusId object_get_id(O const * object, IkarusErrorData * error_out) {
|
[[nodiscard]] int64_t object_get_id(O const * object, IkarusErrorData * error_out) {
|
||||||
IKARUS_FAIL_IF_NULL(object, 0);
|
IKARUS_FAIL_IF_NULL(object, 0);
|
||||||
IKARUS_FAIL_IF_OBJECT_MISSING(object, 0);
|
IKARUS_FAIL_IF_OBJECT_MISSING(object, 0);
|
||||||
|
|
||||||
|
|
@ -49,81 +43,14 @@ template<typename O>
|
||||||
return strdup(ret.data());
|
return strdup(ret.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] inline bool name_is_unique(
|
#define IKARUS_FAIL_IF_NAME_INVALID(name, ret) IKARUS_FAIL_IF_NULL(name, ret);
|
||||||
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 const * 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, 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);
|
|
||||||
|
|
||||||
#define IKARUS_FAIL_IF_NAME_INVALID_OR_DUPLICATE(name, project, object, ret, ...) \
|
|
||||||
IKARUS_FAIL_IF_NAME_INVALID(name, ret); \
|
|
||||||
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>
|
template<typename O>
|
||||||
void object_set_name(O * object, char const * name, IkarusErrorData * error_out) {
|
void object_set_name(O * object, char const * name, IkarusErrorData * error_out) {
|
||||||
IKARUS_FAIL_IF_NULL(object, );
|
IKARUS_FAIL_IF_NULL(object, );
|
||||||
IKARUS_FAIL_IF_OBJECT_MISSING(object, );
|
IKARUS_FAIL_IF_OBJECT_MISSING(object, );
|
||||||
IKARUS_FAIL_IF_NULL(name, );
|
IKARUS_FAIL_IF_NULL(name, );
|
||||||
IKARUS_FAIL_IF_NAME_INVALID_OR_DUPLICATE(name, object->project, object, );
|
IKARUS_FAIL_IF_NAME_INVALID(name, );
|
||||||
|
|
||||||
IKARUS_TRYRV_OR_FAIL(
|
IKARUS_TRYRV_OR_FAIL(
|
||||||
,
|
,
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,12 @@
|
||||||
#include <sqlitecpp/connection.hpp>
|
#include <sqlitecpp/connection.hpp>
|
||||||
|
|
||||||
namespace ikarus {
|
namespace ikarus {
|
||||||
|
|
||||||
CPPBASE_ASSET(m0_initial_layout, "ikarus/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:
|
||||||
Migration(char const * sql, size_t size):
|
Migration(char const * sql, size_t const size):
|
||||||
sql{sql, size} {}
|
sql{sql, size} {}
|
||||||
|
|
||||||
~Migration() override = default;
|
~Migration() override = default;
|
||||||
|
|
|
||||||
|
|
@ -1,68 +1,51 @@
|
||||||
CREATE TABLE `objects`
|
|
||||||
(
|
|
||||||
`do_not_access_rowid_alias` INTEGER PRIMARY KEY,
|
|
||||||
`type` INT NOT NULL,
|
|
||||||
`id` INT GENERATED ALWAYS AS (`do_not_access_rowid_alias` | (`type` << 56)) VIRTUAL UNIQUE
|
|
||||||
) STRICT;
|
|
||||||
|
|
||||||
CREATE UNIQUE INDEX `object_id` ON `objects` (`id`);
|
|
||||||
CREATE INDEX `object_type` ON `objects` (`type`);
|
|
||||||
|
|
||||||
CREATE TABLE `entities`
|
CREATE TABLE `entities`
|
||||||
(
|
(
|
||||||
`id` INT,
|
`id` INTEGER PRIMARY KEY,
|
||||||
`name` TEXT NOT NULL,
|
`name` TEXT NOT NULL
|
||||||
|
) STRICT;
|
||||||
|
|
||||||
PRIMARY KEY (`id`),
|
CREATE TABLE `entity_values`
|
||||||
UNIQUE (`name`),
|
(
|
||||||
FOREIGN KEY (`id`) REFERENCES `objects` (`id`) ON DELETE CASCADE
|
`entity` INTEGER NOT NULL REFERENCES `entities` (`id`) ON DELETE CASCADE,
|
||||||
|
`name` TEXT NOT NULL,
|
||||||
|
`type` INT NOT NULL,
|
||||||
|
`value` TEXT NOT NULL,
|
||||||
|
|
||||||
|
PRIMARY KEY (`entity`, `name`)
|
||||||
) WITHOUT ROWID, STRICT;
|
) WITHOUT ROWID, STRICT;
|
||||||
|
|
||||||
CREATE TABLE `blueprints`
|
CREATE TABLE `blueprints`
|
||||||
(
|
(
|
||||||
`id` INT,
|
`id` INTEGER PRIMARY KEY,
|
||||||
`name` TEXT NOT NULL,
|
`name` TEXT NOT NULL
|
||||||
|
) STRICT;
|
||||||
PRIMARY KEY (`id`),
|
|
||||||
UNIQUE (`name`),
|
|
||||||
FOREIGN KEY (`id`) REFERENCES `objects` (`id`) ON DELETE CASCADE
|
|
||||||
) WITHOUT ROWID, STRICT;
|
|
||||||
|
|
||||||
CREATE TABLE `entity_blueprint_links`
|
|
||||||
(
|
|
||||||
`entity` INT NOT NULL,
|
|
||||||
`blueprint` INT NOT NULL,
|
|
||||||
|
|
||||||
PRIMARY KEY (`entity`, `blueprint`),
|
|
||||||
FOREIGN KEY (`entity`) REFERENCES `entities` (`id`) ON DELETE CASCADE,
|
|
||||||
FOREIGN KEY (`blueprint`) REFERENCES `blueprints` (`id`) ON DELETE CASCADE
|
|
||||||
) WITHOUT ROWID, STRICT;
|
|
||||||
|
|
||||||
CREATE TABLE `properties`
|
CREATE TABLE `properties`
|
||||||
(
|
(
|
||||||
`id` INT,
|
`id` INTEGER PRIMARY KEY,
|
||||||
|
`blueprint` INTEGER NOT NULL REFERENCES `blueprints` (`id`) ON DELETE CASCADE,
|
||||||
`name` TEXT NOT NULL,
|
`name` TEXT NOT NULL,
|
||||||
`type` INT NOT NULL,
|
`type` INT NOT NULL,
|
||||||
|
`cardinality` 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,
|
) STRICT;
|
||||||
|
|
||||||
PRIMARY KEY (`id`),
|
|
||||||
UNIQUE (`source`, `name`),
|
|
||||||
FOREIGN KEY (`id`) REFERENCES `objects` (`id`) ON DELETE CASCADE,
|
|
||||||
FOREIGN KEY (`source`) REFERENCES `objects` (`id`) ON DELETE CASCADE
|
|
||||||
) WITHOUT ROWID, STRICT;
|
|
||||||
|
|
||||||
CREATE INDEX `properties_type` ON `properties` (`type`);
|
CREATE INDEX `properties_type` ON `properties` (`type`);
|
||||||
CREATE INDEX `properties_source` ON `properties` (`source`);
|
|
||||||
|
|
||||||
CREATE TABLE `values`
|
CREATE TABLE `entity_blueprint_links`
|
||||||
(
|
(
|
||||||
`entity` INT NOT NULL,
|
`entity` INTEGER NOT NULL REFERENCES `entities` (`id`) ON DELETE CASCADE,
|
||||||
`property` INT NOT NULL,
|
`blueprint` INTEGER NOT NULL REFERENCES `blueprints` (`id`) ON DELETE CASCADE,
|
||||||
|
|
||||||
|
PRIMARY KEY (`entity`, `blueprint`)
|
||||||
|
) STRICT;
|
||||||
|
|
||||||
|
CREATE TABLE `entity_property_values`
|
||||||
|
(
|
||||||
|
`entity` INTEGER NOT NULL REFERENCES `entities` (`id`) ON DELETE CASCADE,
|
||||||
|
`property` INTEGER NOT NULL REFERENCES `properties` (`id`) ON DELETE CASCADE,
|
||||||
`value` TEXT NOT NULL,
|
`value` TEXT NOT NULL,
|
||||||
|
|
||||||
PRIMARY KEY (`entity`, `property`),
|
PRIMARY KEY (`entity`, `property`)
|
||||||
FOREIGN KEY (`entity`) REFERENCES `entities` (`id`) ON DELETE CASCADE,
|
|
||||||
FOREIGN KEY (`property`) REFERENCES `properties` (`id`) ON DELETE CASCADE
|
|
||||||
) WITHOUT ROWID, STRICT;
|
) WITHOUT ROWID, STRICT;
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ IkarusProject::IkarusProject(std::string_view name, std::string_view path, std::
|
||||||
_properties{},
|
_properties{},
|
||||||
_entities{} {}
|
_entities{} {}
|
||||||
|
|
||||||
IkarusBlueprint * IkarusProject::get_blueprint(IkarusId id) {
|
IkarusBlueprint * IkarusProject::get_blueprint(int64_t id) {
|
||||||
return get_cached_object<IkarusBlueprint>(id, this->_blueprints);
|
return get_cached_object<IkarusBlueprint>(id, this->_blueprints);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -30,7 +30,7 @@ auto IkarusProject::uncache(IkarusBlueprint * blueprint) -> void {
|
||||||
remove_cached_object(blueprint, _blueprints);
|
remove_cached_object(blueprint, _blueprints);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto IkarusProject::get_entity(IkarusId id) -> IkarusEntity * {
|
auto IkarusProject::get_entity(int64_t id) -> IkarusEntity * {
|
||||||
return get_cached_object<IkarusEntity>(id, this->_entities);
|
return get_cached_object<IkarusEntity>(id, this->_entities);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -38,16 +38,16 @@ auto IkarusProject::uncache(IkarusEntity * entity) -> void {
|
||||||
remove_cached_object(entity, _entities);
|
remove_cached_object(entity, _entities);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto IkarusProject::get_property(IkarusId id, IkarusPropertyType type) -> IkarusProperty * {
|
auto IkarusProject::get_property(int64_t id, IkarusValueType type) -> IkarusProperty * {
|
||||||
auto const iter = _properties.find(id);
|
auto const iter = _properties.find(id);
|
||||||
|
|
||||||
if (iter == _properties.cend()) {
|
if (iter == _properties.cend()) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case IkarusPropertyType_Toggle:
|
case IkarusValueType_Toggle:
|
||||||
return _properties.emplace(id, std::make_unique<IkarusToggleProperty>(this, id)).first->second.get();
|
return _properties.emplace(id, std::make_unique<IkarusToggleProperty>(this, id)).first->second.get();
|
||||||
case IkarusPropertyType_Number:
|
case IkarusValueType_Number:
|
||||||
return _properties.emplace(id, std::make_unique<IkarusNumberProperty>(this, id)).first->second.get();
|
return _properties.emplace(id, std::make_unique<IkarusNumberProperty>(this, id)).first->second.get();
|
||||||
case IkarusPropertyType_Text: return _properties.emplace(id, std::make_unique<IkarusTextProperty>(this, id)).first->second.get();
|
case IkarusValueType_Text: return _properties.emplace(id, std::make_unique<IkarusTextProperty>(this, id)).first->second.get();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -212,13 +212,13 @@ void ikarus_project_get_blueprints(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
IkarusId ids[blueprints_out_size];
|
int64_t ids[blueprints_out_size];
|
||||||
|
|
||||||
IKARUS_TRYRV_OR_FAIL(
|
IKARUS_TRYRV_OR_FAIL(
|
||||||
,
|
,
|
||||||
"unable to fetch project blueprints from database: {}",
|
"unable to fetch project blueprints from database: {}",
|
||||||
IkarusErrorInfo_Database_QueryFailed,
|
IkarusErrorInfo_Database_QueryFailed,
|
||||||
project->db->query_many_buffered<IkarusId>("SELECT `id` FROM `blueprints`", ids, blueprints_out_size)
|
project->db->query_many_buffered<int64_t>("SELECT `id` FROM `blueprints`", ids, blueprints_out_size)
|
||||||
);
|
);
|
||||||
|
|
||||||
for (size_t i = 0; i < blueprints_out_size; ++i) {
|
for (size_t i = 0; i < blueprints_out_size; ++i) {
|
||||||
|
|
@ -253,13 +253,13 @@ void ikarus_project_get_entities(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
IkarusId ids[entities_out_size];
|
int64_t ids[entities_out_size];
|
||||||
|
|
||||||
IKARUS_TRYRV_OR_FAIL(
|
IKARUS_TRYRV_OR_FAIL(
|
||||||
,
|
,
|
||||||
"unable to fetch project entities from database: {}",
|
"unable to fetch project entities from database: {}",
|
||||||
IkarusErrorInfo_Database_QueryFailed,
|
IkarusErrorInfo_Database_QueryFailed,
|
||||||
project->db->query_many_buffered<IkarusId>("SELECT `id` FROM `entities`", ids, entities_out_size)
|
project->db->query_many_buffered<int64_t>("SELECT `id` FROM `entities`", ids, entities_out_size)
|
||||||
);
|
);
|
||||||
|
|
||||||
for (size_t i = 0; i < entities_out_size; ++i) {
|
for (size_t i = 0; i < entities_out_size; ++i) {
|
||||||
|
|
@ -293,7 +293,7 @@ struct IkarusEntity * get_entity_by_name(IkarusProject * project, char const * n
|
||||||
nullptr,
|
nullptr,
|
||||||
"unable to find entity in database: {}",
|
"unable to find entity in database: {}",
|
||||||
IkarusErrorInfo_Client_InvalidInput,
|
IkarusErrorInfo_Client_InvalidInput,
|
||||||
project->db->query_one<IkarusId>("SELECT `id` FROM `entities` WHERE `name` = ?", name)
|
project->db->query_one<int64_t>("SELECT `id` FROM `entities` WHERE `name` = ?", name)
|
||||||
);
|
);
|
||||||
|
|
||||||
return project->get_entity(id);
|
return project->get_entity(id);
|
||||||
|
|
@ -310,7 +310,7 @@ get_property_by_name(IkarusProject * project, IkarusPropertyScope * scope, char
|
||||||
nullptr,
|
nullptr,
|
||||||
"unable to find property in database: {}",
|
"unable to find property in database: {}",
|
||||||
IkarusErrorInfo_Client_InvalidInput,
|
IkarusErrorInfo_Client_InvalidInput,
|
||||||
project->db->query_one<IkarusId, IkarusPropertyType>(
|
project->db->query_one<int64_t, IkarusValueType>(
|
||||||
"SELECT `id`, `type` FROM `properties` WHERE `name` = ? AND `scope` = ?",
|
"SELECT `id`, `type` FROM `properties` WHERE `name` = ? AND `scope` = ?",
|
||||||
name,
|
name,
|
||||||
scope->get_id()
|
scope->get_id()
|
||||||
|
|
@ -332,7 +332,7 @@ IkarusBlueprint * get_blueprints_by_name(IkarusProject * project, char const * n
|
||||||
nullptr,
|
nullptr,
|
||||||
"unable to find blueprint in database: {}",
|
"unable to find blueprint in database: {}",
|
||||||
IkarusErrorInfo_Client_InvalidInput,
|
IkarusErrorInfo_Client_InvalidInput,
|
||||||
project->db->query_one<IkarusId>("SELECT `id` FROM `blueprints` WHERE `name` = ?", name)
|
project->db->query_one<int64_t>("SELECT `id` FROM `blueprints` WHERE `name` = ?", name)
|
||||||
);
|
);
|
||||||
|
|
||||||
return project->get_blueprint(id);
|
return project->get_blueprint(id);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <ranges>
|
|
||||||
#include <stack>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
|
|
@ -9,8 +7,7 @@
|
||||||
#include <sqlitecpp/connection.hpp>
|
#include <sqlitecpp/connection.hpp>
|
||||||
|
|
||||||
#include <ikarus/errors.h>
|
#include <ikarus/errors.h>
|
||||||
#include <ikarus/id.h>
|
#include <ikarus/values/value_type.h>
|
||||||
#include <ikarus/objects/properties/property_type.h>
|
|
||||||
|
|
||||||
namespace fs = boost::filesystem;
|
namespace fs = boost::filesystem;
|
||||||
|
|
||||||
|
|
@ -20,19 +17,19 @@ public:
|
||||||
IkarusProject(std::string_view name, std::string_view path, std::unique_ptr<sqlitecpp::Connection> && db);
|
IkarusProject(std::string_view name, std::string_view path, std::unique_ptr<sqlitecpp::Connection> && db);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
[[nodiscard]] auto get_blueprint(IkarusId id) -> struct IkarusBlueprint *;
|
[[nodiscard]] auto get_blueprint(int64_t id) -> struct IkarusBlueprint *;
|
||||||
auto uncache(struct IkarusBlueprint * blueprint) -> void;
|
auto uncache(struct IkarusBlueprint * blueprint) -> void;
|
||||||
|
|
||||||
[[nodiscard]] auto get_entity(IkarusId id) -> struct IkarusEntity *;
|
[[nodiscard]] auto get_entity(int64_t id) -> struct IkarusEntity *;
|
||||||
auto uncache(struct IkarusEntity * entity) -> void;
|
auto uncache(struct IkarusEntity * entity) -> void;
|
||||||
|
|
||||||
// TODO improve this to take a template param so that we don't have to cast in e.g. ikarus_toggle_property_create
|
// TODO improve this to take a template param so that we don't have to cast in e.g. ikarus_toggle_property_create
|
||||||
[[nodiscard]] auto get_property(IkarusId id, IkarusPropertyType type) -> struct IkarusProperty *;
|
[[nodiscard]] auto get_property(int64_t id, IkarusValueType type) -> struct IkarusProperty *;
|
||||||
auto uncache(struct IkarusProperty * property) -> void;
|
auto uncache(struct IkarusProperty * property) -> void;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template<typename T>
|
template<typename T>
|
||||||
[[nodiscard]] T * get_cached_object(IkarusId id, auto & cache) {
|
[[nodiscard]] T * get_cached_object(int64_t id, auto & cache) {
|
||||||
auto const iter = cache.find(id);
|
auto const iter = cache.find(id);
|
||||||
|
|
||||||
if (iter == cache.cend()) {
|
if (iter == cache.cend()) {
|
||||||
|
|
@ -43,7 +40,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void remove_cached_object(T * object, std::unordered_map<IkarusId, std::unique_ptr<T>> & cache) {
|
void remove_cached_object(T * object, std::unordered_map<int64_t, std::unique_ptr<T>> & cache) {
|
||||||
cache.erase(object->id);
|
cache.erase(object->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -53,9 +50,9 @@ public:
|
||||||
std::unique_ptr<sqlitecpp::Connection> db;
|
std::unique_ptr<sqlitecpp::Connection> db;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unordered_map<IkarusId, std::unique_ptr<struct IkarusBlueprint>> mutable _blueprints;
|
std::unordered_map<int64_t, std::unique_ptr<struct IkarusBlueprint>> mutable _blueprints;
|
||||||
std::unordered_map<IkarusId, std::unique_ptr<struct IkarusProperty>> mutable _properties;
|
std::unordered_map<int64_t, std::unique_ptr<struct IkarusProperty>> mutable _properties;
|
||||||
std::unordered_map<IkarusId, std::unique_ptr<struct IkarusEntity>> mutable _entities;
|
std::unordered_map<int64_t, std::unique_ptr<struct IkarusEntity>> mutable _entities;
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr std::string_view DB_PROJECT_NAME_KEY = "PROJECT_NAME";
|
constexpr std::string_view DB_PROJECT_NAME_KEY = "PROJECT_NAME";
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
struct IkarusEntityPropertyValue {
|
|
||||||
struct IkarusEntity const * entity;
|
|
||||||
struct IkarusProperty const * property;
|
|
||||||
struct IkarusValue const * value;
|
|
||||||
};
|
|
||||||
|
|
|
||||||
|
|
@ -6,60 +6,60 @@
|
||||||
#include <ikarus/values/value_base.hpp>
|
#include <ikarus/values/value_base.hpp>
|
||||||
|
|
||||||
IkarusNumberValue::IkarusNumberValue():
|
IkarusNumberValue::IkarusNumberValue():
|
||||||
IkarusValue{this} {}
|
IkarusValueData{this} {}
|
||||||
|
|
||||||
IkarusNumberValue * ikarus_number_value_create() {
|
IkarusNumberValue * ikarus_number_value_data_create() {
|
||||||
return new IkarusNumberValue{};
|
return new IkarusNumberValue{};
|
||||||
}
|
}
|
||||||
|
|
||||||
double const * ikarus_number_value_get(IkarusNumberValue * value, size_t idx) {
|
double const * ikarus_number_value_data_get(IkarusNumberValue * value, size_t idx) {
|
||||||
return ikarus_value_base_get(value, idx);
|
return ikarus_value_data_base_get(value, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ikarus_number_value_get_size(IkarusNumberValue const * value) {
|
size_t ikarus_number_value_data_get_size(IkarusNumberValue const * value) {
|
||||||
return ikarus_value_base_get_size(value);
|
return ikarus_value_data_base_get_size(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ikarus_number_value_set(IkarusNumberValue * value, size_t idx, double new_data) {
|
void ikarus_number_value_data_set(IkarusNumberValue * value, size_t idx, double new_data) {
|
||||||
return ikarus_value_base_set(value, idx, new_data);
|
return ikarus_value_data_base_set(value, idx, new_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ikarus_number_value_remove(IkarusNumberValue * value, size_t idx) {
|
void ikarus_number_value_data_remove(IkarusNumberValue * value, size_t idx) {
|
||||||
return ikarus_value_base_remove(value, idx);
|
return ikarus_value_data_base_remove(value, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ikarus_number_value_insert(IkarusNumberValue * value, size_t idx, long double new_data) {
|
void ikarus_number_value_data_insert(IkarusNumberValue * value, size_t idx, long double new_data) {
|
||||||
return ikarus_value_base_insert(value, idx, new_data);
|
return ikarus_value_data_base_insert(value, idx, new_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ikarus_number_value_clear(IkarusNumberValue * value) {
|
void ikarus_number_value_data_clear(IkarusNumberValue * value) {
|
||||||
return ikarus_value_base_clear(value);
|
return ikarus_value_data_base_clear(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ikarus_number_value_is_undefined(IkarusNumberValue const * value) {
|
bool ikarus_number_value_data_is_undefined(IkarusNumberValue const * value) {
|
||||||
return ikarus_value_base_is_undefined(value);
|
return ikarus_value_data_base_is_undefined(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ikarus_number_value_set_undefined(IkarusNumberValue * value, bool undefined) {
|
void ikarus_number_value_data_set_undefined(IkarusNumberValue * value, bool undefined) {
|
||||||
return ikarus_value_base_set_undefined(value, undefined);
|
return ikarus_value_data_base_set_undefined(value, undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
char const * ikarus_number_value_to_string(IkarusNumberValue const * value) {
|
char const * ikarus_number_value_data_to_string(IkarusNumberValue const * value) {
|
||||||
return ikarus_value_base_to_string(value, [](auto const & value) { return value; });
|
return ikarus_value_data_base_to_string(value, [](auto const & value) { return value; });
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ikarus_number_value_is_equal(IkarusNumberValue const * lhs, IkarusNumberValue const * rhs) {
|
bool ikarus_number_value_data_is_equal(IkarusNumberValue const * lhs, IkarusNumberValue const * rhs) {
|
||||||
return ikarus_value_base_is_equal(lhs, rhs);
|
return ikarus_value_data_base_is_equal(lhs, rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
IkarusNumberValue * ikarus_number_value_copy(IkarusNumberValue const * value) {
|
IkarusNumberValue * ikarus_number_value_data_copy(IkarusNumberValue const * value) {
|
||||||
return ikarus_value_base_copy(value);
|
return ikarus_value_data_base_copy(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct IkarusValue * ikarus_number_value_to_value(IkarusNumberValue * value) {
|
struct IkarusValueData * ikarus_number_value_data_to_value(IkarusNumberValue * value) {
|
||||||
return ikarus_value_base_to_value(value);
|
return ikarus_value_data_base_to_value(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct IkarusValue const * ikarus_number_value_to_value_const(IkarusNumberValue const * value) {
|
struct IkarusValueData const * ikarus_number_value_data_to_value_data_const(IkarusNumberValue const * value) {
|
||||||
return ikarus_value_base_to_value_const(value);
|
return ikarus_value_data_base_to_value_data_const(value);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
#include <ikarus/values/value.hpp>
|
#include <ikarus/values/value.hpp>
|
||||||
|
|
||||||
struct IkarusNumberValue : IkarusValue {
|
struct IkarusNumberValue : IkarusValueData {
|
||||||
public:
|
public:
|
||||||
using DataType = double;
|
using DataType = double;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,60 +7,60 @@
|
||||||
#include <ikarus/values/value_base.hpp>
|
#include <ikarus/values/value_base.hpp>
|
||||||
|
|
||||||
IkarusTextValue::IkarusTextValue():
|
IkarusTextValue::IkarusTextValue():
|
||||||
IkarusValue{this} {}
|
IkarusValueData{this} {}
|
||||||
|
|
||||||
IkarusTextValue * ikarus_text_value_create() {
|
IkarusTextValue * ikarus_text_value_data_create() {
|
||||||
return new IkarusTextValue{};
|
return new IkarusTextValue{};
|
||||||
}
|
}
|
||||||
|
|
||||||
char const * ikarus_text_value_get(IkarusTextValue * value, size_t idx) {
|
char const * ikarus_text_value_data_get(IkarusTextValue * value, size_t idx) {
|
||||||
return ikarus_value_base_get(value, idx)->data();
|
return ikarus_value_data_base_get(value, idx)->data();
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ikarus_text_value_get_size(IkarusTextValue const * value) {
|
size_t ikarus_text_value_data_get_size(IkarusTextValue const * value) {
|
||||||
return ikarus_value_base_get_size(value);
|
return ikarus_value_data_base_get_size(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ikarus_text_value_set(IkarusTextValue * value, size_t idx, char const * new_data) {
|
void ikarus_text_value_data_set(IkarusTextValue * value, size_t idx, char const * new_data) {
|
||||||
return ikarus_value_base_set(value, idx, new_data);
|
return ikarus_value_data_base_set(value, idx, new_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ikarus_text_value_remove(IkarusTextValue * value, size_t idx) {
|
void ikarus_text_value_data_remove(IkarusTextValue * value, size_t idx) {
|
||||||
return ikarus_value_base_remove(value, idx);
|
return ikarus_value_data_base_remove(value, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ikarus_text_value_insert(IkarusTextValue * value, size_t idx, char const * new_data) {
|
void ikarus_text_value_data_insert(IkarusTextValue * value, size_t idx, char const * new_data) {
|
||||||
return ikarus_value_base_insert(value, idx, new_data);
|
return ikarus_value_data_base_insert(value, idx, new_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ikarus_text_value_clear(IkarusTextValue * value) {
|
void ikarus_text_value_data_clear(IkarusTextValue * value) {
|
||||||
return ikarus_value_base_clear(value);
|
return ikarus_value_data_base_clear(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ikarus_text_value_is_undefined(IkarusTextValue const * value) {
|
bool ikarus_text_value_data_is_undefined(IkarusTextValue const * value) {
|
||||||
return ikarus_value_base_is_undefined(value);
|
return ikarus_value_data_base_is_undefined(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ikarus_text_value_set_undefined(IkarusTextValue * value, bool undefined) {
|
void ikarus_text_value_data_set_undefined(IkarusTextValue * value, bool undefined) {
|
||||||
return ikarus_value_base_set_undefined(value, undefined);
|
return ikarus_value_data_base_set_undefined(value, undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
char const * ikarus_text_value_to_string(IkarusTextValue const * value) {
|
char const * ikarus_text_value_data_to_string(IkarusTextValue const * value) {
|
||||||
return ikarus_value_base_to_string(value, [](auto const & value) { return value; });
|
return ikarus_value_data_base_to_string(value, [](auto const & value) { return value; });
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ikarus_text_value_is_equal(IkarusTextValue const * lhs, IkarusTextValue const * rhs) {
|
bool ikarus_text_value_data_is_equal(IkarusTextValue const * lhs, IkarusTextValue const * rhs) {
|
||||||
return ikarus_value_base_is_equal(lhs, rhs);
|
return ikarus_value_data_base_is_equal(lhs, rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
IkarusTextValue * ikarus_text_value_copy(IkarusTextValue const * value) {
|
IkarusTextValue * ikarus_text_value_data_copy(IkarusTextValue const * value) {
|
||||||
return ikarus_value_base_copy(value);
|
return ikarus_value_data_base_copy(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct IkarusValue * ikarus_text_value_to_value(IkarusTextValue * value) {
|
struct IkarusValueData * ikarus_text_value_data_to_value(IkarusTextValue * value) {
|
||||||
return ikarus_value_base_to_value(value);
|
return ikarus_value_data_base_to_value(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct IkarusValue const * ikarus_text_value_to_value_const(IkarusTextValue const * value) {
|
struct IkarusValueData const * ikarus_text_value_data_to_value_data_const(IkarusTextValue const * value) {
|
||||||
return ikarus_value_base_to_value_const(value);
|
return ikarus_value_data_base_to_value_data_const(value);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
#include <ikarus/values/value.hpp>
|
#include <ikarus/values/value.hpp>
|
||||||
|
|
||||||
struct IkarusTextValue : IkarusValue {
|
struct IkarusTextValue : IkarusValueData {
|
||||||
public:
|
public:
|
||||||
using DataType = std::string;
|
using DataType = std::string;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,60 +7,60 @@
|
||||||
#include <ikarus/values/value_base.hpp>
|
#include <ikarus/values/value_base.hpp>
|
||||||
|
|
||||||
IkarusToggleValue::IkarusToggleValue():
|
IkarusToggleValue::IkarusToggleValue():
|
||||||
IkarusValue{this} {}
|
IkarusValueData{this} {}
|
||||||
|
|
||||||
IkarusToggleValue * ikarus_toggle_value_create() {
|
IkarusToggleValue * ikarus_toggle_value_data_create() {
|
||||||
return new IkarusToggleValue{};
|
return new IkarusToggleValue{};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool const * ikarus_toggle_value_get(IkarusToggleValue * value, size_t idx) {
|
bool const * ikarus_toggle_value_data_get(IkarusToggleValue * value, size_t idx) {
|
||||||
return ikarus_value_base_get(value, idx);
|
return ikarus_value_data_base_get(value, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ikarus_toggle_value_get_size(IkarusToggleValue const * value) {
|
size_t ikarus_toggle_value_data_get_size(IkarusToggleValue const * value) {
|
||||||
return ikarus_value_base_get_size(value);
|
return ikarus_value_data_base_get_size(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ikarus_toggle_value_set(IkarusToggleValue * value, size_t idx, bool new_data) {
|
void ikarus_toggle_value_data_set(IkarusToggleValue * value, size_t idx, bool new_data) {
|
||||||
return ikarus_value_base_set(value, idx, new_data);
|
return ikarus_value_data_base_set(value, idx, new_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ikarus_toggle_value_remove(IkarusToggleValue * value, size_t idx) {
|
void ikarus_toggle_value_data_remove(IkarusToggleValue * value, size_t idx) {
|
||||||
return ikarus_value_base_remove(value, idx);
|
return ikarus_value_data_base_remove(value, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ikarus_toggle_value_insert(IkarusToggleValue * value, size_t idx, bool new_data) {
|
void ikarus_toggle_value_data_insert(IkarusToggleValue * value, size_t idx, bool new_data) {
|
||||||
return ikarus_value_base_insert(value, idx, new_data);
|
return ikarus_value_data_base_insert(value, idx, new_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ikarus_toggle_value_clear(IkarusToggleValue * value) {
|
void ikarus_toggle_value_data_clear(IkarusToggleValue * value) {
|
||||||
return ikarus_value_base_clear(value);
|
return ikarus_value_data_base_clear(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ikarus_toggle_value_is_undefined(IkarusToggleValue const * value) {
|
bool ikarus_toggle_value_data_is_undefined(IkarusToggleValue const * value) {
|
||||||
return ikarus_value_base_is_undefined(value);
|
return ikarus_value_data_base_is_undefined(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ikarus_toggle_value_set_undefined(IkarusToggleValue * value, bool undefined) {
|
void ikarus_toggle_value_data_set_undefined(IkarusToggleValue * value, bool undefined) {
|
||||||
return ikarus_value_base_set_undefined(value, undefined);
|
return ikarus_value_data_base_set_undefined(value, undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
char const * ikarus_toggle_value_to_string(IkarusToggleValue const * value) {
|
char const * ikarus_toggle_value_data_to_string(IkarusToggleValue const * value) {
|
||||||
return ikarus_value_base_to_string(value, [](auto const & value) { return value ? "✓" : "✗"; });
|
return ikarus_value_data_base_to_string(value, [](auto const & value) { return value ? "✓" : "✗"; });
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ikarus_toggle_value_is_equal(IkarusToggleValue const * lhs, IkarusToggleValue const * rhs) {
|
bool ikarus_toggle_value_data_is_equal(IkarusToggleValue const * lhs, IkarusToggleValue const * rhs) {
|
||||||
return ikarus_value_base_is_equal(lhs, rhs);
|
return ikarus_value_data_base_is_equal(lhs, rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
IkarusToggleValue * ikarus_toggle_value_copy(IkarusToggleValue const * value) {
|
IkarusToggleValue * ikarus_toggle_value_data_copy(IkarusToggleValue const * value) {
|
||||||
return ikarus_value_base_copy(value);
|
return ikarus_value_data_base_copy(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct IkarusValue * ikarus_toggle_value_to_value(IkarusToggleValue * value) {
|
struct IkarusValueData * ikarus_toggle_value_data_to_value(IkarusToggleValue * value) {
|
||||||
return ikarus_value_base_to_value(value);
|
return ikarus_value_data_base_to_value(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct IkarusValue const * ikarus_toggle_value_to_value_const(IkarusToggleValue const * value) {
|
struct IkarusValueData const * ikarus_toggle_value_data_to_value_data_const(IkarusToggleValue const * value) {
|
||||||
return ikarus_value_base_to_value_const(value);
|
return ikarus_value_data_base_to_value_data_const(value);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
#include <ikarus/values/value.hpp>
|
#include <ikarus/values/value.hpp>
|
||||||
|
|
||||||
struct IkarusToggleValue : IkarusValue {
|
struct IkarusToggleValue : IkarusValueData {
|
||||||
public:
|
public:
|
||||||
using DataType = bool;
|
using DataType = bool;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,41 +3,53 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <boost/container/small_vector.hpp>
|
#include <boost/container/small_vector.hpp>
|
||||||
|
|
||||||
// required for header-only inclusion
|
|
||||||
#include "cppbase/templates.hpp"
|
|
||||||
|
|
||||||
#include <boost/json/src.hpp>
|
#include <boost/json/src.hpp>
|
||||||
|
|
||||||
#include <ikarus/objects/properties/property_type.h>
|
// required for header-only inclusion
|
||||||
|
#include <cppbase/templates.hpp>
|
||||||
|
|
||||||
#include <ikarus/values/number_value.hpp>
|
#include <ikarus/values/number_value.hpp>
|
||||||
#include <ikarus/values/text_value.hpp>
|
#include <ikarus/values/text_value.hpp>
|
||||||
#include <ikarus/values/toggle_value.hpp>
|
#include <ikarus/values/toggle_value.hpp>
|
||||||
#include <ikarus/values/value.hpp>
|
#include <ikarus/values/value.hpp>
|
||||||
|
#include <ikarus/values/value_cardinality.h>
|
||||||
|
#include <ikarus/values/value_type.h>
|
||||||
|
|
||||||
IkarusValue::IkarusValue(Data data):
|
IkarusValue::IkarusValue(Data data, IkarusValueCardinality cardinality):
|
||||||
data(data) {}
|
data{data},
|
||||||
|
cardinality{cardinality} {}
|
||||||
|
|
||||||
cppbase::Result<IkarusValue *, IkarusValue::FromJsonError> IkarusValue::from_json(boost::json::value json) {
|
cppbase::Result<IkarusValue *, IkarusValue::FromJsonError> IkarusValue::from_json(boost::json::value json) {
|
||||||
if (auto const * obj = json.if_object(); obj == nullptr) {
|
if (auto const * obj = json.if_object(); obj == nullptr) {
|
||||||
return cppbase::err(FromJsonError{});
|
return cppbase::err(FromJsonError{});
|
||||||
} else {
|
} else {
|
||||||
boost::int64_t const * type = nullptr;
|
int64_t const * type;
|
||||||
boost::json::value const * data = nullptr;
|
int64_t const * cardinality;
|
||||||
|
boost::json::value const * data;
|
||||||
|
|
||||||
if (auto const * type_value = obj->if_contains("type"); type_value == nullptr) {
|
if (auto const * type_value = obj->if_contains(IKARUS_VALUE_JSON_TYPE_KEY); type_value == nullptr) {
|
||||||
return cppbase::err(FromJsonError{});
|
return cppbase::err(FromJsonError{});
|
||||||
} else if (type = type_value->if_int64(); type == nullptr) {
|
} else if (type = type_value->if_int64(); type == nullptr) {
|
||||||
return cppbase::err(FromJsonError{});
|
return cppbase::err(FromJsonError{});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data = obj->if_contains("data"); data == nullptr) {
|
if (auto const * cardinality_value = obj->if_contains(IKARUS_VALUE_JSON_CARDINALITY_KEY); cardinality_value == nullptr) {
|
||||||
|
return cppbase::err(FromJsonError{});
|
||||||
|
} else if (cardinality = cardinality_value->if_int64(); cardinality == nullptr) {
|
||||||
|
return cppbase::err(FromJsonError{});
|
||||||
|
} else if (*cardinality != IkarusValueCardinality_Single && *cardinality != IkarusValueCardinality_Multiple) {
|
||||||
return cppbase::err(FromJsonError{});
|
return cppbase::err(FromJsonError{});
|
||||||
}
|
}
|
||||||
|
|
||||||
auto create_value = [data]<typename T>() -> cppbase::Result<IkarusValue *, FromJsonError> {
|
if (data = obj->if_contains(IKARUS_VALUE_JSON_DATA_KEY); data == nullptr) {
|
||||||
|
return cppbase::err(FromJsonError{});
|
||||||
|
}
|
||||||
|
|
||||||
|
auto create_value = [data, cardinality]<typename T>() -> cppbase::Result<IkarusValue *, FromJsonError> {
|
||||||
T * ret = nullptr;
|
T * ret = nullptr;
|
||||||
|
|
||||||
|
ret->cardinality = *cardinality;
|
||||||
|
|
||||||
if (data->is_null()) {
|
if (data->is_null()) {
|
||||||
ret = new T{};
|
ret = new T{};
|
||||||
ret->data = boost::variant2::monostate{};
|
ret->data = boost::variant2::monostate{};
|
||||||
|
|
@ -58,13 +70,13 @@ cppbase::Result<IkarusValue *, IkarusValue::FromJsonError> IkarusValue::from_jso
|
||||||
};
|
};
|
||||||
|
|
||||||
switch (*type) {
|
switch (*type) {
|
||||||
case IkarusPropertyType_Toggle: {
|
case IkarusValueType_Toggle: {
|
||||||
return create_value.operator()<IkarusToggleValue>();
|
return create_value.operator()<IkarusToggleValue>();
|
||||||
}
|
}
|
||||||
case IkarusPropertyType_Number: {
|
case IkarusValueType_Number: {
|
||||||
return create_value.operator()<IkarusNumberValue>();
|
return create_value.operator()<IkarusNumberValue>();
|
||||||
}
|
}
|
||||||
case IkarusPropertyType_Text: {
|
case IkarusValueType_Text: {
|
||||||
return create_value.operator()<IkarusTextValue>();
|
return create_value.operator()<IkarusTextValue>();
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
|
|
@ -75,18 +87,18 @@ cppbase::Result<IkarusValue *, IkarusValue::FromJsonError> IkarusValue::from_jso
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::json::value IkarusValue::to_json() const {
|
boost::json::value IkarusValue::to_json() const {
|
||||||
auto type = boost::variant2::visit(
|
auto type = std::visit(
|
||||||
cppbase::overloaded{
|
cppbase::overloaded{
|
||||||
[]([[maybe_unused]] IkarusToggleValue const * value) { return IkarusPropertyType_Toggle; },
|
[]([[maybe_unused]] IkarusToggleValue const * value) { return IkarusValueType_Toggle; },
|
||||||
[]([[maybe_unused]] IkarusNumberValue const * value) { return IkarusPropertyType_Number; },
|
[]([[maybe_unused]] IkarusNumberValue const * value) { return IkarusValueType_Number; },
|
||||||
[]([[maybe_unused]] IkarusTextValue const * value) { return IkarusPropertyType_Text; }
|
[]([[maybe_unused]] IkarusTextValue const * value) { return IkarusValueType_Text; }
|
||||||
},
|
},
|
||||||
data
|
data
|
||||||
);
|
);
|
||||||
|
|
||||||
auto data_json = boost::variant2::visit(
|
auto data_json = std::visit(
|
||||||
[]<typename T>(T const * value) -> boost::json::value {
|
[]<typename T>(T const * value) -> boost::json::value {
|
||||||
return boost::variant2::visit(
|
return std::visit(
|
||||||
cppbase::overloaded{
|
cppbase::overloaded{
|
||||||
[]([[maybe_unused]] boost::variant2::monostate const & data) -> boost::json::value { return nullptr; },
|
[]([[maybe_unused]] boost::variant2::monostate const & data) -> boost::json::value { return nullptr; },
|
||||||
[](auto const & data) -> boost::json::value { return boost::json::value_from(data); }
|
[](auto const & data) -> boost::json::value { return boost::json::value_from(data); }
|
||||||
|
|
@ -98,8 +110,9 @@ boost::json::value IkarusValue::to_json() const {
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
{"type", type},
|
{ IKARUS_VALUE_JSON_TYPE_KEY, type},
|
||||||
{"data", data_json}
|
{IKARUS_VALUE_JSON_CARDINALITY_KEY, cardinality},
|
||||||
|
{ IKARUS_VALUE_JSON_DATA_KEY, data_json}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -110,7 +123,7 @@ void ikarus_value_visit(
|
||||||
void (*text_visitor)(IkarusTextValue *, void *),
|
void (*text_visitor)(IkarusTextValue *, void *),
|
||||||
void * data
|
void * data
|
||||||
) {
|
) {
|
||||||
boost::variant2::visit(
|
std::visit(
|
||||||
cppbase::overloaded{
|
cppbase::overloaded{
|
||||||
[toggle_visitor, data](IkarusToggleValue * toggle_value) { toggle_visitor(toggle_value, data); },
|
[toggle_visitor, data](IkarusToggleValue * toggle_value) { toggle_visitor(toggle_value, data); },
|
||||||
[number_visitor, data](IkarusNumberValue * number_value) { number_visitor(number_value, data); },
|
[number_visitor, data](IkarusNumberValue * number_value) { number_visitor(number_value, data); },
|
||||||
|
|
@ -119,20 +132,3 @@ void ikarus_value_visit(
|
||||||
value->data
|
value->data
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ikarus_value_visit_const(
|
|
||||||
IkarusValue const * value,
|
|
||||||
void (*toggle_visitor)(IkarusToggleValue const *, void *),
|
|
||||||
void (*number_visitor)(IkarusNumberValue const *, void *),
|
|
||||||
void (*text_visitor)(IkarusTextValue const *, void *),
|
|
||||||
void * data
|
|
||||||
) {
|
|
||||||
boost::variant2::visit(
|
|
||||||
cppbase::overloaded{
|
|
||||||
[toggle_visitor, data](IkarusToggleValue const * toggle_value) { toggle_visitor(toggle_value, data); },
|
|
||||||
[number_visitor, data](IkarusNumberValue const * number_value) { number_visitor(number_value, data); },
|
|
||||||
[text_visitor, data](IkarusTextValue const * text_value) { text_visitor(text_value, data); }
|
|
||||||
},
|
|
||||||
value->data
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,24 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <boost/json.hpp>
|
#include <boost/json.hpp>
|
||||||
#include <boost/variant2.hpp>
|
|
||||||
|
|
||||||
#include <cppbase/result.hpp>
|
#include <cppbase/result.hpp>
|
||||||
|
|
||||||
#include <ikarus/errors.hpp>
|
#include <ikarus/errors.hpp>
|
||||||
#include <ikarus/persistence/project.hpp>
|
#include <ikarus/persistence/project.hpp>
|
||||||
|
#include <ikarus/values/value_cardinality.h>
|
||||||
|
|
||||||
|
constexpr auto IKARUS_VALUE_JSON_TYPE_KEY = "type";
|
||||||
|
constexpr auto IKARUS_VALUE_JSON_CARDINALITY_KEY = "card";
|
||||||
|
constexpr auto IKARUS_VALUE_JSON_DATA_KEY = "data";
|
||||||
|
|
||||||
struct IkarusValue {
|
struct IkarusValue {
|
||||||
public:
|
public:
|
||||||
using Data = boost::variant2::variant<struct IkarusToggleValue *, struct IkarusNumberValue *, struct IkarusTextValue *>;
|
using Data = std::variant<struct IkarusToggleValue *, struct IkarusNumberValue *, struct IkarusTextValue *>;
|
||||||
constexpr static auto SMALL_VEC_VALUE_SIZE = 8;
|
constexpr static auto SMALL_VEC_VALUE_SIZE = 8;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit IkarusValue(Data data);
|
explicit IkarusValue(Data data, IkarusValueCardinality cardinality);
|
||||||
|
|
||||||
IkarusValue(IkarusValue const &) = default;
|
IkarusValue(IkarusValue const &) = default;
|
||||||
IkarusValue(IkarusValue &&) noexcept = default;
|
IkarusValue(IkarusValue &&) noexcept = default;
|
||||||
|
|
@ -32,6 +36,7 @@ public:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Data data;
|
Data data;
|
||||||
|
IkarusValueCardinality cardinality;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
|
|
@ -74,3 +79,20 @@ IkarusValue * fetch_value_from_db(IkarusProject * project, IkarusErrorData * err
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define IKARUS_FAIL_IF_VALUE_MISSING_IMPL(var_name, entity, name, ret) \
|
||||||
|
IKARUS_VTRYRV_OR_FAIL( \
|
||||||
|
bool const var_name, \
|
||||||
|
ret, \
|
||||||
|
"unable to check whether value exists: {}", \
|
||||||
|
IkarusErrorInfo_Database_QueryFailed, \
|
||||||
|
(entity)->project->db->template query_one<bool>( \
|
||||||
|
"SELECT EXISTS(SELECT 1 FROM `entity_values` WHERE `entity` = ? AND `name` = ?)", \
|
||||||
|
(entity)->id, \
|
||||||
|
name \
|
||||||
|
) \
|
||||||
|
) \
|
||||||
|
\
|
||||||
|
IKARUS_FAIL_IF(!(var_name), ret, "entity value does not exist", IkarusErrorInfo_Client_Misuse);
|
||||||
|
|
||||||
|
#define IKARUS_FAIL_IF_VALUE_MISSING(entity, name, ret) IKARUS_FAIL_IF_VALUE_MISSING_IMPL(CPPBASE_UNIQUE_NAME(exists), entity, name, ret);
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,10 @@
|
||||||
#include <cppbase/templates.hpp>
|
#include <cppbase/templates.hpp>
|
||||||
|
|
||||||
template<typename V>
|
template<typename V>
|
||||||
typename V::DataType const * ikarus_value_base_get(V * value, size_t idx) {
|
typename V::DataType const * ikarus_value_data_base_get(V * value, size_t idx) {
|
||||||
if (auto * data =
|
if (auto * data = boost::variant2::get_if<boost::container::small_vector<typename V::DataType, IkarusValueData::SMALL_VEC_VALUE_SIZE>>(
|
||||||
boost::variant2::get_if<boost::container::small_vector<typename V::DataType, IkarusValue::SMALL_VEC_VALUE_SIZE>>(&value->data);
|
&value->data
|
||||||
|
);
|
||||||
data != nullptr) {
|
data != nullptr) {
|
||||||
return &(*data)[idx];
|
return &(*data)[idx];
|
||||||
}
|
}
|
||||||
|
|
@ -18,9 +19,10 @@ typename V::DataType const * ikarus_value_base_get(V * value, size_t idx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename V>
|
template<typename V>
|
||||||
size_t ikarus_value_base_get_size(V const * value) {
|
size_t ikarus_value_data_base_get_size(V const * value) {
|
||||||
if (auto * data =
|
if (auto * data = boost::variant2::get_if<boost::container::small_vector<typename V::DataType, IkarusValueData::SMALL_VEC_VALUE_SIZE>>(
|
||||||
boost::variant2::get_if<boost::container::small_vector<typename V::DataType, IkarusValue::SMALL_VEC_VALUE_SIZE>>(&value->data);
|
&value->data
|
||||||
|
);
|
||||||
data != nullptr) {
|
data != nullptr) {
|
||||||
return data->size();
|
return data->size();
|
||||||
}
|
}
|
||||||
|
|
@ -29,57 +31,61 @@ size_t ikarus_value_base_get_size(V const * value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename V>
|
template<typename V>
|
||||||
void ikarus_value_base_set(V * value, size_t idx, typename V::DataType new_data) {
|
void ikarus_value_data_base_set(V * value, size_t idx, typename V::DataType new_data) {
|
||||||
if (auto * data =
|
if (auto * data = boost::variant2::get_if<boost::container::small_vector<typename V::DataType, IkarusValueData::SMALL_VEC_VALUE_SIZE>>(
|
||||||
boost::variant2::get_if<boost::container::small_vector<typename V::DataType, IkarusValue::SMALL_VEC_VALUE_SIZE>>(&value->data);
|
&value->data
|
||||||
|
);
|
||||||
data != nullptr) {
|
data != nullptr) {
|
||||||
(*data)[idx] = new_data;
|
(*data)[idx] = new_data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename V>
|
template<typename V>
|
||||||
void ikarus_value_base_remove(V * value, size_t idx) {
|
void ikarus_value_data_base_remove(V * value, size_t idx) {
|
||||||
if (auto * data =
|
if (auto * data = boost::variant2::get_if<boost::container::small_vector<typename V::DataType, IkarusValueData::SMALL_VEC_VALUE_SIZE>>(
|
||||||
boost::variant2::get_if<boost::container::small_vector<typename V::DataType, IkarusValue::SMALL_VEC_VALUE_SIZE>>(&value->data);
|
&value->data
|
||||||
|
);
|
||||||
data != nullptr) {
|
data != nullptr) {
|
||||||
data->erase(data->begin() + idx);
|
data->erase(data->begin() + idx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename V>
|
template<typename V>
|
||||||
void ikarus_value_base_insert(V * value, size_t idx, typename V::DataType new_data) {
|
void ikarus_value_data_base_insert(V * value, size_t idx, typename V::DataType new_data) {
|
||||||
if (auto * data =
|
if (auto * data = boost::variant2::get_if<boost::container::small_vector<typename V::DataType, IkarusValueData::SMALL_VEC_VALUE_SIZE>>(
|
||||||
boost::variant2::get_if<boost::container::small_vector<typename V::DataType, IkarusValue::SMALL_VEC_VALUE_SIZE>>(&value->data);
|
&value->data
|
||||||
|
);
|
||||||
data != nullptr) {
|
data != nullptr) {
|
||||||
data->insert(data->begin() + idx, new_data);
|
data->insert(data->begin() + idx, new_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename V>
|
template<typename V>
|
||||||
void ikarus_value_base_clear(V * value) {
|
void ikarus_value_data_base_clear(V * value) {
|
||||||
if (auto * data =
|
if (auto * data = boost::variant2::get_if<boost::container::small_vector<typename V::DataType, IkarusValueData::SMALL_VEC_VALUE_SIZE>>(
|
||||||
boost::variant2::get_if<boost::container::small_vector<typename V::DataType, IkarusValue::SMALL_VEC_VALUE_SIZE>>(&value->data);
|
&value->data
|
||||||
|
);
|
||||||
data != nullptr) {
|
data != nullptr) {
|
||||||
data->clear();
|
data->clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename V>
|
template<typename V>
|
||||||
bool ikarus_value_base_is_undefined(V const * value) {
|
bool ikarus_value_data_base_is_undefined(V const * value) {
|
||||||
return boost::variant2::holds_alternative<boost::variant2::monostate>(value->data);
|
return boost::variant2::holds_alternative<boost::variant2::monostate>(value->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename V>
|
template<typename V>
|
||||||
void ikarus_value_base_set_undefined(V * value, bool undefined) {
|
void ikarus_value_data_base_set_undefined(V * value, bool undefined) {
|
||||||
if (undefined) {
|
if (undefined) {
|
||||||
value->data = boost::variant2::monostate{};
|
value->data = boost::variant2::monostate{};
|
||||||
} else {
|
} else {
|
||||||
value->data = boost::container::small_vector<typename V::DataType, IkarusValue::SMALL_VEC_VALUE_SIZE>{};
|
value->data = boost::container::small_vector<typename V::DataType, IkarusValueData::SMALL_VEC_VALUE_SIZE>{};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename V, std::invocable<typename V::DataType> F>
|
template<typename V, std::invocable<typename V::DataType> F>
|
||||||
char const * ikarus_value_base_to_string(V const * value, F transformer) {
|
char const * ikarus_value_data_base_to_string(V const * value, F transformer) {
|
||||||
return boost::variant2::visit(
|
return boost::variant2::visit(
|
||||||
cppbase::overloaded{
|
cppbase::overloaded{
|
||||||
[](boost::variant2::monostate const &) -> char const * { return nullptr; },
|
[](boost::variant2::monostate const &) -> char const * { return nullptr; },
|
||||||
|
|
@ -100,21 +106,21 @@ char const * ikarus_value_base_to_string(V const * value, F transformer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename V>
|
template<typename V>
|
||||||
bool ikarus_value_base_is_equal(V const * lhs, V const * rhs) {
|
bool ikarus_value_data_base_is_equal(V const * lhs, V const * rhs) {
|
||||||
return lhs->data == rhs->data;
|
return lhs->data == rhs->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename V>
|
template<typename V>
|
||||||
V * ikarus_value_base_copy(V const * value) {
|
V * ikarus_value_data_base_copy(V const * value) {
|
||||||
return new V{*value};
|
return new V{*value};
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename V>
|
template<typename V>
|
||||||
struct IkarusValue * ikarus_value_base_to_value(V * value) {
|
struct IkarusValueData * ikarus_value_data_base_to_value(V * value) {
|
||||||
return static_cast<IkarusValue *>(value);
|
return static_cast<IkarusValueData *>(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename V>
|
template<typename V>
|
||||||
struct IkarusValue const * ikarus_value_base_to_value_const(V const * value) {
|
struct IkarusValueData const * ikarus_value_data_base_to_value_data_const(V const * value) {
|
||||||
return static_cast<IkarusValue const *>(value);
|
return static_cast<IkarusValueData const *>(value);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue