YSTest: any.cpp 源文件

YSTest PreAlpha_b400_20130424 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 = nullptr;
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