add flatbuffers support and initial rewrite
Signed-off-by: Folling <mail@folling.io>
This commit is contained in:
parent
b5852698e3
commit
70820129ae
72 changed files with 3929 additions and 1403 deletions
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>
|
||||
|
||||
#include <ikarus/macros.h>
|
||||
#include <ikarus/stdtypes.h>
|
||||
|
||||
/// \addtogroup errors Errors
|
||||
/// \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.
|
||||
/// 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.
|
||||
|
|
@ -93,7 +92,7 @@ enum IkarusErrorInfo {
|
|||
};
|
||||
|
||||
/// \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
|
||||
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,27 +1,23 @@
|
|||
#pragma once
|
||||
|
||||
#if defined(__unix__)
|
||||
|
||||
#define IKA_OS_FAMILY_UNIX
|
||||
#define IKA_API __attribute__((visibility("default")))
|
||||
|
||||
#if defined(linux)
|
||||
#define IKA_OS_LINUX
|
||||
#endif
|
||||
|
||||
#elif defined(_WIN32) || defined(WIN32)
|
||||
#define IKA_OS_WIN
|
||||
#define IKA_API __declspec(dllexport)
|
||||
#endif
|
||||
|
||||
#ifndef IKA_API
|
||||
#define IKA_API
|
||||
|
||||
#if defined(__unix__)
|
||||
#define IKA_OS_FAMILY_UNIX
|
||||
#define IKA_API __attribute__((visibility("default")))
|
||||
|
||||
#if defined(linux)
|
||||
#define IKA_OS_LINUX
|
||||
#endif
|
||||
#elif defined(_WIN32)
|
||||
#define IKA_OS_WIN
|
||||
#define IKA_API __declspec(dllexport)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define IKARUS_BEGIN_HEADER extern "C" {
|
||||
#define IKARUS_END_HEADER }
|
||||
#define IKARUS_BEGIN_HEADER extern "C" {
|
||||
#define IKARUS_END_HEADER }
|
||||
#else
|
||||
#define IKARUS_BEGIN_HEADER
|
||||
#define IKARUS_END_HEADER
|
||||
#define IKARUS_BEGIN_HEADER
|
||||
#define IKARUS_END_HEADER
|
||||
#endif
|
||||
|
|
|
|||
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>
|
||||
|
||||
#include <ikarus/errors.h>
|
||||
#include <ikarus/id.h>
|
||||
#include <ikarus/macros.h>
|
||||
#include <ikarus/stdtypes.h>
|
||||
|
||||
|
|
@ -14,9 +13,10 @@
|
|||
|
||||
IKARUS_BEGIN_HEADER
|
||||
|
||||
/// \brief A blueprint object.
|
||||
/// \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
|
||||
/// \brief Blueprints are templates for managing common properties of 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. Changes in blueprints will be reflected in all linked entities.
|
||||
struct IkarusBlueprint;
|
||||
|
||||
/// \brief Creates a blueprint.
|
||||
|
|
@ -25,19 +25,24 @@ struct IkarusBlueprint;
|
|||
/// \pre \li Must exist.
|
||||
/// \param name The name of the blueprint.
|
||||
/// \pre \li Must not be null.
|
||||
/// \pre \li Must not be empty.
|
||||
/// \pre \li Must be unique among all blueprints in the project.
|
||||
/// \param error_out \see errors.h
|
||||
/// \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.
|
||||
/// \pre \li Must not be null.
|
||||
/// \pre \li Must exist.
|
||||
/// \param error_out \see errors.h
|
||||
/// \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.
|
||||
/// \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.
|
||||
/// \param error_out \see errors.h
|
||||
/// \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.
|
||||
/// \param blueprint The blueprint to get the project of.
|
||||
/// \pre \li Must not be null.
|
||||
/// \pre \li Must exist.
|
||||
/// \param error_out \see errors.h
|
||||
/// \return The project the blueprint is part of or null if an error occurs.
|
||||
IKA_API IkarusProject * ikarus_blueprint_get_project(IkarusBlueprint const * blueprint, IkarusErrorData * error_out);
|
||||
/// \return The project or null if an error occurs.
|
||||
IKA_API IkarusProject * ikarus_blueprint_get_project(
|
||||
IkarusBlueprint const * blueprint,
|
||||
IkarusErrorData * error_out
|
||||
);
|
||||
|
||||
/// \brief Gets the name of a blueprint.
|
||||
/// \param blueprint The blueprint to get the name of.
|
||||
/// \pre \li Must not be null.
|
||||
/// \pre \li Must exist.
|
||||
/// \param error_out \see errors.h
|
||||
/// \return The name of the blueprint or null if an error occurs.
|
||||
IKA_API char const * ikarus_blueprint_get_name(IkarusBlueprint const * blueprint, IkarusErrorData * error_out);
|
||||
/// \return The name or null if an error occurs.
|
||||
IKA_API char const * ikarus_blueprint_get_name(
|
||||
IkarusBlueprint const * blueprint,
|
||||
IkarusErrorData * error_out
|
||||
);
|
||||
|
||||
/// \brief Sets the name of a blueprint.
|
||||
/// \param blueprint The blueprint to set the name of.
|
||||
|
|
@ -69,10 +83,12 @@ IKA_API char const * ikarus_blueprint_get_name(IkarusBlueprint const * blueprint
|
|||
/// \pre \li Must exist.
|
||||
/// \param name The new name of the blueprint.
|
||||
/// \pre \li Must not be null.
|
||||
/// \pre \li Must not be empty.
|
||||
/// \pre \li Must be unique among all blueprints in the project.
|
||||
/// \param error_out \see errors.h
|
||||
IKA_API void ikarus_blueprint_set_name(IkarusBlueprint * blueprint, char const * name, IkarusErrorData * error_out);
|
||||
IKA_API void ikarus_blueprint_set_name(
|
||||
IkarusBlueprint * blueprint,
|
||||
char const * name,
|
||||
IkarusErrorData * error_out
|
||||
);
|
||||
|
||||
/// \brief Gets the properties of a blueprint.
|
||||
/// \param blueprint The blueprint to get the properties of.
|
||||
|
|
@ -96,7 +112,10 @@ IKA_API void ikarus_blueprint_get_properties(
|
|||
/// \pre \li Must exist.
|
||||
/// \param error_out \see errors.h
|
||||
/// \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.
|
||||
/// \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.
|
||||
/// \param error_out \see errors.h
|
||||
/// \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
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <ikarus/errors.h>
|
||||
#include <ikarus/id.h>
|
||||
#include <ikarus/macros.h>
|
||||
#include <ikarus/stdtypes.h>
|
||||
|
||||
|
|
@ -14,25 +13,20 @@
|
|||
IKARUS_BEGIN_HEADER
|
||||
|
||||
/// \brief Entities are the core building blocks of Ikarus.
|
||||
/// \detials Blueprints and Properties define the structure of the data.
|
||||
/// Entities define the data itself.
|
||||
/// \details Entities store two data: A name and a set of values.
|
||||
/// 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:
|
||||
/// - Directly: The property is linked to the entity.
|
||||
/// - Indirectly: The property is linked to a blueprint the entity is linked to.
|
||||
/// For documentation on the types and layout of values \see Values.h.
|
||||
///
|
||||
/// For each property an entity is linked to, it has a value. These values depend on the property's type.
|
||||
/// For more information on the types see the property documentation.
|
||||
/// Entities can be linked to blueprints.
|
||||
/// 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.
|
||||
/// Each value is associated with one page and one property.
|
||||
///
|
||||
/// \remark Values are typed, the type of a value is specified by its associated property.
|
||||
/// 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.
|
||||
/// We distinguish between `EntityValues` and `EntityPropertyValues`.
|
||||
/// `EntityValues` are a direct part of the entity.
|
||||
/// `EntityPropertyValues` are an indirect part of the entity, linked to them
|
||||
/// via a blueprint.
|
||||
struct IkarusEntity;
|
||||
|
||||
/// \brief Creates an entity.
|
||||
|
|
@ -41,11 +35,13 @@ struct IkarusEntity;
|
|||
/// \pre \li Must exist.
|
||||
/// \param name The name of the entity.
|
||||
/// \pre \li Must not be null.
|
||||
/// \pre \li Must not be empty.
|
||||
/// \pre \li Must be unique among all entities in the project.
|
||||
/// \param error_out \see errors.h
|
||||
/// \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.
|
||||
/// \param entity The entity to delete.
|
||||
|
|
@ -53,15 +49,17 @@ IKA_API IkarusEntity * ikarus_entity_create(struct IkarusProject * project, char
|
|||
/// \pre \li Must exist.
|
||||
/// \param error_out \see errors.h
|
||||
/// \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.
|
||||
/// \param entity The entity to get the ID of.
|
||||
/// \brief Gets the id of an entity.
|
||||
/// \param entity The entity to get the id of.
|
||||
/// \pre \li Must not be null.
|
||||
/// \pre \li Must exist.
|
||||
/// \param error_out \see errors.h
|
||||
/// \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);
|
||||
/// \return The id of the entity or 0 if an error occurs.
|
||||
IKA_API int64_t
|
||||
ikarus_entity_get_id(IkarusEntity const * entity, IkarusErrorData * error_out);
|
||||
|
||||
/// \brief Gets the project an entity is part 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.
|
||||
/// \param error_out \see errors.h
|
||||
/// \return The project the entity is part of or null if an error occurs.
|
||||
IKA_API IkarusProject * ikarus_entity_get_project(IkarusEntity const * entity, IkarusErrorData * error_out);
|
||||
IKA_API IkarusProject * ikarus_entity_get_project(
|
||||
IkarusEntity const * entity,
|
||||
IkarusErrorData * error_out
|
||||
);
|
||||
|
||||
/// \brief Gets the name of an entity.
|
||||
/// \param entity The entity to get the name of.
|
||||
|
|
@ -77,7 +78,10 @@ IKA_API IkarusProject * ikarus_entity_get_project(IkarusEntity const * entity, I
|
|||
/// \pre \li Must exist.
|
||||
/// \param error_out \see errors.h
|
||||
/// \return The name of the entity or null if an error occurs.
|
||||
IKA_API char const * ikarus_entity_get_name(IkarusEntity const * entity, IkarusErrorData * error_out);
|
||||
IKA_API char const * ikarus_entity_get_name(
|
||||
IkarusEntity const * entity,
|
||||
IkarusErrorData * error_out
|
||||
);
|
||||
|
||||
/// \brief Sets the name of an entity.
|
||||
/// \param entity The entity to set the name of.
|
||||
|
|
@ -85,10 +89,12 @@ IKA_API char const * ikarus_entity_get_name(IkarusEntity const * entity, IkarusE
|
|||
/// \pre \li Must exist.
|
||||
/// \param name The new name of the entity.
|
||||
/// \pre \li Must not be null.
|
||||
/// \pre \li Must not be empty.
|
||||
/// \pre \li Must be unique among all entities in the project.
|
||||
/// \param error_out \see errors.h
|
||||
IKA_API void ikarus_entity_set_name(IkarusEntity * entity, char const * name, IkarusErrorData * error_out);
|
||||
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.
|
||||
/// \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.
|
||||
/// \param error_out \see errors.h
|
||||
/// \return True if the entity is linked to the blueprint, false otherwise.
|
||||
IKA_API bool
|
||||
ikarus_entity_is_linked_to_blueprint(IkarusEntity const * entity, struct IkarusBlueprint const * blueprint, IkarusErrorData * error_out);
|
||||
IKA_API bool ikarus_entity_is_linked_to_blueprint(
|
||||
IkarusEntity const * entity,
|
||||
struct IkarusBlueprint const * blueprint,
|
||||
IkarusErrorData * error_out
|
||||
);
|
||||
|
||||
/// \brief Links an entity to a blueprint.
|
||||
/// \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.
|
||||
/// \param error_out \see errors.h
|
||||
/// \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
|
||||
/// will be deleted.
|
||||
/// \brief Unlinks an entity from a blueprint.
|
||||
/// All values of the blueprints' properties will be deleted.
|
||||
/// \param entity The entity to unlink.
|
||||
/// \pre \li Must not be null.
|
||||
/// \pre \li Must exist.
|
||||
|
|
@ -123,9 +136,13 @@ IKA_API void ikarus_entity_link_to_blueprint(IkarusEntity * entity, struct Ikaru
|
|||
/// \pre \li Must exist.
|
||||
/// \param error_out \see errors.h
|
||||
/// \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.
|
||||
/// \pre \li Must not be null.
|
||||
/// \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.
|
||||
/// \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 exist.
|
||||
/// \param error_out \see errors.h
|
||||
/// \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.
|
||||
/// \pre \li Must not be null.
|
||||
/// \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 exist.
|
||||
/// \param error_out \see errors.h
|
||||
/// \return False if an error occurs or the entity does not have the property, true otherwise.
|
||||
IKA_API bool ikarus_entity_has_property(IkarusEntity const * entity, struct IkarusProperty const * property, IkarusErrorData * error_out);
|
||||
/// \return False if an error occurs or the entity does not have the property,
|
||||
/// 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.
|
||||
/// \param entity The entity to get the properties of.
|
||||
/// \brief Gets the properties an entity is linked to.
|
||||
/// \param entity The entity to get the linked properties of.
|
||||
/// \pre \li Must not be null.
|
||||
/// \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.
|
||||
/// \param error_out \see errors.h
|
||||
/// \param properties_out_size The size of the buffer.
|
||||
|
|
@ -176,30 +264,37 @@ IKA_API void ikarus_entity_get_properties(
|
|||
IkarusErrorData * error_out
|
||||
);
|
||||
|
||||
/// \brief Gets the number of properties of an entity.
|
||||
/// \param entity The entity to get the number of properties of.
|
||||
/// \brief Gets the number of properties an entity is linked to.
|
||||
/// \param entity The entity to get the number of linked properties of.
|
||||
/// \pre \li Must not be null.
|
||||
/// \pre \li Must exist.
|
||||
/// \param error_out \see errors.h
|
||||
/// \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.
|
||||
/// \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.
|
||||
/// \pre \li Must not be null.
|
||||
/// \pre \li Must exist.
|
||||
/// \param property The property to get the value of.
|
||||
/// \pre \li Must not be null.
|
||||
/// \pre \li Must exist.
|
||||
/// \pre \li Must be linked to the entity.
|
||||
/// \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.
|
||||
/// \remark Must be freed using #ikarus_free.
|
||||
IKA_API struct IkarusEntityPropertyValue *
|
||||
ikarus_entity_get_value(IkarusEntity const * entity, struct IkarusProperty const * property, IkarusErrorData * error_out);
|
||||
/// \return The value of the property or null if an error occurs.
|
||||
IKA_API struct IkarusValue * ikarus_entity_get_property_value(
|
||||
IkarusEntity const * entity,
|
||||
struct IkarusProperty const * property,
|
||||
IkarusErrorData * error_out
|
||||
);
|
||||
|
||||
/// \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 exist.
|
||||
/// \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.
|
||||
/// \param error_out \see errors.h
|
||||
/// \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,
|
||||
struct IkarusProperty const * property,
|
||||
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.
|
||||
/// \param name The name of the property.
|
||||
/// \pre \li Must not be null.
|
||||
/// \pre \li Must not be empty.
|
||||
/// \param property_source The property source to create the property for.
|
||||
/// \pre \li Must not be null.
|
||||
/// \pre \li Must exist.
|
||||
|
|
@ -36,31 +35,6 @@ IKA_API IkarusNumberProperty * ikarus_number_property_create(
|
|||
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
|
||||
|
||||
/// @}
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@
|
|||
/// \author Folling <folling@ikarus.world>
|
||||
|
||||
#include <ikarus/errors.h>
|
||||
#include <ikarus/id.h>
|
||||
#include <ikarus/macros.h>
|
||||
#include <ikarus/objects/properties/property_type.h>
|
||||
#include <ikarus/stdtypes.h>
|
||||
#include <ikarus/values/value_cardinality.h>
|
||||
#include <ikarus/values/value_type.h>
|
||||
|
||||
/// \defgroup properties Properties
|
||||
/// \brief Properties define the structure and types of data.
|
||||
|
|
@ -15,9 +15,10 @@
|
|||
|
||||
IKARUS_BEGIN_HEADER
|
||||
|
||||
/// \brief Properties are the placeholders of values for entities.
|
||||
/// \details Each entity can have any number of properties.
|
||||
/// \brief Properties define the structure of blueprints.
|
||||
/// \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.
|
||||
/// This is the "base class" of properties. See the derived types (e.g. IkarusToggleProperty) for more information.
|
||||
///
|
||||
/// The following types currently exist:
|
||||
/// - Toggle: A true/false boolean-like value
|
||||
|
|
@ -29,32 +30,10 @@ IKARUS_BEGIN_HEADER
|
|||
/// - Age (Number)
|
||||
/// - 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.
|
||||
///
|
||||
/// Properties can also be added to blueprints in which case they are available for all entities associated with the
|
||||
/// 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.
|
||||
/// \remark Values for properties are lazily created to save space.
|
||||
/// 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;
|
||||
|
||||
/// \brief Deletes a property.
|
||||
|
|
@ -71,7 +50,7 @@ IKA_API void ikarus_property_delete(IkarusProperty * property, IkarusErrorData *
|
|||
/// \pre \li Must exist.
|
||||
/// \param error_out \see errors.h
|
||||
/// \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.
|
||||
/// \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.
|
||||
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.
|
||||
/// \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 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.
|
||||
/// \pre \li Must not be null.
|
||||
/// \pre \li Must exist.
|
||||
/// \param error_out \see errors.h
|
||||
/// \return The source of the property or null if an error occurs.
|
||||
/// \remark Must be freed using #ikarus_free.
|
||||
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);
|
||||
IKA_API struct IkarusBlueprint * ikarus_property_get_blueprint(IkarusProperty const * property, IkarusErrorData * error_out);
|
||||
|
||||
/// \brief Visits a property. Calling the appropriate function for the property's type.
|
||||
/// \param property The property to visit.
|
||||
|
|
@ -125,28 +139,6 @@ IKA_API void ikarus_property_visit(
|
|||
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
|
||||
|
||||
// @}
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
/// \param name The name of the property.
|
||||
/// \pre \li Must not be null.
|
||||
/// \pre \li Must not be empty.
|
||||
/// \param property_source The property source to create the property for.
|
||||
/// \pre \li Must not be null.
|
||||
/// \pre \li Must exist.
|
||||
|
|
@ -32,31 +31,7 @@ IKA_API IkarusTextProperty * ikarus_text_property_create(
|
|||
struct IkarusProject * project,
|
||||
char const * name,
|
||||
struct IkarusPropertySource * property_source,
|
||||
struct IkarusTextValue* default_value,
|
||||
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,
|
||||
struct IkarusTextValue * default_value,
|
||||
IkarusErrorData * error_out
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -7,11 +7,11 @@
|
|||
#include <ikarus/macros.h>
|
||||
|
||||
/// \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
|
||||
|
||||
/// \brief Toggle properties store a value that can be either true or false. (e.g. "Is the character dead?")
|
||||
struct IkarusToggleProperty;
|
||||
|
||||
/// \brief Creates a toggle property.
|
||||
|
|
@ -20,44 +20,15 @@ struct IkarusToggleProperty;
|
|||
/// \pre \li Must exist.
|
||||
/// \param name The name of the property.
|
||||
/// \pre \li Must not be null.
|
||||
/// \pre \li Must not be empty.
|
||||
/// \param property_source The property source to create the property for.
|
||||
/// \pre \li Must not be null.
|
||||
/// \pre \li Must exist.
|
||||
/// \param default_value The default value for the property.
|
||||
/// \pre \li Must not be null.
|
||||
/// \param error_out \see errors.h
|
||||
/// \return The created property or null if an error occurs.
|
||||
IKA_API IkarusToggleProperty * ikarus_toggle_property_create(
|
||||
struct IkarusProject * project,
|
||||
char const * name,
|
||||
struct IkarusPropertySource * property_source,
|
||||
struct IkarusToggleValue * default_value,
|
||||
IkarusErrorData * error_out
|
||||
);
|
||||
|
||||
/// \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
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,11 @@ struct IkarusProject;
|
|||
/// \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
|
||||
/// 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.
|
||||
/// \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.
|
||||
/// \remark Must be freed using #ikarus_free. Freeing does not delete the project from the filesystem. For that, use
|
||||
/// 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.
|
||||
/// \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.
|
||||
/// \remark Must be freed using ikarus_free. Freeing does not delete the project from the filesystem. For that, use
|
||||
/// 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.
|
||||
/// \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
|
||||
/// \return The name of the project.
|
||||
/// \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.
|
||||
/// \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 empty.
|
||||
/// \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.
|
||||
/// \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
|
||||
/// \return The path of the project.
|
||||
/// \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.
|
||||
/// \param project The project to get the entities of.
|
||||
|
|
@ -101,7 +117,10 @@ IKA_API void ikarus_project_get_entities(
|
|||
/// \pre \li Must exist.
|
||||
/// \param error_out \see errors.h
|
||||
/// \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.
|
||||
/// \param project The project to get the blueprints of.
|
||||
|
|
@ -124,51 +143,11 @@ IKA_API void ikarus_project_get_blueprints(
|
|||
/// \pre \li Must exist.
|
||||
/// \param error_out \see errors.h
|
||||
/// \return The number of blueprints or undefined if an error occurs.
|
||||
IKA_API size_t ikarus_project_get_blueprint_count(IkarusProject const * project, IkarusErrorData * error_out);
|
||||
|
||||
/// \brief Finds an entity by a given name.
|
||||
/// \param project The project to search.
|
||||
/// \pre \li Must not be null.
|
||||
/// \pre \li Must exist.
|
||||
/// \param name The name to search for.
|
||||
/// \pre \li Must not be null.
|
||||
/// \pre \li Must not be empty.
|
||||
/// \param error_out \see errors.h
|
||||
/// \return The entity with the given name or null if none was found.
|
||||
IKA_API struct IkarusEntity * 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,
|
||||
IKA_API size_t ikarus_project_get_blueprint_count(
|
||||
IkarusProject const * project,
|
||||
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
|
||||
|
||||
/// @}
|
||||
|
|
|
|||
|
|
@ -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/macros.h>
|
||||
#include <ikarus/values/value_cardinality.h>
|
||||
|
||||
/// \addtogroup values Values
|
||||
/// @{
|
||||
|
|
@ -15,10 +16,11 @@ IKARUS_BEGIN_HEADER
|
|||
struct IkarusNumberValue;
|
||||
|
||||
/// \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
|
||||
/// \return The value or null if an error occurs.
|
||||
/// \remark Must be freed with #ikarus_free.
|
||||
IKA_API IkarusNumberValue * ikarus_number_value_create(IkarusErrorData * error_out);
|
||||
IKA_API IkarusNumberValue * ikarus_number_value_create(IkarusValueCardinality cardinality, IkarusErrorData * error_out);
|
||||
|
||||
/// \brief Fetches the underlying data of a number value at a specific index.
|
||||
/// \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.
|
||||
/// \pre \li Must be less than the size of the value.
|
||||
/// \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);
|
||||
|
||||
/// \brief Fetches the size of the underlying data of a number value.
|
||||
/// \param value The number value.
|
||||
/// \pre \li Must not be null.
|
||||
/// \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);
|
||||
|
||||
/// \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
|
||||
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.
|
||||
/// \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 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_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.
|
||||
/// \param value The number value.
|
||||
/// \pre \li Cardinality must be "Multiple".
|
||||
/// \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);
|
||||
|
||||
/// \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.
|
||||
/// \param value The number value to convert.
|
||||
/// \pre \li Must not be null.
|
||||
/// \param error_out \see errors.h
|
||||
/// \return The converted string.
|
||||
/// \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);
|
||||
|
||||
/// \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.
|
||||
/// \param error_out \see errors.h
|
||||
/// \return The copied value.
|
||||
/// \remark Must be freed with #ikarus_free.
|
||||
IKA_API IkarusNumberValue * ikarus_number_value_copy(IkarusNumberValue const * value, IkarusErrorData * error_out);
|
||||
|
||||
/// \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
|
||||
/// \return The converted entity 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);
|
||||
|
||||
/// \see ikarus_toggle_value_to_value
|
||||
IKA_API struct IkarusValue const * ikarus_number_value_to_value_const(IkarusNumberValue const * value, IkarusErrorData * error_out);
|
||||
IKA_API struct IkarusValueData * ikarus_number_value_to_value(IkarusNumberValue * value, IkarusErrorData * error_out);
|
||||
|
||||
IKARUS_END_HEADER
|
||||
|
||||
|
|
|
|||
|
|
@ -5,36 +5,37 @@
|
|||
|
||||
#include <ikarus/errors.h>
|
||||
#include <ikarus/macros.h>
|
||||
#include <ikarus/stdtypes.h>
|
||||
#include <ikarus/values/value_cardinality.h>
|
||||
|
||||
/// \addtogroup values Values
|
||||
/// @{
|
||||
|
||||
IKARUS_BEGIN_HEADER
|
||||
|
||||
/// \brief A textual value. For example "Surname" or "Description"
|
||||
/// \brief A numeric value. For example "Age" or "Height".
|
||||
struct IkarusTextValue;
|
||||
|
||||
/// \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
|
||||
/// \return The value or null if an error occurs.
|
||||
/// \remark Must be freed with #ikarus_free.
|
||||
IKA_API IkarusTextValue * ikarus_text_value_create(IkarusErrorData * error_out);
|
||||
IKA_API IkarusTextValue * ikarus_text_value_create(IkarusValueCardinality cardinality, IkarusErrorData * error_out);
|
||||
|
||||
/// \brief Fetches the underlying data of a number value at a specific index.
|
||||
/// \param value The number value.
|
||||
/// \brief Fetches the underlying data of a text value at a specific index.
|
||||
/// \param value The text value.
|
||||
/// \pre \li Must not be null.
|
||||
/// \param idx The index of the data to fetch.
|
||||
/// \pre \li Must be less than the size of the value.
|
||||
/// \param error_out \see errors.h
|
||||
/// \return The underlying data or null if an error occurs or the value is undefined.
|
||||
IKA_API char const * const * ikarus_text_value_get(IkarusTextValue const * value, size_t idx, IkarusErrorData * error_out);
|
||||
/// \return The underlying data or NaN if an error occurs.
|
||||
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.
|
||||
/// \param value The text value.
|
||||
/// \pre \li Must not be null.
|
||||
/// \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);
|
||||
|
||||
/// \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.
|
||||
/// \param idx The index of the data to set.
|
||||
/// \pre \li Must be less than the size of the value.
|
||||
/// \param new_data The new data. Ownership remains with the caller.
|
||||
/// \pre \li Must not be null.
|
||||
/// \param new_data The new data.
|
||||
/// \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);
|
||||
|
||||
/// \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.
|
||||
/// \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 remove.
|
||||
/// \pre \li Must be less than the size of the value.
|
||||
/// \param error_out \see errors.h
|
||||
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.
|
||||
/// \param value The text value.
|
||||
/// \pre \li Cardinality must be "Multiple".
|
||||
/// \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);
|
||||
|
||||
/// \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.
|
||||
/// \param value The text value to convert.
|
||||
/// \pre \li Must not be null.
|
||||
/// \param error_out \see errors.h
|
||||
/// \return The converted string.
|
||||
/// \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);
|
||||
|
||||
/// \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.
|
||||
/// \param error_out \see errors.h
|
||||
/// \return The copied value.
|
||||
/// \remark Must be freed with #ikarus_free.
|
||||
IKA_API IkarusTextValue * ikarus_text_value_copy(IkarusTextValue const * value, IkarusErrorData * error_out);
|
||||
|
||||
/// \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
|
||||
/// \return The converted entity 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);
|
||||
|
||||
/// \see ikarus_text_value_to_value
|
||||
IKA_API struct IkarusValue const * ikarus_text_value_to_value_const(IkarusTextValue const * value, IkarusErrorData * error_out);
|
||||
IKA_API struct IkarusValueData * ikarus_text_value_to_value(IkarusTextValue * value, IkarusErrorData * error_out);
|
||||
|
||||
IKARUS_END_HEADER
|
||||
|
||||
|
|
|
|||
|
|
@ -5,36 +5,37 @@
|
|||
|
||||
#include <ikarus/errors.h>
|
||||
#include <ikarus/macros.h>
|
||||
#include <ikarus/stdtypes.h>
|
||||
#include <ikarus/values/value_cardinality.h>
|
||||
|
||||
/// \addtogroup values Values
|
||||
/// @{
|
||||
|
||||
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;
|
||||
|
||||
/// \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
|
||||
/// \return The value or null if an error occurs.
|
||||
/// \remark Must be freed with #ikarus_free.
|
||||
IKA_API IkarusToggleValue * ikarus_toggle_value_create(IkarusErrorData * error_out);
|
||||
IKA_API IkarusToggleValue * ikarus_toggle_value_create(IkarusValueCardinality cardinality, IkarusErrorData * error_out);
|
||||
|
||||
/// \brief Fetches the underlying data of a number value at a specific index.
|
||||
/// \param value The number value.
|
||||
/// \brief Fetches the underlying data of a toggle value at a specific index.
|
||||
/// \param value The toggle value.
|
||||
/// \pre \li Must not be null.
|
||||
/// \param idx The index of the data to fetch.
|
||||
/// \pre \li Must be less than the size of the value.
|
||||
/// \param error_out \see errors.h
|
||||
/// \return The underlying data or null if an error occurs or the value is undefined.
|
||||
IKA_API bool const * ikarus_toggle_value_get(IkarusToggleValue const * value, size_t idx, IkarusErrorData * error_out);
|
||||
/// \return The underlying data or NaN if an error occurs.
|
||||
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.
|
||||
/// \param value The toggle value.
|
||||
/// \pre \li Must not be null.
|
||||
/// \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);
|
||||
|
||||
/// \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
|
||||
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.
|
||||
/// \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 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_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.
|
||||
/// \param value The toggle value.
|
||||
/// \pre \li Cardinality must be "Multiple".
|
||||
/// \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);
|
||||
|
||||
/// \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.
|
||||
/// \param value The toggle value to convert.
|
||||
/// \pre \li Must not be null.
|
||||
/// \param error_out \see errors.h
|
||||
/// \return The converted string.
|
||||
/// \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);
|
||||
|
||||
/// \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.
|
||||
/// \param error_out \see errors.h
|
||||
/// \return The copied value.
|
||||
/// \remark Must be freed with #ikarus_free.
|
||||
IKA_API IkarusToggleValue * ikarus_toggle_value_copy(IkarusToggleValue const * value, IkarusErrorData * error_out);
|
||||
|
||||
/// \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
|
||||
/// \return The converted entity 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);
|
||||
|
||||
/// \see ikarus_toggle_value_to_value
|
||||
IKA_API struct IkarusValue const * ikarus_toggle_value_to_value_const(IkarusToggleValue const * value, IkarusErrorData * error_out);
|
||||
IKA_API struct IkarusValueData * ikarus_toggle_value_to_value(IkarusToggleValue * value, IkarusErrorData * error_out);
|
||||
|
||||
IKARUS_END_HEADER
|
||||
|
||||
|
|
|
|||
|
|
@ -4,14 +4,27 @@
|
|||
/// \author Folling <folling@ikarus.world>
|
||||
|
||||
/// \defgroup values Values
|
||||
/// \brief The values of properties.
|
||||
/// \details Each entity has a value for each property it is associated with.
|
||||
/// These value classes represent plain objects. They are not associated with any entity.
|
||||
/// Each value may be undefined. \see IkarusProperty
|
||||
/// Values are stored as lists. If a property is "singular" then its value is a list of size 1.
|
||||
/// Values are typed, with types existing for each of the corresponding property types. The data of values starts with the index 0.
|
||||
/// When setting values for a property the type must match the property type and the value must be valid under the
|
||||
/// property's settings. \see PropertyType
|
||||
/// \brief Values are data in entities.
|
||||
/// \details An entity is made up of any number of values.
|
||||
/// Each value defines a certain aspect of an entity.
|
||||
/// Values have a name, a type, and some data.
|
||||
/// Examples of values would be:
|
||||
/// - Is Dead (Toggle)
|
||||
/// - Age (Number)
|
||||
/// - 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>
|
||||
|
|
@ -19,15 +32,19 @@
|
|||
|
||||
IKARUS_BEGIN_HEADER
|
||||
|
||||
/// \brief The common type for all values.
|
||||
/// \brief The common type for all value data.
|
||||
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.
|
||||
/// \pre \li Must not be null.
|
||||
/// \param toggle_visitor The function to call if the value is a toggle value. Skipped if null.
|
||||
/// \param number_visitor The function to call if the value is a number value. Skipped if null.
|
||||
/// \param text_visitor The function to call if the value is a text value. Skipped if null.
|
||||
/// \param toggle_visitor The function to call if the value is a toggle value.
|
||||
/// \remark 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 error_out \see errors.h
|
||||
IKA_API void ikarus_value_visit(
|
||||
|
|
@ -39,16 +56,6 @@ IKA_API void ikarus_value_visit(
|
|||
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
|
||||
|
||||
/// @}
|
||||
|
|
|
|||
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
|
||||
|
||||
/// @}
|
||||
Loading…
Add table
Add a link
Reference in a new issue