restructure into smaller files & add IWYU/clang-tidy
Signed-off-by: Folling <mail@folling.io>
This commit is contained in:
parent
660736133a
commit
13eee8b168
28 changed files with 845 additions and 556 deletions
66
include/ikarus/id.h
Normal file
66
include/ikarus/id.h
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
// IMPLEMENTATION_DETAIL_DATABASE
|
||||
|
||||
/// \file id.h
|
||||
/// \author Folling <mail@folling.io>
|
||||
|
||||
#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 8 bits: #IkarusObjectType - 255 possible values, 0 for special values
|
||||
/// - 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 - 127 possible values, 0 for special values
|
||||
/// - last 56 bits: incremented counter generated by the database
|
||||
struct IkarusId {
|
||||
/// \private \brief The value of the id.
|
||||
int64_t data;
|
||||
};
|
||||
|
||||
/// \brief A special id returned by failed functions.
|
||||
IkarusId const IKARUS_ID_NONE{0};
|
||||
/// \brief A special id used to indicate an optional id not being specified.
|
||||
IkarusId const IKARUS_ID_UNSPECIFIED{1};
|
||||
|
||||
/// \private \brief Generates a new id for the given object type.
|
||||
/// \param data The data from which the id will be constructed.
|
||||
/// \return The generated id.
|
||||
/// \pre data must be valid under the format described in Id. It should also point to an object in the database.
|
||||
IkarusId ikarus_id_from_data(int64_t data);
|
||||
|
||||
/// \brief Checkes whether two ids are equal
|
||||
/// \param left the left side of the comparison
|
||||
/// \param right the right side of the comparison
|
||||
/// \return True if the bits from the left id are equal to the bits of the right id
|
||||
bool ikarus_id_is_equal(IkarusId left, IkarusId right);
|
||||
|
||||
/// \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);
|
||||
|
||||
/// \brief Checks if the given id is IKARUS_ID_NONE.
|
||||
/// \param id The id to check.
|
||||
/// \return True if the id is IKARUS_ID_NONE, false otherwise.
|
||||
IKA_API bool ikarus_id_is_none(IkarusId id);
|
||||
|
||||
/// \brief Checks if the given id is IKARUS_ID_UNSPECIFIED.
|
||||
/// \param id The id to check.
|
||||
/// \return True if the id is IKARUS_ID_UNSPECIFIED, false otherwise.
|
||||
IKA_API bool ikarus_id_is_unspecified(IkarusId id);
|
||||
|
||||
/// @}
|
||||
|
||||
IKARUS_END_HEADER
|
||||
Loading…
Add table
Add a link
Reference in a new issue