libikarus/include/ikarus/id.h
Folling e1bf97704a
change error system & function signatures
Signed-off-by: Folling <mail@folling.io>
2025-01-01 14:07:47 +01:00

46 lines
1.7 KiB
C

// 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>
IKARUS_BEGIN_HEADER
/// \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
/// @{
/// \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