Skip to content

Commit

Permalink
#1401 Add UUIDs to doc addon
Browse files Browse the repository at this point in the history
* Add support for UUID doc strings

* Add UUID doc functions to C++ API
  • Loading branch information
SanderMertens authored Oct 16, 2024
1 parent 2bf5eb3 commit 8bd9a36
Show file tree
Hide file tree
Showing 15 changed files with 300 additions and 9 deletions.
28 changes: 27 additions & 1 deletion distr/flecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -17753,13 +17753,17 @@ const ecs_entity_t EcsDocBrief = FLECS_HI_COMPONENT_ID + 114;
const ecs_entity_t EcsDocDetail = FLECS_HI_COMPONENT_ID + 115;
const ecs_entity_t EcsDocLink = FLECS_HI_COMPONENT_ID + 116;
const ecs_entity_t EcsDocColor = FLECS_HI_COMPONENT_ID + 117;
const ecs_entity_t EcsDocUuid = FLECS_HI_COMPONENT_ID + 118;
#endif

/* REST module components */
#ifdef FLECS_REST
const ecs_entity_t ecs_id(EcsRest) = FLECS_HI_COMPONENT_ID + 118;
const ecs_entity_t ecs_id(EcsRest) = FLECS_HI_COMPONENT_ID + 119;
#endif

/* Max static id:
* #define EcsFirstUserEntityId (FLECS_HI_COMPONENT_ID + 128) */

/* Default lookup path */
static ecs_entity_t ecs_default_lookup_path[2] = { 0, 0 };

Expand Down Expand Up @@ -20800,6 +20804,14 @@ void flecs_doc_set(
}
}

void ecs_doc_set_uuid(
ecs_world_t *world,
ecs_entity_t entity,
const char *name)
{
flecs_doc_set(world, entity, EcsDocUuid, name);
}

