YSTest: any.cpp 源文件

YSTest PreAlpha_b800_20170810 The YSLib Test Project

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

- 文件列表
- 文件成员

any.cpp
浏览该文件的文档.
1 /*
2 © 2012-2016 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 "ystdex/any.h" // for default_init;
29
30 namespace ystdex
31 {
32
33 namespace any_ops
34 {
35
36 holder::~holder() = default;
37
38 } // namespace any_ops;
39
40
41 bad_any_cast::~bad_any_cast() = default;
42
43 const char*
44 bad_any_cast::from() const ynothrow
45 {
46 return
47 from_type() == ystdex::type_id<void>() ? "unknown" : from_type().name();
48 }
49
50 const char*
51 bad_any_cast::to() const ynothrow
52 {
53 return to_type() == ystdex::type_id<void>() ? "unknown" : to_type().name();
54 }
55
56 const char*
57 bad_any_cast::what() const ynothrow
58 {
59 return "Failed conversion: any_cast.";
60 }
61
62
63 namespace details
64 {
65
66 any_ops::any_storage&
67 any_base::call(any_ops::any_storage& t, any_ops::op_code op) const
68 {
69 yconstraint(manager);
70
71 manager(t, storage, op);
72 return t;
73 }
74
75 void
76 any_base::clear() ynothrowv
77 {
78 yconstraint(manager);
79
80 manager(storage, storage, any_ops::destroy);
81 manager = {};
82 }
83
84 void
85 any_base::copy(const any_base& a)
86 {
87 yconstraint(manager);
88
89 manager(storage, a.storage, any_ops::clone);
90 }
91
92 void
93 any_base::destroy() ynothrowv
94 {
95 yconstraint(manager);
96
97 manager(storage, storage, any_ops::destroy);
98 }
99
100 void*
101 any_base::get() const ynothrowv
102 {
103 return unchecked_access<void*>(ystdex::default_init, any_ops::get_ptr);
104 }
105
106 any_ops::holder*
107 any_base::get_holder() const
108 {
109 return unchecked_access<any_ops::holder*>(default_init,
110 any_ops::get_holder_ptr);
111 }
112
113 void
114 any_base::swap(any_base& a) ynothrow
115 {
116 std::swap(storage, a.storage),
117 std::swap(manager, a.manager);
118 }
119
120 const type_info&
121 any_base::type() const ynothrowv
122 {
123 return *unchecked_access<const type_info*>(default_init, any_ops::get_type);
124 }
125
126 } // namespace details;
127
128
129 any::any(const any& a)
130 : any_base(a)
131 {
132 if(manager)
133 copy(a);
134 }
135 any::~any()
136 {
137 if(manager)
138 destroy();
139 }
140
141 void
142 any::reset() ynothrow
143 {
144 if(manager)
145 clear();
146 }
147
148 } // namespace ystdex;
149
any.h
动态泛型类型。
ystdex::any_ops::op_code
std::uint32_t op_code
操作码。
Definition: any.h:218
ystdex::any::reset
void reset()
Definition: any.cpp:142
ystdex::any_ops::holder
抽象动态泛型持有者接口。
Definition: any.h:66
ystdex::details::any_base::type
const type_info & type() const
Definition: any.cpp:121
ystdex::any_ops::get_type
Definition: any.h:229
ystdex::standard_layout_storage
任意标准布局类型对象提供空间的存储。
Definition: type_pun.hpp:307
ystdex::bad_any_cast::to_type
const type_info & to_type() const
Definition: any.h:671
ystdex::any::any
any()=default
ystdex::details::any_base::storage
any_ops::any_storage storage
Definition: any.h:690
YSLib::a
YB_PURE const _type * a
Definition: YCoreUtilities.h:167
ystdex::any
基于类型擦除的动态泛型对象。
Definition: any.h:845
ystdex::any_ops::holder::~holder
virtual ~holder()
虚析构：类定义外默认实现。
ystdex::bad_any_cast::from_type
const type_info & from_type() const
Definition: any.h:661
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:766
ystdex::any_ops::destroy
Definition: any.h:235
ystdex
特性测试宏。
Definition: ydef.h:822
ystdex::details::any_base::get_holder
any_ops::holder * get_holder() const
Definition: any.cpp:107
ystdex::any_ops::clone
Definition: any.h:233
ystdex::any::~any
~any()
Definition: any.cpp:135
ystdex::details::any_base::swap
void swap(any_base &)
Definition: any.cpp:114
ystdex::details::any_base::call
any_ops::any_storage & call(any_ops::any_storage &, any_ops::op_code) const
Definition: any.cpp:67
ystdex::any_ops::get_holder_ptr
Definition: any.h:239
ystdex::details::any_base::get
void * get() const
Definition: any.cpp:101
ystdex::bad_any_cast::what
virtual const char * what() const override
Definition: any.cpp:57
ynothrowv
#define ynothrowv
YSLib 无异常抛出保证验证：有条件地使用无异常抛出规范。
Definition: ydef.h:786
ystdex::bad_any_cast::from
const char * from() const
Definition: any.cpp:44
ystdex::swap
void swap(container_adaptor< _tSeqCon > &x, container_adaptor< _tSeqCon > &y)
Definition: container.hpp:179
ystdex::details::any_base::manager
any_ops::any_manager manager
Definition: any.h:691
ystdex::details::any_base::clear
void clear()
Definition: any.cpp:76
ystdex::any_ops::get_ptr
Definition: any.h:231
ystdex::details::any_base::copy
void copy(const any_base &)
Definition: any.cpp:85
ystdex::details::any_base::destroy
void destroy()
Definition: any.cpp:93
ystdex::default_init
const struct ystdex::default_init_t default_init
ystdex::bad_any_cast::to
const char * to() const
Definition: any.cpp:51
yconstraint
#define yconstraint(_expr)
约束：接口语义。
Definition: cassert.h:88
ystdex::bad_any_cast::~bad_any_cast
~bad_any_cast() override
虚析构：类定义外默认实现。
ystdex::details::any_base
Definition: any.h:687