YSTest: YObject.cpp 源文件

YSTest PreAlpha_b800_20170810 The YSLib Test Project

- 首页
- 相关页面
- 模块
- 命名空间
- 类
- 文件

- 文件列表
- 文件成员

YObject.cpp
浏览该文件的文档.
1 /*
2 © 2009-2013, 2015-2017 FrankHB.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
28 #include "YSLib/Core/YModules.h"
29 #include YFM_YSLib_Core_YObject // for ystdex::invoke_value_or;
30 #include <ystdex/cast.hpp> // for ystdex::polymorphic_downcast;
31
32 namespace YSLib
33 {
34
35 ImplDeDtor(IValueHolder)
36
37
38 namespace
40 {
41
43 inline PDefH(IValueHolder&, HolderDownCast, ystdex::any_ops::holder& h)
44 ynothrowv
45 ImplRet(ystdex::polymorphic_downcast<IValueHolder&>(h))
47 inline PDefH(const IValueHolder&, HolderDownCast,
48 const ystdex::any_ops::holder& h) ynothrowv
49 ImplRet(ystdex::polymorphic_downcast<const IValueHolder&>(h))
50
51 inline PDefH(bool, HolderEquals, ystdex::any_ops::holder& h, const void* p)
52 ImplRet(HolderDownCast(h).Equals(p))
53
54 } // unnamed namespace;
55
56 IValueHolder*
57 ValueObject::GetHolderPtr() const
58 {
59 return ystdex::polymorphic_downcast<IValueHolder*>(content.get_holder());
60 }
61 IValueHolder&
62 ValueObject::GetHolderRef() const
63 {
64 return HolderDownCast(Deref(content.get_holder()));
65 }
66
67 ValueObject
68 ValueObject::Create(IValueHolder::Creation c) const
69 {
70 return ystdex::call_value_or([c](const IValueHolder& h){
71 return ValueObject(h, c);
72 }, GetHolderPtr());
73 }
74
75 bool
76 ValueObject::Equals(const ValueObject& x) const
77 {
78 const auto p_holder(content.get_holder());
79
80 if(const auto q = x.content.get_holder())
81 return p_holder == q || (p_holder && p_holder->type() == q->type()
82 && HolderEquals(*p_holder, q->get()));
83 return !p_holder;
84 }
85
86 bool
87 ValueObject::EqualsRaw(const void* p) const
88 {
89 if(const auto p_holder = content.get_holder())
90 return HolderEquals(*p_holder, p);
91 return !p;
92 }
93
94 bool
95 ValueObject::EqualsUnchecked(const void* p) const
96 {
97 return HolderEquals(GetHolderRef(), p);
98 }
99
100 size_t
101 ValueObject::OwnsCount() const ynothrow
102 {
103 return ystdex::invoke_value_or(&IValueHolder::OwnsCount, GetHolderPtr());
104 }
105
106 } // namespace YSLib;
107
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:45
cast.hpp
C++ 转换模板。
YSLib::ImplDeDtor
ImplDeDtor(LoggedEvent) FatalError
Definition: YException.cpp:47
platform::Deref
yconstfn auto Deref(_type &&p) -> decltype(*p)
断言并解引用非空指针。
Definition: Debug.h:451
NPL::x
const TermNode &term ynothrow const TermNode &term ynothrow const TermNode &term ynothrow TermNode &term const TermNode &term ValueNode &node const ValueNode &node const _type & x
Definition: SContext.h:94
ystdex::any_ops::holder
抽象动态泛型持有者接口。
Definition: any.h:66
ystdex::call_value_or
auto call_value_or(_func f, _type &&p) -> decay_t< decltype(f(*std::forward< decltype(p)>(p)))>
调用非空值或取默认值。
Definition: deref_op.hpp:140
YSLib::ValueObject::GetHolderRef
IValueHolder & GetHolderRef() const
Definition: YObject.cpp:62
YSLib::ValueObject::ValueObject
ValueObject(ystdex::in_place_type_t< _type >, _tParams &&...args)
构造：使用对象初始化参数。
Definition: YObject.h:578
YSLib::ValueObject::EqualsRaw
bool EqualsRaw(const void *) const
Definition: YObject.cpp:87
YSLib::PDefH
PDefH(Environment &, FetchEnvironment,) ImplRet(FetchGlobalInstance().GetEnvironmentRef()) inline PDefH(GUIHost &
取单一环境对象引用。
YSLib::ValueObject
值类型对象类。
Definition: YObject.h:539
ystdex::invoke_value_or
auto invoke_value_or(_func f, _type &&p) -> decay_t< decltype(ystdex::invoke(f,*std::forward< decltype(p)>(p)))>
使用 invoke 调用非空值或取默认值。
Definition: functional.hpp:388
YSLib::ValueObject::Equals
bool Equals(const _type &x) const
Definition: YObject.h:819
YSLib::ValueObject::EqualsUnchecked
bool EqualsUnchecked(const void *) const
Definition: YObject.cpp:95
YSLib::ValueObject::content
Content content
Definition: YObject.h:550
YSLib::ynothrow
YB_PURE const _type size_t n ynothrow
Definition: YCoreUtilities.h:168
ynothrowv
#define ynothrowv
YSLib 无异常抛出保证验证：有条件地使用无异常抛出规范。
Definition: ydef.h:786
YSLib::ImplRet
ImplRet(FetchGlobalInstance().GetGUIHostRef()) YF_API void Execute(GUIApplication &
执行程序主消息循环。
YModules.h
CHRLib::c
c
Definition: CharacterProcessing.h:81
ystdex::any::get_holder
any_ops::holder * get_holder() const
Definition: any.h:963
CHRLib::p
const auto p(d)