Skip to content

Commit 77cbd00

Browse files
committed
fix typo
1 parent 377b09e commit 77cbd00

File tree

4 files changed

+30
-25
lines changed

4 files changed

+30
-25
lines changed

example/depend-use-cmake-find/build.sh

-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ rm -rf $NAME babylon
1111
tar xzf $NAME.tar.gz
1212
mv $NAME babylon
1313

14-
sudo apt install googletest
15-
1614
cd babylon
1715
cmake -Bbuild -DCMAKE_INSTALL_PREFIX=$PWD/output -DBUILD_TESTING=OFF
1816
cmake --build build

src/babylon/application_context.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,24 @@ void ApplicationContext::register_component(
4949
pholder->for_each_type([&](const Id* type) {
5050
{
5151
auto result = _holder_by_type.emplace(type, pholder);
52-
// Find one type only accessable path
52+
// Find one type only accessible path
5353
if (result.second) {
54-
pholder->increase_accessable_path();
54+
pholder->increase_accessible_path();
5555
} else if (result.first->second) {
56-
// Remove one type only accessable path
57-
result.first->second->decrease_accessable_path();
56+
// Remove one type only accessible path
57+
result.first->second->decrease_accessible_path();
5858
result.first->second = nullptr;
5959
}
6060
}
6161
if (!name.empty()) {
6262
::std::tuple<const Id*, ::std::string> key {type, name};
6363
auto result = _holder_by_type_and_name.emplace(key, pholder);
64-
// Find one type name accessable path
64+
// Find one type name accessible path
6565
if (result.second) {
66-
pholder->increase_accessable_path();
66+
pholder->increase_accessible_path();
6767
} else if (result.first->second) {
68-
// Remove one type name only accessable path
69-
result.first->second->decrease_accessable_path();
68+
// Remove one type name only accessible path
69+
result.first->second->decrease_accessible_path();
7070
result.first->second = nullptr;
7171
}
7272
}

src/babylon/application_context.h

+16-10
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,10 @@ class ApplicationContext::ComponentHolder {
170170

171171
// How many paths exist to access this component by type or name.
172172
// Use to detect orphan component cause by type and name conflict.
173-
inline size_t accessable_path_number() const noexcept;
173+
inline size_t accessible_path_number() const noexcept;
174174

175175
inline const ::std::string& name() const noexcept;
176+
inline const Id* type_id() const noexcept;
176177

177178
protected:
178179
// 构造时需要给定必要的类型信息
@@ -293,8 +294,8 @@ class ApplicationContext::ComponentHolder {
293294
int>::type = 0>
294295
static int initialize(Any&, ApplicationContext&, const Any&) noexcept;
295296

296-
inline void increase_accessable_path() noexcept;
297-
inline void decrease_accessable_path() noexcept;
297+
inline void increase_accessible_path() noexcept;
298+
inline void decrease_accessible_path() noexcept;
298299

299300
inline void set_name(StringView name) noexcept;
300301

@@ -309,7 +310,7 @@ class ApplicationContext::ComponentHolder {
309310
SingletonState _singleton_state {SingletonState::UNINITIALIZED};
310311
Any _singleton;
311312
size_t _sequence {0};
312-
size_t _accessable_path {0};
313+
size_t _accessible_path {0};
313314

314315
friend ApplicationContext;
315316
};
@@ -588,15 +589,20 @@ ApplicationContext::ComponentHolder::sequence() const noexcept {
588589
}
589590

590591
inline ABSL_ATTRIBUTE_ALWAYS_INLINE size_t
591-
ApplicationContext::ComponentHolder::accessable_path_number() const noexcept {
592-
return _accessable_path;
592+
ApplicationContext::ComponentHolder::accessible_path_number() const noexcept {
593+
return _accessible_path;
593594
}
594595

595596
inline ABSL_ATTRIBUTE_ALWAYS_INLINE const ::std::string&
596597
ApplicationContext::ComponentHolder::name() const noexcept {
597598
return _name;
598599
}
599600

601+
inline ABSL_ATTRIBUTE_ALWAYS_INLINE const Id*
602+
ApplicationContext::ComponentHolder::type_id() const noexcept {
603+
return &(_type_id->type_id);
604+
}
605+
600606
template <typename T>
601607
ABSL_ATTRIBUTE_NOINLINE void
602608
ApplicationContext::ComponentHolder::set_type() noexcept {
@@ -711,13 +717,13 @@ ABSL_ATTRIBUTE_NOINLINE int ApplicationContext::ComponentHolder::initialize(
711717
}
712718

713719
inline void
714-
ApplicationContext::ComponentHolder::increase_accessable_path() noexcept {
715-
_accessable_path++;
720+
ApplicationContext::ComponentHolder::increase_accessible_path() noexcept {
721+
_accessible_path++;
716722
}
717723

718724
inline void
719-
ApplicationContext::ComponentHolder::decrease_accessable_path() noexcept {
720-
_accessable_path--;
725+
ApplicationContext::ComponentHolder::decrease_accessible_path() noexcept {
726+
_accessible_path--;
721727
}
722728

723729
inline void ApplicationContext::ComponentHolder::set_name(

test/test_application_context.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ TEST_F(ApplicationContextTest, get_component_after_register) {
3030
context.register_component(DefaultComponentHolder<::std::string>::create());
3131
ASSERT_TRUE(context.component_accessor<::std::string>());
3232
for (auto& holder : context) {
33-
ASSERT_EQ(1, holder.accessable_path_number());
33+
ASSERT_EQ(&::babylon::TypeId<::std::string>::ID, holder.type_id());
34+
ASSERT_EQ(1, holder.accessible_path_number());
3435
}
3536
}
3637

@@ -41,7 +42,7 @@ TEST_F(ApplicationContextTest,
4142
context.register_component(DefaultComponentHolder<::std::string>::create());
4243
ASSERT_FALSE(context.component_accessor<::std::string>());
4344
for (auto& holder : context) {
44-
ASSERT_EQ(0, holder.accessable_path_number());
45+
ASSERT_EQ(0, holder.accessible_path_number());
4546
}
4647
}
4748

@@ -57,7 +58,7 @@ TEST_F(ApplicationContextTest,
5758
ASSERT_TRUE(context.component_accessor<::std::string>("B"));
5859
ASSERT_FALSE(context.component_accessor<::std::string>("C"));
5960
for (auto& holder : context) {
60-
ASSERT_EQ(1, holder.accessable_path_number());
61+
ASSERT_EQ(1, holder.accessible_path_number());
6162
}
6263
}
6364

@@ -71,7 +72,7 @@ TEST_F(ApplicationContextTest,
7172
ASSERT_FALSE(context.component_accessor<::std::string>());
7273
ASSERT_FALSE(context.component_accessor<::std::string>("A"));
7374
for (auto& holder : context) {
74-
ASSERT_EQ(0, holder.accessable_path_number());
75+
ASSERT_EQ(0, holder.accessible_path_number());
7576
}
7677
}
7778

@@ -89,7 +90,7 @@ TEST_F(ApplicationContextTest,
8990
ASSERT_TRUE(context.component_accessor<::std::vector<int>>("A"));
9091
for (auto& holder : context) {
9192
ASSERT_EQ("A", holder.name());
92-
ASSERT_EQ(2, holder.accessable_path_number());
93+
ASSERT_EQ(2, holder.accessible_path_number());
9394
}
9495
}
9596

0 commit comments

Comments
 (0)