YSTest  PreAlpha_b500_20140530
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
yref.hpp
浏览该文件的文档.
1 /*
2  © 2010-2013 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 YSL_INC_Adaptor_yref_hpp_
29 #define YSL_INC_Adaptor_yref_hpp_ 1
30 
31 #include "YModules.h"
32 #include YFM_YSLib_Adaptor_YAdaptor
33 #include <utility>
34 #include <ystdex/memory.hpp>
35 
36 namespace YSLib
37 {
38 
39 using std::bad_weak_ptr;
40 using std::const_pointer_cast;
41 using std::dynamic_pointer_cast;
42 using std::enable_shared_from_this;
43 using std::get_deleter;
49 using ystdex::get_raw;
51 using std::owner_less;
52 using ystdex::reset;
53 using ystdex::share_raw;
54 using std::shared_ptr;
55 using std::static_pointer_cast;
56 using ystdex::unique_raw;
57 using std::unique_ptr;
58 using std::weak_ptr;
59 
60 
67 template<typename _type>
68 inline bool
69 reset(_type*& p) ynothrow
70 {
71  bool b(p);
72 
73  ydelete(p);
74  p = {};
75  return b;
76 }
78 
83 template<typename _type>
84 inline bool
85 operator==(const shared_ptr<_type>& sp, _type* p)
86 {
87  return sp.get() == p;
88 }
94 template<typename _type1, typename _type2>
95 inline bool
96 operator==(const weak_ptr<_type1>& x, const weak_ptr<_type2>& y)
97 {
98  return !x.owner_before(y) && !y.owner_before(x);
99 }
100 
105 template<typename _type>
106 inline bool
107 operator!=(const shared_ptr<_type>& sp, _type* p)
108 {
109  return sp.get() != p;
110 }
116 template<typename _type1, typename _type2>
117 inline bool
118 operator!=(const weak_ptr<_type1>& x, const weak_ptr<_type2>& y)
119 {
120  return !(x == y);
121 }
122 
123 } // namespace YSLib;
124 
125 #endif
126 
bool operator==(const shared_ptr< _type > &sp, _type *p)
比较: shared_ptr 和内建指针类型的相等关系。
Definition: yref.hpp:85
std::unique_ptr< _type > unique_raw(const _pSrc &p)
Definition: memory.hpp:114
std::shared_ptr< _type > make_shared(_tParams &&...args)
使用 new 和指定参数构造指定类型的 std::shared_ptr 实例。
Definition: memory.hpp:239
std::shared_ptr< _type > share_raw(const _pSrc &p)
Definition: memory.hpp:165
_type * get_raw(_type *const &p)
Definition: memory.hpp:45
存储和智能指针特性。
#define ynothrow
YSLib 无异常抛出保证:若支持 noexcept 关键字, 指定特定的 noexcept 异常规范。
Definition: ydef.h:514
bool reset(std::unique_ptr< _type > &p)
Definition: memory.hpp:77
#define ydelete
Definition: ynew.h:207
bool operator!=(const shared_ptr< _type > &sp, _type *p)
比较: shared_ptr 左值和内建指针类型的不等关系。
Definition: yref.hpp:107
enable_if_t<!is_array< _type >::value, std::unique_ptr< _type > > make_unique(_tParams &&...args)
使用 new 和指定参数构造指定类型的 std::unique_ptr 实例。
Definition: memory.hpp:213
bool reset(_type *&p) ynothrow
Definition: yref.hpp:69