YSTest: YObject.cpp 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

YObject.cpp
浏览该文件的文档.
1 /*
2 © 2009-2013, 2015-2017, 2019-2020 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, any_ops::holder& h)
44 ynothrowv
45 ImplRet(ystdex::polymorphic_downcast<IValueHolder&>(h))
46
47 inline PDefH(bool, HolderEquals, any_ops::holder& h, const void* p)
48 ImplRet(HolderDownCast(h).Equals(p))
49
50 } // unnamed namespace;
51
52 IValueHolder*
53 ValueObject::GetHolderPtr() const
54 {
55 return ystdex::polymorphic_downcast<IValueHolder*>(content.get_holder());
56 }
57 IValueHolder&
58 ValueObject::GetHolderRef() const
59 {
60 return HolderDownCast(Deref(content.get_holder()));
61 }
62
63 ValueObject
64 ValueObject::Create(IValueHolder::Creation c) const
65 {
66 return ystdex::call_value_or([this, c](const IValueHolder& h){
67 return ValueObject(h, content, c);
68 }, GetHolderPtr());
69 }
70
71 bool
72 ValueObject::Equals(const ValueObject& x) const
73 {
74 const auto p_holder(content.get_holder());
75
76 if(const auto q = x.content.get_holder())
77 return p_holder == q || (p_holder && p_holder->type() == q->type()
78 && HolderEquals(*p_holder, q->get()));
79 return !p_holder;
80 }
81
82 bool
83 ValueObject::EqualsRaw(const void* p) const
84 {
85 if(const auto p_holder = content.get_holder())
86 return HolderEquals(*p_holder, p);
87 return !p;
88 }
89
90 bool
91 ValueObject::EqualsUnchecked(const void* p) const
92 {
93 return HolderEquals(GetHolderRef(), p);
94 }
95
96 size_t
97 ValueObject::OwnsCount() const ynothrow
98 {
99 return ystdex::invoke_value_or(&IValueHolder::OwnsCount, GetHolderPtr());
100 }
101
102 any
103 ValueObject::Query(uintmax_t val) const
104 {
105 return ystdex::call_value_or([this, val](const IValueHolder& h){
106 return h.Query(val);
107 }, GetHolderPtr());
108 }
109
110 } // namespace YSLib;
111
cast.hpp
C++ 转换模板。
x
const EncapsulationBase & x
Definition: NPLA1Forms.cpp:1536
CHRLib::c
c
Definition: CharacterProcessing.h:84
YModules.h
YSLib 核心模块配置文件。
YSLib::ValueObject::ValueObject
ValueObject(std::allocator_arg_t, const _tAlloc &a, _type &&arg)
构造：使用对象引用和分配器。
Definition: YObject.h:1127
YSLib::ValueObject::EqualsRaw
YB_ATTR_nodiscard YB_PURE bool EqualsRaw(const void *) const
Definition: YObject.cpp:83
YSLib::ImplDeDtor
ImplDeDtor(LoggedEvent) FatalError
Definition: YException.cpp:49
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: invoke.hpp:588
YSLib::ValueObject::EqualsUnchecked
YB_ATTR_nodiscard YB_PURE bool EqualsUnchecked(const void *) const
Definition: YObject.cpp:91
YSLib::ValueObject::content
Content content
Definition: YObject.h:1096
YSLib::ValueObject
值类型对象类。
Definition: YObject.h:1068
YSLib::ValueObject::x
content const ValueObject & x
Definition: YObject.h:1280
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:46
YSLib::ynothrow
YB_PURE const _type size_t n ynothrow
Definition: YCoreUtilities.h:169
platform::Deref
YB_PURE yconstfn auto Deref(_type &&p) -> decltype(*p)
断言并解引用非空指针。
Definition: Debug.h:547
YSLib::ImplRet
ImplRet(FetchGlobalInstance().GetGUIHostRef()) YF_API void Execute(GUIApplication &
执行程序主消息循环。
ynothrowv
#define ynothrowv
YSLib 无异常抛出保证验证：有条件地使用无异常抛出规范。
Definition: ydef.h:1219
YSLib::ValueObject::GetHolderRef
YB_ATTR_nodiscard YB_PURE IValueHolder & GetHolderRef() const
取持有者引用。
Definition: YObject.cpp:58
platform::p
return p p
Definition: YCLib/FileSystem.h:209
ystdex::any_ops::holder
抽象动态泛型持有者接口。
Definition: any.h:82
const
const Decapsulate const Decapsulate &y ynothrow ContextNode &ctx const
Definition: NPLA1Forms.cpp:1629
ystdex::any::get_holder
any_ops::holder * get_holder() const
Definition: any.h:2051
YSLib::ValueObject::Equals
YB_ATTR_nodiscard YB_PURE bool Equals(const _type &x) const
Definition: YObject.h:1429
YSLib::PDefH
PDefH(Environment &, FetchEnvironment,) ImplRet(FetchGlobalInstance().GetEnvironmentRef()) inline PDefH(GUIHost &
取单一环境对象引用。
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:152