void ecs_doc_set_name(
ecs_world_t *world,
ecs_entity_t entity,
Expand Down Expand Up @@ -20840,6 +20852,19 @@ void ecs_doc_set_color(
flecs_doc_set(world, entity, EcsDocColor, color);
}

const char* ecs_doc_get_uuid(
const ecs_world_t *world,
ecs_entity_t entity)
{
const EcsDocDescription *ptr = ecs_get_pair(
world, entity, EcsDocDescription, EcsDocUuid);
if (ptr) {
return ptr->value;
} else {
return NULL;
}
}

const char* ecs_doc_get_name(
const ecs_world_t *world,
ecs_entity_t entity)
Expand Down Expand Up @@ -21002,6 +21027,7 @@ void FlecsDocImport(
ecs_set_name_prefix(world, "EcsDoc");

flecs_bootstrap_component(world, EcsDocDescription);
flecs_bootstrap_tag(world, EcsDocUuid);
flecs_bootstrap_tag(world, EcsDocBrief);
flecs_bootstrap_tag(world, EcsDocDetail);
flecs_bootstrap_tag(world, EcsDocLink);
Expand Down
95 changes: 93 additions & 2 deletions distr/flecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -14673,6 +14673,11 @@ extern "C" {

FLECS_API extern const ecs_entity_t ecs_id(EcsDocDescription); /**< Component id for EcsDocDescription. */

/** Tag for adding a UUID to entities.
* Added to an entity as (EcsDocDescription, EcsUuid) by ecs_doc_set_uuid().
*/
FLECS_API extern const ecs_entity_t EcsDocUuid;

/** Tag for adding brief descriptions to entities.
* Added to an entity as (EcsDocDescription, EcsBrief) by ecs_doc_set_brief().
*/
Expand Down Expand Up @@ -14705,6 +14710,23 @@ typedef struct EcsDocDescription {
char *value;
} EcsDocDescription;

/** Add UUID to entity.
* Associate entity with an (external) UUID.
*
* @param world The world.
* @param entity The entity to which to add the UUID.
* @param uuid The UUID to add.
*
* @see ecs_doc_get_uuid()
* @see flecs::doc::set_uuid()
* @see flecs::entity_builder::set_doc_uuid()
*/
FLECS_API
void ecs_doc_set_uuid(
ecs_world_t *world,
ecs_entity_t entity,
const char *uuid);

/** Add human-readable name to entity.
* Contrary to entity names, human readable names do not have to be unique and
* can contain special characters used in the query language like '*'.
Expand Down Expand Up @@ -14788,6 +14810,20 @@ void ecs_doc_set_color(
ecs_entity_t entity,
const char *color);

/** Get UUID from entity.
* @param world The world.
* @param entity The entity from which to get the UUID.
* @return The UUID.
*
* @see ecs_doc_set_uuid()
* @see flecs::doc::get_uuid()
* @see flecs::entity_view::get_doc_uuid()
*/
FLECS_API
const char* ecs_doc_get_uuid(
const ecs_world_t *world,
ecs_entity_t entity);

/** Get human readable name from entity.
* If entity does not have an explicit human readable name, this operation will
* return the entity name.
Expand Down Expand Up @@ -18484,6 +18520,9 @@ namespace doc {
/** flecs.doc.Description component */
using Description = EcsDocDescription;

/** flecs.doc.Uuid component */
static const flecs::entity_t Uuid = EcsDocUuid;

/** flecs.doc.Brief component */
static const flecs::entity_t Brief = EcsDocBrief;

Expand Down Expand Up @@ -23905,6 +23944,19 @@ const char* doc_color() const {
return ecs_doc_get_color(world_, id_);
}

/** Get UUID.
*
* @see ecs_doc_get_uuid()
* @see flecs::doc::get_uuid()
* @see flecs::entity_builder::set_doc_uuid()
*
* @memberof flecs::entity_view
* @ingroup cpp_addons_doc
*/
const char* doc_uuid() const {
return ecs_doc_get_uuid(world_, id_);
}

# endif
# ifdef FLECS_ALERTS
/**
Expand Down Expand Up @@ -25099,8 +25151,23 @@ const Self& set_doc_link(const char *link) const {
* @memberof flecs::entity_builder
* @ingroup cpp_addons_doc
*/
const Self& set_doc_color(const char *link) const {
ecs_doc_set_color(world_, id_, link);
const Self& set_doc_color(const char *color) const {
ecs_doc_set_color(world_, id_, color);
return to_base();
}

/** Set doc UUID.
* This adds `(flecs.doc.Description, flecs.doc.Uuid)` to the entity.
*
* @see ecs_doc_set_uuid()
* @see flecs::doc::set_uuid()
* @see flecs::entity_view::doc_uuid()
*
* @memberof flecs::entity_builder
* @ingroup cpp_addons_doc
*/
const Self& set_doc_uuid(const char *uuid) const {
ecs_doc_set_uuid(world_, id_, uuid);
return to_base();
}

Expand Down Expand Up @@ -31398,6 +31465,18 @@ inline void timer_init(flecs::world& world) {
namespace flecs {
namespace doc {

/** Get UUID for an entity.
*
* @see ecs_doc_get_uuid()
* @see flecs::doc::set_uuid()
* @see flecs::entity_view::doc_uuid()
*
* @ingroup cpp_addons_doc
*/
inline const char* get_uuid(const flecs::entity_view& e) {
return ecs_doc_get_uuid(e.world(), e);
}

/** Get human readable name for an entity.
*
* @see ecs_doc_get_name()
Expand Down Expand Up @@ -31458,6 +31537,18 @@ inline const char* get_color(const flecs::entity_view& e) {
return ecs_doc_get_color(e.world(), e);
}

/** Set UUID for an entity.
*
* @see ecs_doc_set_uuid()
* @see flecs::doc::get_uuid()
* @see flecs::entity_builder::set_doc_uuid()
*
* @ingroup cpp_addons_doc
*/
inline void set_uuid(flecs::entity& e, const char *uuid) {
ecs_doc_set_uuid(e.world(), e, uuid);
}

/** Set human readable name for an entity.
*
* @see ecs_doc_set_name()
Expand Down
3 changes: 3 additions & 0 deletions include/flecs/addons/cpp/mixins/doc/decl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ namespace doc {
/** flecs.doc.Description component */
using Description = EcsDocDescription;

/** flecs.doc.Uuid component */
static const flecs::entity_t Uuid = EcsDocUuid;

/** flecs.doc.Brief component */
static const flecs::entity_t Brief = EcsDocBrief;

Expand Down
19 changes: 17 additions & 2 deletions include/flecs/addons/cpp/mixins/doc/entity_builder.inl
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,22 @@ const Self& set_doc_link(const char *link) const {
* @memberof flecs::entity_builder
* @ingroup cpp_addons_doc
*/
const Self& set_doc_color(const char *link) const {
ecs_doc_set_color(world_, id_, link);
const Self& set_doc_color(const char *color) const {
ecs_doc_set_color(world_, id_, color);
return to_base();
}

/** Set doc UUID.
* This adds `(flecs.doc.Description, flecs.doc.Uuid)` to the entity.
*
* @see ecs_doc_set_uuid()
* @see flecs::doc::set_uuid()
* @see flecs::entity_view::doc_uuid()
*
* @memberof flecs::entity_builder
* @ingroup cpp_addons_doc
*/
const Self& set_doc_uuid(const char *uuid) const {
ecs_doc_set_uuid(world_, id_, uuid);
return to_base();
}
13 changes: 13 additions & 0 deletions include/flecs/addons/cpp/mixins/doc/entity_view.inl
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,16 @@ const char* doc_link() const {
const char* doc_color() const {
return ecs_doc_get_color(world_, id_);
}

/** Get UUID.
*
* @see ecs_doc_get_uuid()
* @see flecs::doc::get_uuid()
* @see flecs::entity_builder::set_doc_uuid()
*
* @memberof flecs::entity_view
* @ingroup cpp_addons_doc
*/
const char* doc_uuid() const {
return ecs_doc_get_uuid(world_, id_);
}
24 changes: 24 additions & 0 deletions include/flecs/addons/cpp/mixins/doc/impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@
namespace flecs {
namespace doc {

/** Get UUID for an entity.
*
* @see ecs_doc_get_uuid()
* @see flecs::doc::set_uuid()
* @see flecs::entity_view::doc_uuid()
*
* @ingroup cpp_addons_doc
*/
inline const char* get_uuid(const flecs::entity_view& e) {
return ecs_doc_get_uuid(e.world(), e);
}

/** Get human readable name for an entity.
*
* @see ecs_doc_get_name()
Expand Down Expand Up @@ -68,6 +80,18 @@ inline const char* get_color(const flecs::entity_view& e) {
return ecs_doc_get_color(e.world(), e);
}

/** Set UUID for an entity.
*
* @see ecs_doc_set_uuid()
* @see flecs::doc::get_uuid()
* @see flecs::entity_builder::set_doc_uuid()
*
* @ingroup cpp_addons_doc
*/
inline void set_uuid(flecs::entity& e, const char *uuid) {
ecs_doc_set_uuid(e.world(), e, uuid);
}

/** Set human readable name for an entity.
*
* @see ecs_doc_set_name()
Expand Down
36 changes: 36 additions & 0 deletions include/flecs/addons/doc.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ extern "C" {

FLECS_API extern const ecs_entity_t ecs_id(EcsDocDescription); /**< Component id for EcsDocDescription. */

/** Tag for adding a UUID to entities.
* Added to an entity as (EcsDocDescription, EcsUuid) by ecs_doc_set_uuid().
*/
FLECS_API extern const ecs_entity_t EcsDocUuid;

/** Tag for adding brief descriptions to entities.
* Added to an entity as (EcsDocDescription, EcsBrief) by ecs_doc_set_brief().
*/
Expand Down Expand Up @@ -63,6 +68,23 @@ typedef struct EcsDocDescription {
char *value;
} EcsDocDescription;

/** Add UUID to entity.
* Associate entity with an (external) UUID.
*
* @param world The world.
* @param entity The entity to which to add the UUID.
* @param uuid The UUID to add.
*
* @see ecs_doc_get_uuid()
* @see flecs::doc::set_uuid()
* @see flecs::entity_builder::set_doc_uuid()
*/
FLECS_API
void ecs_doc_set_uuid(
ecs_world_t *world,
ecs_entity_t entity,
const char *uuid);

/** Add human-readable name to entity.
* Contrary to entity names, human readable names do not have to be unique and
* can contain special characters used in the query language like '*'.
Expand Down Expand Up @@ -146,6 +168,20 @@ void ecs_doc_set_color(
ecs_entity_t entity,
const char *color);

/** Get UUID from entity.
* @param world The world.
* @param entity The entity from which to get the UUID.
* @return The UUID.
*
* @see ecs_doc_set_uuid()
* @see flecs::doc::get_uuid()
* @see flecs::entity_view::get_doc_uuid()
*/
FLECS_API
const char* ecs_doc_get_uuid(
const ecs_world_t *world,
ecs_entity_t entity);

/** Get human readable name from entity.
* If entity does not have an explicit human readable name, this operation will
* return the entity name.
Expand Down
Loading

0 comments on commit 8bd9a36

Please sign in to comment.