YSTest: base.h 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

base.h
浏览该文件的文档.
1 /*
2 © 2013-2015, 2017-2019 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 #ifndef YB_INC_ystdex_base_h_
29 #define YB_INC_ystdex_base_h_ 1
30
31 #include "../ydef.h"
32
33 namespace ystdex
34 {
35
41 namespace bases
42 {
43
49 class noncopyable
50 {
51 protected:
56 yconstfn
57 noncopyable() = default;
59 ~noncopyable() = default;
60
61 public:
63 yconstfn
64 noncopyable(const noncopyable&) = delete;
69 yconstfn
70 noncopyable(noncopyable&&) = default;
71
73 noncopyable&
74 operator=(const noncopyable&) = delete;
79 noncopyable&
80 operator=(noncopyable&&) = default;
81 };
82
83
89 class nonmovable
90 {
91 protected:
96 yconstfn
97 nonmovable() = default;
99 ~nonmovable() = default;
100
101 public:
103
104 yconstfn
106 nonmovable(const nonmovable&) = default;
108 yconstfn
109 nonmovable(nonmovable&&) = delete;
110
112 nonmovable&
113 operator=(const nonmovable&) = default;
115 nonmovable&
116 operator=(nonmovable&&) = delete;
118 };
119
120
125 class YB_API YB_ATTR_novtable cloneable
126 {
127 public:
129 cloneable() = default;
131 cloneable(const cloneable&) = default;
133 virtual
134 ~cloneable();
135
137 cloneable&
138 operator=(const cloneable&) = default;
139
140 virtual cloneable*
141 clone() const = 0;
142 };
143
144
151 template<typename _type>
152 struct deref_self
153 {
154 _type&
155 operator*() ynothrow
156 {
157 return *static_cast<_type*>(this);
158 }
159 const _type&
160 operator*() const ynothrow
161 {
162 return *static_cast<const _type*>(this);
163 }
164 volatile _type&
165 operator*() volatile ynothrow
166 {
167 return *static_cast<volatile _type*>(this);
168 }
169 const volatile _type&
170 operator*() const volatile ynothrow
171 {
172 return *static_cast<const volatile _type*>(this);
173 }
174 };
175
176
183 template<class _tBase, typename...>
184 class derived_entity : public _tBase
185 {
186 public:
187 using base = _tBase;
188
189 derived_entity() = default;
195 using base::base;
196 derived_entity(const base& b) ynoexcept_spec(base(b))
197 : base(b)
198 {}
199 derived_entity(base&& b) ynoexcept_spec(base(std::move(b)))
200 : base(std::move(b))
201 {}
202 derived_entity(const derived_entity&) = default;
203 derived_entity(derived_entity&&) = default;
204
205 derived_entity&
206 operator=(const derived_entity&) = default;
207 derived_entity&
208 operator=(derived_entity&&) = default;
209 };
210
211 } // namespace bases;
212
214
215 using noncopyable = bases::noncopyable;
216
217 using nonmovable = bases::nonmovable;
218
219 using cloneable = bases::cloneable;
220
221 template<typename _type>
222 using deref_self = bases::deref_self<_type>;
223
224 template<class _tBase, typename... _tParams>
225 using derived_entity = bases::derived_entity<_tBase, _tParams...>;
227
228 } // namespace ystdex;
229
230 #endif
231
ystdex::bases::nonmovable::nonmovable
nonmovable()=default
protected 构造：默认实现。
ystdex::bases::cloneable::cloneable
cloneable()=default
ystdex::bases::derived_entity::base
_tBase base
Definition: base.h:187
ystdex::derived_entity
bases::derived_entity< _tBase, _tParams... > derived_entity
Definition: base.h:225
ystdex::bases::nonmovable::nonmovable
nonmovable(const nonmovable &)=default
允许复制构造。
ystdex::bases::noncopyable::noncopyable
noncopyable()=default
protected 构造：默认实现。
ystdex::noncopyable
bases::noncopyable noncopyable
Definition: base.h:215
ystdex::bases::derived_entity::derived_entity
derived_entity(const derived_entity &)=default
ystdex::cloneable
bases::cloneable cloneable
Definition: base.h:219
ynoexcept_spec
#define ynoexcept_spec(...)
表达式 noexcept 异常规范。
Definition: ydef.h:1181
ystdex::bases::derived_entity
派生类实体。
Definition: base.h:185
ystdex::bases::nonmovable::operator=
nonmovable & operator=(nonmovable &&)=delete
禁止转移赋值。
ystdex::bases::derived_entity::derived_entity
derived_entity()=default
ystdex::bases::derived_entity::derived_entity
derived_entity(const base &b)
Definition: base.h:196
ystdex::bases::noncopyable::~noncopyable
~noncopyable()=default
protected 析构：默认实现。
ystdex::bases::noncopyable::noncopyable
noncopyable(noncopyable &&)=default
允许转移构造。
ystdex::bases::cloneable::cloneable
cloneable(const cloneable &)=default
ystdex::bases::derived_entity::operator=
derived_entity & operator=(derived_entity &&)=default
ystdex::bases::deref_self::operator*
const _type & operator*() const
Definition: base.h:160
ystdex::bases::nonmovable
不可转移对象：禁止继承此类的对象调用默认原型的转移构造函数和转移赋值操作符。
Definition: base.h:90
ystdex::bases::cloneable::clone
virtual cloneable * clone() const =0
std
Definition: optional.h:982
ystdex::bases::cloneable::operator=
cloneable & operator=(const cloneable &)=default
ystdex::bases::noncopyable::operator=
noncopyable & operator=(const noncopyable &)=delete
禁止复制赋值。
ystdex::bases::deref_self::operator*
const volatile _type & operator*() const volatile
Definition: base.h:170
ystdex::bases::derived_entity::derived_entity
derived_entity(derived_entity &&)=default
ystdex::bases::noncopyable::noncopyable
noncopyable(const noncopyable &)=delete
禁止复制构造。
ystdex::bases::deref_self::operator*
volatile _type & operator*() volatile
Definition: base.h:165
YB_API
#define YB_API
YBase 应用程序编程接口：用于向库文件约定链接。
Definition: ydef.h:985
ystdex::bases::nonmovable::operator=
nonmovable & operator=(const nonmovable &)=default
允许复制赋值。
YB_ATTR_novtable
#define YB_ATTR_novtable
修饰类定义要求实现不生成初始化动态类型信息。
Definition: ydef.h:745
ystdex::bases::derived_entity::derived_entity
derived_entity(base &&b)
Definition: base.h:199
ystdex
<memory> 特性测试宏。
Definition: ydef.h:1262
ystdex::bases::derived_entity::operator=
derived_entity & operator=(const derived_entity &)=default
YSLib::_tParams
YB_ATTR_nodiscard YB_PURE typename _tParams
Definition: ValueNode.h:1294
ystdex::bases::deref_self
间接操作：返回派生类自身引用。
Definition: base.h:153
ystdex::bases::cloneable::~cloneable
virtual ~cloneable()
虚析构：类定义外默认实现。
ystdex::bases::noncopyable::operator=
noncopyable & operator=(noncopyable &&)=default
允许转移赋值。
ystdex::bases::nonmovable::~nonmovable
~nonmovable()=default
protected 析构：默认实现。
ystdex::bases::nonmovable::nonmovable
nonmovable(nonmovable &&)=delete
禁止转移构造。
ystdex::nonmovable
bases::nonmovable nonmovable
Definition: base.h:217
ystdex::bases::deref_self::operator*
_type & operator*()
Definition: base.h:155
const
const Decapsulate const Decapsulate &y ynothrow ContextNode &ctx const
Definition: NPLA1Forms.cpp:1629
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:1199
ystdex::bases::noncopyable
不可复制对象：禁止派生类调用默认原型的复制构造函数和复制赋值操作符。
Definition: base.h:50
yconstfn
#define yconstfn
指定编译时常量函数。
Definition: ydef.h:1073
ystdex::bases::cloneable
可动态复制的抽象基类。
Definition: base.h:126