YSTest  PreAlpha_b500_20140530
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
any.cpp
浏览该文件的文档.
1 /*
2  Copyright by FrankHB 2012 - 2013.
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 any::any(const any& a)
34  : any()
35 {
36  if(a)
37  {
38  manager = a.manager,
40  }
41 }
43 {
44  if(manager)
46 }
47 
48 void*
50 {
51  if(manager)
52  {
54 
56  return t.access<void*>();
57  }
58  return nullptr;
59 }
60 
63 {
64  if(manager)
65  {
67 
69  return t.access<any_ops::holder*>();
70  }
71  return nullptr;
72 }
73 
74 void
76 {
77  if(manager)
78  {
80  manager = {};
81  }
82 }
83 
84 void
86 {
87  std::swap(storage, a.storage),
88  std::swap(manager, a.manager);
89 }
90 
91 const std::type_info&
93 {
94  if(manager)
95  {
97 
99  return *t.access<const std::type_info*>();
100  }
101  return typeid(void);
102 }
103 
104 } // namespace ystdex;
105 
基于类型擦除的动态泛型对象。
Definition: any.h:584
void * access()
Definition: any.h:97
抽象动态泛型持有者接口。
Definition: any.h:162
void swap(any &x, any &y)
交换对象。
Definition: any.h:729
#define ynothrow
YSLib 无异常抛出保证:若支持 noexcept 关键字, 指定特定的 noexcept 异常规范。
Definition: ydef.h:514
const std::type_info & type() const
Definition: any.cpp:92
any_ops::any_storage storage
Definition: any.h:589
void clear()
Definition: any.cpp:75
void * get() const
Definition: any.cpp:49
~any()
Definition: any.cpp:42
void swap(any &a)
Definition: any.cpp:85
动态泛型类型。
any_ops::holder * get_holder() const
Definition: any.cpp:62
any_ops::any_manager manager
Definition: any.h:590
any()
Definition: any.h:596