diff --git a/flecs.h b/flecs.h index f72e6bdc4f..8104e3478c 100644 --- a/flecs.h +++ b/flecs.h @@ -21570,7 +21570,7 @@ struct entity_view : public id { return m_id; } - /** Check is entity is valid. + /** Check if entity is valid. * * @return True if the entity is alive, false otherwise. */ @@ -21582,7 +21582,7 @@ struct entity_view : public id { return is_valid(); } - /** Check is entity is alive. + /** Check if entity is alive. * * @return True if the entity is alive, false otherwise. */ @@ -25874,6 +25874,16 @@ struct table { return static_cast(get(_::cpp_type::id(m_world))); } + /** Get pointer to component array by (enum) component. + * + * @tparam T The (enum) component. + * @return Pointer to the column, NULL if not found. + */ + template ::value > = 0> + T* get() const { + return static_cast(get(_::cpp_type::id(m_world))); + } + /** Get pointer to component array by component. * * @tparam T The component. diff --git a/include/flecs/addons/cpp/entity_view.hpp b/include/flecs/addons/cpp/entity_view.hpp index c190cc1f12..a41cf10168 100644 --- a/include/flecs/addons/cpp/entity_view.hpp +++ b/include/flecs/addons/cpp/entity_view.hpp @@ -51,7 +51,7 @@ struct entity_view : public id { return m_id; } - /** Check is entity is valid. + /** Check if entity is valid. * * @return True if the entity is alive, false otherwise. */ @@ -63,7 +63,7 @@ struct entity_view : public id { return is_valid(); } - /** Check is entity is alive. + /** Check if entity is alive. * * @return True if the entity is alive, false otherwise. */ diff --git a/include/flecs/addons/cpp/table.hpp b/include/flecs/addons/cpp/table.hpp index b96bdf39a9..c967c04959 100644 --- a/include/flecs/addons/cpp/table.hpp +++ b/include/flecs/addons/cpp/table.hpp @@ -228,6 +228,16 @@ struct table { return static_cast(get(_::cpp_type::id(m_world))); } + /** Get pointer to component array by (enum) component. + * + * @tparam T The (enum) component. + * @return Pointer to the column, NULL if not found. + */ + template ::value > = 0> + T* get() const { + return static_cast(get(_::cpp_type::id(m_world))); + } + /** Get pointer to component array by component. * * @tparam T The component. diff --git a/test/cpp_api/include/cpp_api.h b/test/cpp_api/include/cpp_api.h index ab35a402a7..d8fd73ba8b 100644 --- a/test/cpp_api/include/cpp_api.h +++ b/test/cpp_api/include/cpp_api.h @@ -30,6 +30,12 @@ struct Self { flecs::entity_view value; }; +enum Number { + One = 1, + Two = 2, + Three = 3 +}; + class Pod { public: struct Child { }; diff --git a/test/cpp_api/project.json b/test/cpp_api/project.json index 4aac59ca2c..35f00f41df 100644 --- a/test/cpp_api/project.json +++ b/test/cpp_api/project.json @@ -1319,6 +1319,7 @@ "has_pair_R_T", "get_id", "get_T", + "get_T_enum", "get_pair_r_t", "get_pair_R_t", "get_pair_R_T", diff --git a/test/cpp_api/src/Table.cpp b/test/cpp_api/src/Table.cpp index cb81461537..c3b2baf19d 100644 --- a/test/cpp_api/src/Table.cpp +++ b/test/cpp_api/src/Table.cpp @@ -663,3 +663,22 @@ void Table_iter_type(void) { } test_int(count, 2); } + +void Table_get_T_enum(void) { + flecs::world ecs; + + flecs::entity e = ecs.entity() + .set(Number::One); + ecs.entity() + .set(Number::Two); + ecs.entity() + .set(Number::Three); + + flecs::table table = e.table(); + + Number *n = table.get(); + test_assert(n != NULL); + test_int(n[0], Number::One); + test_int(n[1], Number::Two); + test_int(n[2], Number::Three); +} diff --git a/test/cpp_api/src/main.cpp b/test/cpp_api/src/main.cpp index 2a7755e097..1a75d8a641 100644 --- a/test/cpp_api/src/main.cpp +++ b/test/cpp_api/src/main.cpp @@ -1261,6 +1261,7 @@ void Table_has_pair_R_t(void); void Table_has_pair_R_T(void); void Table_get_id(void); void Table_get_T(void); +void Table_get_T_enum(void); void Table_get_pair_r_t(void); void Table_get_pair_R_t(void); void Table_get_pair_R_T(void); @@ -6155,6 +6156,10 @@ bake_test_case Table_testcases[] = { "get_T", Table_get_T }, + { + "get_T_enum", + Table_get_T_enum + }, { "get_pair_r_t", Table_get_pair_r_t @@ -6411,7 +6416,7 @@ static bake_test_suite suites[] = { "Table", NULL, NULL, - 31, + 32, Table_testcases }, {