YSTest: any.cpp 源文件

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,
39 a.manager(storage, a.storage, any_ops::clone);
40 }
41 }
42 any::~any()
43 {
44 if(manager)
45 manager(storage, storage, any_ops::destroy);
46 }
47
48 void*
49 any::get() const ynothrow
50 {
51 if(manager)
52 {
53 any_ops::any_storage t;
54
55 manager(t, storage, any_ops::get_ptr);
56 return t.access<void*>();
57 }
58 return nullptr;
59 }
60
61 any_ops::holder*
62 any::get_holder() const
63 {
64 if(manager)
65 {
66 any_ops::any_storage t;
67
68 manager(t, storage, any_ops::get_holder_ptr);
69 return t.access<any_ops::holder*>();
70 }
71 return nullptr;
72 }
73
74 void
75 any::clear() ynothrow
76 {
77 if(manager)
78 {
79 manager(storage, storage, any_ops::destroy);
80 manager = {};
81 }
82 }
83
84 void
85 any::swap(any& a) ynothrow
86 {
87 std::swap(storage, a.storage),
88 std::swap(manager, a.manager);
89 }
90
91 const std::type_info&
92 any::type() const ynothrow
93 {
94 if(manager)
95 {
96 any_ops::any_storage t;
97
98 manager(t, storage, any_ops::get_type);
99 return *t.access<const std::type_info*>();
100 }
101 return typeid(void);
102 }
103
104 } // namespace ystdex;
105
ystdex::any
基于类型擦除的动态泛型对象。
Definition: any.h:584
ystdex::pod_storage< non_aggregate_pod >
ystdex::pod_storage::access
void * access()
Definition: any.h:97
ystdex::any_ops::get_holder_ptr
Definition: any.h:313
ystdex::any_ops::holder
抽象动态泛型持有者接口。
Definition: any.h:162
ystdex::swap
void swap(any &x, any &y)
交换对象。
Definition: any.h:729
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:514
ystdex::any::type
const std::type_info & type() const
Definition: any.cpp:92
ystdex::any::storage
any_ops::any_storage storage
Definition: any.h:589
ystdex::any::clear
void clear()
Definition: any.cpp:75
ystdex::any::get
void * get() const
Definition: any.cpp:49
ystdex::any::~any
~any()
Definition: any.cpp:42
ystdex::any_ops::get_type
Definition: any.h:308
ystdex::any::swap
void swap(any &a)
Definition: any.cpp:85
any.h
动态泛型类型。
ystdex::any_ops::get_ptr
Definition: any.h:309
ystdex::any::get_holder
any_ops::holder * get_holder() const
Definition: any.cpp:62
ystdex::any::manager
any_ops::any_manager manager
Definition: any.h:590
ystdex::any_ops::clone
Definition: any.h:310
ystdex::any_ops::destroy
Definition: any.h:311
ystdex::any::any
any()
Definition: any.h:596