Skip to content

Commit

Permalink
fix typo
Browse files Browse the repository at this point in the history
  • Loading branch information
oathdruid committed Oct 17, 2024
1 parent 377b09e commit 77cbd00
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 25 deletions.
2 changes: 0 additions & 2 deletions example/depend-use-cmake-find/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions src/babylon/application_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const Id*, ::std::string> 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;
}
}
Expand Down
26 changes: 16 additions & 10 deletions src/babylon/application_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
// 构造时需要给定必要的类型信息
Expand Down Expand Up @@ -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;

Expand All @@ -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;
};
Expand Down Expand Up @@ -588,15 +589,20 @@ 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&
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 <typename T>
ABSL_ATTRIBUTE_NOINLINE void
ApplicationContext::ComponentHolder::set_type() noexcept {
Expand Down Expand Up @@ -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(
Expand Down
11 changes: 6 additions & 5 deletions test/test_application_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand All @@ -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());
}
}

Expand All @@ -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());
}
}

Expand All @@ -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());
}
}

Expand All @@ -89,7 +90,7 @@ TEST_F(ApplicationContextTest,
ASSERT_TRUE(context.component_accessor<::std::vector<int>>("A"));
for (auto& holder : context) {
ASSERT_EQ("A", holder.name());
ASSERT_EQ(2, holder.accessable_path_number());
ASSERT_EQ(2, holder.accessible_path_number());
}
}

Expand Down

0 comments on commit 77cbd00

Please sign in to comment.