YSTest: any.cpp 源文件

YSTest PreAlpha_b700_20160611 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"
29
30 namespace ystdex
31 {
32
33 namespace any_ops
34 {
35
36 invalid_construction::invalid_construction()
37 : invalid_argument("Violation on construction found.")
38 {}
39
40 invalid_construction::~invalid_construction() = default;
41
42 void
43 throw_invalid_construction()
44 {
45 throw invalid_construction();
46 }
47
48
49 holder::~holder() = default;
50
51 } // namespace any_ops;
52
53
54 bad_any_cast::~bad_any_cast() = default;
55
56 const char*
57 bad_any_cast::from() const ynothrow
58 {
59 return
60 from_type() == ystdex::type_id<void>() ? "unknown" : from_type().name();
61 }
62
63 const char*
64 bad_any_cast::to() const ynothrow
65 {
66 return to_type() == ystdex::type_id<void>() ? "unknown" : to_type().name();
67 }
68
69 const char*
70 bad_any_cast::what() const ynothrow
71 {
72 return "Failed conversion: any_cast.";
73 }
74
75
76 namespace details
77 {
78
79 any_ops::any_storage&
80 any_base::call(any_ops::any_storage& t, any_ops::op_code op) const
81 {
82 yconstraint(manager);
83
84 manager(t, storage, op);
85 return t;
86 }
87
88 void
89 any_base::clear() ynothrowv
90 {
91 yconstraint(manager);
92
93 manager(storage, storage, any_ops::destroy);
94 manager = {};
95 }
96
97 void
98 any_base::copy(const any_base& a)
99 {
100 yconstraint(manager);
101
102 manager(storage, a.storage, any_ops::clone);
103 }
104
105 void
106 any_base::destroy() ynothrowv
107 {
108 yconstraint(manager);
109
110 manager(storage, storage, any_ops::destroy);
111 }
112
113 void*
114 any_base::get() const ynothrowv
115 {
116 return unchecked_access<void*>(any_ops::get_ptr);
117 }
118
119 any_ops::holder*
120 any_base::get_holder() const
121 {
122 return unchecked_access<any_ops::holder*>(any_ops::get_holder_ptr);
123 }
124
125 void
126 any_base::swap(any_base& a) ynothrow
127 {
128 std::swap(storage, a.storage),
129 std::swap(manager, a.manager);
130 }
131
132 const type_info&
133 any_base::type() const ynothrowv
134 {
135 return *unchecked_access<const type_info*>(any_ops::get_type);
136 }
137
138 } // namespace details;
139
140
141 any::any(const any& a)
142 : any_base(a)
143 {
144 if(manager)
145 copy(a);
146 }
147 any::~any()
148 {
149 if(manager)
150 destroy();
151 }
152
153 void
154 any::clear() ynothrow
155 {
156 if(manager)
157 any_base::clear();
158 }
159
160 } // namespace ystdex;
161
ystdex::any_ops::get_type
Definition: any.h:251
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:740
yconstraint
#define yconstraint(_expr)
约束：接口语义。
Definition: cassert.h:82
ystdex::any_ops::op_code
std::uint32_t op_code
Definition: any.h:244
ystdex::swap
void swap(container_adaptor< _tSeqCon > &x, container_adaptor< _tSeqCon > &y)
Definition: container.hpp:179
ystdex::any_ops::holder
抽象动态泛型持有者接口。
Definition: any.h:97
ystdex::any_ops::get_ptr
Definition: any.h:252
ystdex::details::any_base::type
const type_info & type() const
Definition: any.cpp:133
ystdex::any_ops::clone
Definition: any.h:253
ynothrowv
#define ynothrowv
YSLib 无异常抛出保证验证：有条件地使用无异常抛出规范。
Definition: ydef.h:760
ystdex::any::any
any()=default
ystdex::bad_any_cast::to_type
const type_info & to_type() const
Definition: any.h:679
ystdex::details::any_base::storage
any_ops::any_storage storage
Definition: any.h:698
ystdex::bad_any_cast::to
const char * to() const
Definition: any.cpp:64
ystdex::any
基于类型擦除的动态泛型对象。
Definition: any.h:823
ystdex::any_ops::throw_invalid_construction
void throw_invalid_construction()
Definition: any.cpp:43
ystdex::details::any_base::get_holder
any_ops::holder * get_holder() const
Definition: any.cpp:120
ystdex::any_ops::destroy
Definition: any.h:254
ystdex::bad_any_cast::what
virtual const char * what() const override
Definition: any.cpp:70
ystdex::any::~any
~any()
Definition: any.cpp:147
ystdex
特性测试宏。
Definition: ydef.h:796
ystdex::any_ops::invalid_construction::~invalid_construction
~invalid_construction() override
虚析构：类定义外默认实现。
ystdex::details::any_base::swap
void swap(any_base &)
Definition: any.cpp:126
ystdex::details::any_base::call
any_ops::any_storage & call(any_ops::any_storage &, any_ops::op_code) const
Definition: any.cpp:80
ystdex::bad_any_cast::~bad_any_cast
~bad_any_cast() override
虚析构：类定义外默认实现。
ystdex::any_ops::invalid_construction
使用不满足构造限制检查导致的异常。
Definition: any.h:57
ystdex::details::any_base::get
void * get() const
Definition: any.cpp:114
ystdex::any::clear
void clear()
Definition: any.cpp:154
ystdex::any_ops::invalid_construction::invalid_construction
invalid_construction()
Definition: any.cpp:36
ystdex::any_ops::get_holder_ptr
Definition: any.h:256
ystdex::details::any_base::manager
any_ops::any_manager manager
Definition: any.h:699
ystdex::details::any_base::clear
void clear()
Definition: any.cpp:89
ystdex::bad_any_cast::from_type
const type_info & from_type() const
Definition: any.h:669
YSLib::a
YB_PURE const _type * a
Definition: YCoreUtilities.h:167
ystdex::details::any_base::copy
void copy(const any_base &)
Definition: any.cpp:98
ystdex::standard_layout_storage
任意标准布局类型存储。
Definition: type_pun.hpp:227
ystdex::details::any_base::destroy
void destroy()
Definition: any.cpp:106
ystdex::any_ops::holder::~holder
~holder() override
虚析构：类定义外默认实现。
any.h
动态泛型类型。
ystdex::bad_any_cast::from
const char * from() const
Definition: any.cpp:57
ystdex::details::any_base
Definition: any.h:695