@@ -16495,14 +16495,27 @@ struct entity_view : public id {
16495
16495
* @tparam R the relation type.
16496
16496
* @param object the object.
16497
16497
*/
16498
- template<typename R>
16499
- const R* get(flecs::id_t object) const {
16498
+ template<typename R, typename O, if_not_t< is_enum<O>::value> = 0 >
16499
+ const R* get(O object) const {
16500
16500
auto comp_id = _::cpp_type<R>::id(m_world);
16501
16501
ecs_assert(_::cpp_type<R>::size() != 0, ECS_INVALID_PARAMETER, NULL);
16502
16502
return static_cast<const R*>(
16503
16503
ecs_get_id(m_world, m_id, ecs_pair(comp_id, object)));
16504
16504
}
16505
16505
16506
+ /** Get a pair.
16507
+ * This operation gets the value for a pair from the entity.
16508
+ *
16509
+ * @tparam R the relation type.
16510
+ * @param constant the enum constant.
16511
+ */
16512
+ template<typename R, typename O, if_t< is_enum<O>::value> = 0>
16513
+ const R* get(O constant) const {
16514
+ const auto& et = enum_type<O>(this->m_world);
16515
+ flecs::entity_t object = et.entity(constant);
16516
+ return get<R>(object);
16517
+ }
16518
+
16506
16519
/** Get component value (untyped).
16507
16520
*
16508
16521
* @param comp The component to get.
@@ -16683,16 +16696,29 @@ struct entity_view : public id {
16683
16696
16684
16697
/** Check if entity has the provided pair.
16685
16698
*
16686
- * @tparam Relation The relation type.
16699
+ * @tparam R The relation type.
16687
16700
* @param object The object.
16688
16701
* @return True if the entity has the provided component, false otherwise.
16689
16702
*/
16690
- template <typename Relation >
16691
- bool has(flecs::id_t object) const {
16692
- auto comp_id = _::cpp_type<Relation >::id(m_world);
16703
+ template<typename R, typename O, if_not_t< is_enum<O>::value > = 0 >
16704
+ bool has(O object) const {
16705
+ auto comp_id = _::cpp_type<R >::id(m_world);
16693
16706
return ecs_has_id(m_world, m_id, ecs_pair(comp_id, object));
16694
16707
}
16695
16708
16709
+ /** Check if entity has the provided pair.
16710
+ *
16711
+ * @tparam R The relation type.
16712
+ * @param value The enum constant.
16713
+ * @return True if the entity has the provided component, false otherwise.
16714
+ */
16715
+ template<typename R, typename E, if_t< is_enum<E>::value > = 0>
16716
+ bool has(E value) const {
16717
+ const auto& et = enum_type<E>(this->m_world);
16718
+ flecs::entity_t object = et.entity(value);
16719
+ return has<R>(object);
16720
+ }
16721
+
16696
16722
/** Check if entity has the provided pair.
16697
16723
*
16698
16724
* @param relation The relation.
@@ -16951,8 +16977,8 @@ struct entity_builder : entity_view {
16951
16977
/** Add a pair.
16952
16978
* This operation adds a pair to the entity.
16953
16979
*
16954
- * @param relation The relation id .
16955
- * @param object The object id .
16980
+ * @param relation The relation.
16981
+ * @param object The object.
16956
16982
*/
16957
16983
Self& add(entity_t relation, entity_t object) {
16958
16984
ecs_add_pair(this->m_world, this->m_id, relation, object);
@@ -16962,8 +16988,8 @@ struct entity_builder : entity_view {
16962
16988
/** Add a pair.
16963
16989
* This operation adds a pair to the entity.
16964
16990
*
16965
- * @tparam R the relation type.
16966
- * @tparam O the object type.
16991
+ * @tparam R The relation type
16992
+ * @tparam O The object type.
16967
16993
*/
16968
16994
template<typename R, typename O>
16969
16995
Self& add() {
@@ -16973,27 +16999,43 @@ struct entity_builder : entity_view {
16973
16999
/** Add a pair.
16974
17000
* This operation adds a pair to the entity.
16975
17001
*
16976
- * @tparam R the relation type.
16977
- * @param object the object type .
17002
+ * @tparam R The relation type
17003
+ * @param object The object.
16978
17004
*/
16979
- template<typename R>
16980
- Self& add(entity_t object) {
17005
+ template<typename R, typename O, if_not_t< is_enum<O>::value > = 0 >
17006
+ Self& add(O object) {
16981
17007
flecs_static_assert(is_flecs_constructible<R>::value,
16982
- "cannot default construct type: add T::T() or use emplace<T>()");
17008
+ "cannot default construct type: add T::T() or use emplace<T>()");
16983
17009
return this->add(_::cpp_type<R>::id(this->m_world), object);
16984
17010
}
16985
17011
17012
+ /** Add a pair.
17013
+ * This operation adds a pair to the entity that consists out of a tag
17014
+ * combined with an enum constant.
17015
+ *
17016
+ * @tparam R The relation type
17017
+ * @param constant the enum constant.
17018
+ */
17019
+ template<typename R, typename O, if_t< is_enum<O>::value > = 0>
17020
+ Self& add(O constant) {
17021
+ flecs_static_assert(is_flecs_constructible<R>::value,
17022
+ "cannot default construct type: add T::T() or use emplace<T>()");
17023
+ const auto& et = enum_type<O>(this->m_world);
17024
+ flecs::entity_t object = et.entity(constant);
17025
+ return this->add<R>(object);
17026
+ }
17027
+
16986
17028
/** Shortcut for add(IsA, obj).
16987
17029
*
16988
- * @param object the object id .
17030
+ * @param object The object.
16989
17031
*/
16990
17032
Self& is_a(entity_t object) {
16991
17033
return this->add(flecs::IsA, object);
16992
17034
}
16993
17035
16994
17036
/** Shortcut for add(IsA, obj).
16995
17037
*
16996
- * @tparam T the type associated with the object .
17038
+ * @tparam T the type associated with the O .
16997
17039
*/
16998
17040
template <typename T>
16999
17041
Self& is_a() {
@@ -17002,27 +17044,27 @@ struct entity_builder : entity_view {
17002
17044
17003
17045
/** Shortcut for add(ChildOf, obj).
17004
17046
*
17005
- * @param object the object id .
17047
+ * @param object The object.
17006
17048
*/
17007
17049
Self& child_of(entity_t object) {
17008
17050
return this->add(flecs::ChildOf, object);
17009
17051
}
17010
17052
17011
17053
/** Shortcut for add(ChildOf, obj).
17012
17054
*
17013
- * @tparam T the type associated with the object .
17055
+ * @tparam T the type associated with the O .
17014
17056
*/
17015
17057
template <typename T>
17016
17058
Self& child_of() {
17017
17059
return this->add(flecs::ChildOf, _::cpp_type<T>::id(this->m_world));
17018
17060
}
17019
17061
17020
- /** Add a pair with object type.
17021
- * This operation adds a pair to the entity. The relation part of the pair
17062
+ /** Add a pair with O type.
17063
+ * This operation adds a pair to the entity. The R part of the pair
17022
17064
* should not be a component.
17023
17065
*
17024
- * @param relation the relation type .
17025
- * @tparam O the object type.
17066
+ * @param relation The relation.
17067
+ * @tparam O The object type.
17026
17068
*/
17027
17069
template<typename O>
17028
17070
Self& add_w_object(entity_t relation) {
@@ -17053,8 +17095,8 @@ struct entity_builder : entity_view {
17053
17095
/** Remove a pair.
17054
17096
* This operation removes a pair from the entity.
17055
17097
*
17056
- * @param relation The relation id .
17057
- * @param object The object id .
17098
+ * @param relation The relation.
17099
+ * @param object The object.
17058
17100
*/
17059
17101
Self& remove(entity_t relation, entity_t object) {
17060
17102
ecs_remove_pair(this->m_world, this->m_id, relation, object);
@@ -17064,34 +17106,47 @@ struct entity_builder : entity_view {
17064
17106
/** Removes a pair.
17065
17107
* This operation removes a pair from the entity.
17066
17108
*
17067
- * @tparam Relation the relation type.
17068
- * @tparam Object the object type.
17109
+ * @tparam R The relation type
17110
+ * @tparam O The object type.
17069
17111
*/
17070
- template<typename Relation , typename Object >
17112
+ template<typename R , typename O >
17071
17113
Self& remove() {
17072
- return this->remove<Relation >(_::cpp_type<Object >::id(this->m_world));
17114
+ return this->remove<R >(_::cpp_type<O >::id(this->m_world));
17073
17115
}
17074
17116
17075
17117
/** Remove a pair.
17076
17118
* This operation adds a pair to the entity.
17077
17119
*
17078
- * @tparam Relation the relation type.
17079
- * @param object the object type.
17120
+ * @tparam R The relation type
17121
+ * @param object The object.
17122
+ */
17123
+ template<typename R, typename O, if_not_t< is_enum<O>::value > = 0>
17124
+ Self& remove(O object) {
17125
+ return this->remove(_::cpp_type<R>::id(this->m_world), object);
17126
+ }
17127
+
17128
+ /** Remove a pair.
17129
+ * This operation adds a pair to the entity.
17130
+ *
17131
+ * @tparam R The relation type
17132
+ * @param constant the enum constant.
17080
17133
*/
17081
- template<typename Relation>
17082
- Self& remove(entity_t object) {
17083
- return this->remove(_::cpp_type<Relation>::id(this->m_world), object);
17134
+ template<typename R, typename O, if_t< is_enum<O>::value > = 0>
17135
+ Self& remove(O constant) {
17136
+ const auto& et = enum_type<O>(this->m_world);
17137
+ flecs::entity_t object = et.entity(constant);
17138
+ return this->remove<R>(object);
17084
17139
}
17085
17140
17086
- /** Removes a pair with object type.
17141
+ /** Removes a pair with O type.
17087
17142
* This operation removes a pair from the entity.
17088
17143
*
17089
- * @param relation the relation type .
17090
- * @tparam Object the object type.
17144
+ * @param relation The relation.
17145
+ * @tparam O The object type.
17091
17146
*/
17092
- template<typename Object >
17147
+ template<typename O >
17093
17148
Self& remove_w_object(entity_t relation) {
17094
- return this->remove(relation, _::cpp_type<Object >::id(this->m_world));
17149
+ return this->remove(relation, _::cpp_type<O >::id(this->m_world));
17095
17150
}
17096
17151
17097
17152
/** Add owned flag for component (forces ownership when instantiating)
@@ -17133,7 +17188,7 @@ struct entity_builder : entity_view {
17133
17188
this->override<T>();
17134
17189
this->set<T>(val);
17135
17190
return to_base();
17136
- }
17191
+ }
17137
17192
17138
17193
/** Add a switch to an entity by id.
17139
17194
* The switch entity must be a type, that is it must have the EcsType
@@ -17244,10 +17299,10 @@ struct entity_builder : entity_view {
17244
17299
*/
17245
17300
template <typename E, if_t< is_enum<E>::value > = 0>
17246
17301
Self& add(E value) {
17247
- flecs::entity_t r = _::cpp_type<E>::id(this->m_world);
17302
+ flecs::entity_t relation = _::cpp_type<E>::id(this->m_world);
17248
17303
const auto& et = enum_type<E>(this->m_world);
17249
- flecs::entity_t o = et.entity(value);
17250
- return this->add(r, o );
17304
+ flecs::entity_t object = et.entity(value);
17305
+ return this->add(relation, object );
17251
17306
}
17252
17307
17253
17308
/** Remove pair for enum.
@@ -17257,8 +17312,8 @@ struct entity_builder : entity_view {
17257
17312
*/
17258
17313
template <typename E, if_t< is_enum<E>::value > = 0>
17259
17314
Self& remove() {
17260
- flecs::entity_t r = _::cpp_type<E>::id(this->m_world);
17261
- return this->remove(r , flecs::Wildcard);
17315
+ flecs::entity_t relation = _::cpp_type<E>::id(this->m_world);
17316
+ return this->remove(relation , flecs::Wildcard);
17262
17317
}
17263
17318
17264
17319
/** Enable an entity.
@@ -17367,11 +17422,11 @@ struct entity_builder : entity_view {
17367
17422
}
17368
17423
17369
17424
/** Set a pair for an entity.
17370
- * This operation sets the pair value, and uses the relation as type. If the
17425
+ * This operation sets the pair value, and uses the R as type. If the
17371
17426
* entity did not yet have the pair, it will be added.
17372
17427
*
17373
- * @tparam R The relation part of the pair .
17374
- * @tparam O The object part of the pair .
17428
+ * @tparam R The relation type .
17429
+ * @tparam O The object type .
17375
17430
* @param value The value to set.
17376
17431
*/
17377
17432
template <typename R, typename O, typename P = pair<R, O>,
@@ -17382,27 +17437,42 @@ struct entity_builder : entity_view {
17382
17437
}
17383
17438
17384
17439
/** Set a pair for an entity.
17385
- * This operation sets the pair value, and uses the relation as type. If the
17440
+ * This operation sets the pair value, and uses the R as type. If the
17386
17441
* entity did not yet have the pair, it will be added.
17387
17442
*
17388
- * @tparam R The relation part of the pair .
17389
- * @param object The object part of the pair .
17443
+ * @tparam R The relation type .
17444
+ * @param object The object.
17390
17445
* @param value The value to set.
17391
17446
*/
17392
- template <typename R>
17393
- Self& set(entity_t object, const R& value) {
17447
+ template <typename R, typename O, if_not_t< is_enum<O>::value > = 0 >
17448
+ Self& set(O object, const R& value) {
17394
17449
auto relation = _::cpp_type<R>::id(this->m_world);
17395
17450
flecs::set(this->m_world, this->m_id, value,
17396
17451
ecs_pair(relation, object));
17397
17452
return to_base();
17398
17453
}
17399
17454
17400
17455
/** Set a pair for an entity.
17401
- * This operation sets the pair value, and uses the relation as type. If the
17456
+ * This operation sets the pair value, and uses the R as type. If the
17457
+ * entity did not yet have the pair, it will be added.
17458
+ *
17459
+ * @tparam R The relation type.
17460
+ * @param constant The enum constant.
17461
+ * @param value The value to set.
17462
+ */
17463
+ template <typename R, typename O, if_t< is_enum<O>::value > = 0>
17464
+ Self& set(O constant, const R& value) {
17465
+ const auto& et = enum_type<O>(this->m_world);
17466
+ flecs::entity_t object = et.entity(constant);
17467
+ return set<R>(object, value);
17468
+ }
17469
+
17470
+ /** Set a pair for an entity.
17471
+ * This operation sets the pair value, and uses the R as type. If the
17402
17472
* entity did not yet have the pair, it will be added.
17403
17473
*
17404
- * @tparam O The object part of the pair .
17405
- * @param relation The relation part of the pair .
17474
+ * @tparam O The object type .
17475
+ * @param relation The relation.
17406
17476
* @param value The value to set.
17407
17477
*/
17408
17478
template <typename O>
@@ -17439,7 +17509,7 @@ struct entity_builder : entity_view {
17439
17509
17440
17510
/** Emplace component.
17441
17511
* Emplace constructs a component in the storage, which prevents calling the
17442
- * destructor on the object passed into the function.
17512
+ * destructor on the O passed into the function.
17443
17513
*
17444
17514
* Emplace attempts the following signatures to construct the component:
17445
17515
* T{Args...}
@@ -17474,25 +17544,25 @@ struct entity_builder : entity_view {
17474
17544
return to_base();
17475
17545
}
17476
17546
17477
- /** Entities created in function will have (Relation , this)
17547
+ /** Entities created in function will have (relation , this)
17478
17548
* This operation is thread safe.
17479
17549
*
17480
- * @tparam Relation The relation to use.
17550
+ * @tparam R The R to use.
17481
17551
* @param func The function to call.
17482
17552
*/
17483
- template <typename Relation , typename Func>
17553
+ template <typename R , typename Func>
17484
17554
Self& with(const Func& func) {
17485
- with(_::cpp_type<Relation >::id(this->m_world), func);
17555
+ with(_::cpp_type<R >::id(this->m_world), func);
17486
17556
return to_base();
17487
17557
}
17488
17558
17489
17559
/** Entities created in function will have (relation, this)
17490
17560
*
17491
- * @param relation The relation to use .
17561
+ * @param relation The relation.
17492
17562
* @param func The function to call.
17493
17563
*/
17494
17564
template <typename Func>
17495
- Self& with(id_t relation, const Func& func) {
17565
+ Self& with(entity_t relation, const Func& func) {
17496
17566
ecs_id_t prev = ecs_set_with(this->m_world,
17497
17567
ecs_pair(relation, this->m_id));
17498
17568
func();
0 commit comments