From 77cbd0038c06ed23e203acf5c8bb30fa006be7b7 Mon Sep 17 00:00:00 2001 From: Kevin Li Date: Thu, 17 Oct 2024 18:37:52 +0800 Subject: [PATCH] fix typo --- example/depend-use-cmake-find/build.sh | 2 -- src/babylon/application_context.cpp | 16 ++++++++-------- src/babylon/application_context.h | 26 ++++++++++++++++---------- test/test_application_context.cpp | 11 ++++++----- 4 files changed, 30 insertions(+), 25 deletions(-) diff --git a/example/depend-use-cmake-find/build.sh b/example/depend-use-cmake-find/build.sh index 148b376..2106045 100755 --- a/example/depend-use-cmake-find/build.sh +++ b/example/depend-use-cmake-find/build.sh @@ -11,8 +11,6 @@ rm -rf $NAME babylon tar xzf $NAME.tar.gz mv $NAME babylon -sudo apt install googletest - cd babylon cmake -Bbuild -DCMAKE_INSTALL_PREFIX=$PWD/output -DBUILD_TESTING=OFF cmake --build build diff --git a/src/babylon/application_context.cpp b/src/babylon/application_context.cpp index 3d8e44e..b97ad82 100644 --- a/src/babylon/application_context.cpp +++ b/src/babylon/application_context.cpp @@ -49,24 +49,24 @@ void ApplicationContext::register_component( pholder->for_each_type([&](const Id* type) { { auto result = _holder_by_type.emplace(type, pholder); - // Find one type only accessable path + // Find one type only accessible path if (result.second) { - pholder->increase_accessable_path(); + pholder->increase_accessible_path(); } else if (result.first->second) { - // Remove one type only accessable path - result.first->second->decrease_accessable_path(); + // Remove one type only accessible path + result.first->second->decrease_accessible_path(); result.first->second = nullptr; } } if (!name.empty()) { ::std::tuple key {type, name}; auto result = _holder_by_type_and_name.emplace(key, pholder); - // Find one type name accessable path + // Find one type name accessible path if (result.second) { - pholder->increase_accessable_path(); + pholder->increase_accessible_path(); } else if (result.first->second) { - // Remove one type name only accessable path - result.first->second->decrease_accessable_path(); + // Remove one type name only accessible path + result.first->second->decrease_accessible_path(); result.first->second = nullptr; } } diff --git a/src/babylon/application_context.h b/src/babylon/application_context.h index ff3fb8b..c203cb1 100644 --- a/src/babylon/application_context.h +++ b/src/babylon/application_context.h @@ -170,9 +170,10 @@ class ApplicationContext::ComponentHolder { // How many paths exist to access this component by type or name. // Use to detect orphan component cause by type and name conflict. - inline size_t accessable_path_number() const noexcept; + inline size_t accessible_path_number() const noexcept; inline const ::std::string& name() const noexcept; + inline const Id* type_id() const noexcept; protected: // 构造时需要给定必要的类型信息 @@ -293,8 +294,8 @@ class ApplicationContext::ComponentHolder { int>::type = 0> static int initialize(Any&, ApplicationContext&, const Any&) noexcept; - inline void increase_accessable_path() noexcept; - inline void decrease_accessable_path() noexcept; + inline void increase_accessible_path() noexcept; + inline void decrease_accessible_path() noexcept; inline void set_name(StringView name) noexcept; @@ -309,7 +310,7 @@ class ApplicationContext::ComponentHolder { SingletonState _singleton_state {SingletonState::UNINITIALIZED}; Any _singleton; size_t _sequence {0}; - size_t _accessable_path {0}; + size_t _accessible_path {0}; friend ApplicationContext; }; @@ -588,8 +589,8 @@ ApplicationContext::ComponentHolder::sequence() const noexcept { } inline ABSL_ATTRIBUTE_ALWAYS_INLINE size_t -ApplicationContext::ComponentHolder::accessable_path_number() const noexcept { - return _accessable_path; +ApplicationContext::ComponentHolder::accessible_path_number() const noexcept { + return _accessible_path; } inline ABSL_ATTRIBUTE_ALWAYS_INLINE const ::std::string& @@ -597,6 +598,11 @@ ApplicationContext::ComponentHolder::name() const noexcept { return _name; } +inline ABSL_ATTRIBUTE_ALWAYS_INLINE const Id* +ApplicationContext::ComponentHolder::type_id() const noexcept { + return &(_type_id->type_id); +} + template ABSL_ATTRIBUTE_NOINLINE void ApplicationContext::ComponentHolder::set_type() noexcept { @@ -711,13 +717,13 @@ ABSL_ATTRIBUTE_NOINLINE int ApplicationContext::ComponentHolder::initialize( } inline void -ApplicationContext::ComponentHolder::increase_accessable_path() noexcept { - _accessable_path++; +ApplicationContext::ComponentHolder::increase_accessible_path() noexcept { + _accessible_path++; } inline void -ApplicationContext::ComponentHolder::decrease_accessable_path() noexcept { - _accessable_path--; +ApplicationContext::ComponentHolder::decrease_accessible_path() noexcept { + _accessible_path--; } inline void ApplicationContext::ComponentHolder::set_name( diff --git a/test/test_application_context.cpp b/test/test_application_context.cpp index f70b4cf..0c5efc2 100644 --- a/test/test_application_context.cpp +++ b/test/test_application_context.cpp @@ -30,7 +30,8 @@ TEST_F(ApplicationContextTest, get_component_after_register) { context.register_component(DefaultComponentHolder<::std::string>::create()); ASSERT_TRUE(context.component_accessor<::std::string>()); for (auto& holder : context) { - ASSERT_EQ(1, holder.accessable_path_number()); + ASSERT_EQ(&::babylon::TypeId<::std::string>::ID, holder.type_id()); + ASSERT_EQ(1, holder.accessible_path_number()); } } @@ -41,7 +42,7 @@ TEST_F(ApplicationContextTest, context.register_component(DefaultComponentHolder<::std::string>::create()); ASSERT_FALSE(context.component_accessor<::std::string>()); for (auto& holder : context) { - ASSERT_EQ(0, holder.accessable_path_number()); + ASSERT_EQ(0, holder.accessible_path_number()); } } @@ -57,7 +58,7 @@ TEST_F(ApplicationContextTest, ASSERT_TRUE(context.component_accessor<::std::string>("B")); ASSERT_FALSE(context.component_accessor<::std::string>("C")); for (auto& holder : context) { - ASSERT_EQ(1, holder.accessable_path_number()); + ASSERT_EQ(1, holder.accessible_path_number()); } } @@ -71,7 +72,7 @@ TEST_F(ApplicationContextTest, ASSERT_FALSE(context.component_accessor<::std::string>()); ASSERT_FALSE(context.component_accessor<::std::string>("A")); for (auto& holder : context) { - ASSERT_EQ(0, holder.accessable_path_number()); + ASSERT_EQ(0, holder.accessible_path_number()); } } @@ -89,7 +90,7 @@ TEST_F(ApplicationContextTest, ASSERT_TRUE(context.component_accessor<::std::vector>("A")); for (auto& holder : context) { ASSERT_EQ("A", holder.name()); - ASSERT_EQ(2, holder.accessable_path_number()); + ASSERT_EQ(2, holder.accessible_path_number()); } }