MyGUI 3.5.3
MyGUI_Any.cpp
Go to the documentation of this file.
1/*
2 * This source file is part of MyGUI. For the latest info, see http://mygui.info/
3 * Distributed under the MIT License
4 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5 */
6
7#include "MyGUI_Precompiled.h"
8#include "MyGUI_Any.h"
9
10namespace MyGUI
11{
12
13 const Any Any::Null{};
14
15 Any::Any() = default;
16
17 Any::Any(const Any& other) :
18 mData(other.mData ? other.mType->copy(other.mData) : nullptr),
19 mType(other.mType)
20 {
21 }
22
23 Any::Any(Any&& other) noexcept :
24 mData(std::exchange(other.mData, nullptr)),
25 mType(std::exchange(other.mType, nullptr))
26 {
27 }
28
29 Any::~Any()
30 {
31 if (mData)
32 mType->destroy(mData);
33 }
34
35 Any& Any::operator=(const Any& rhs)
36 {
37 return *this = Any(rhs);
38 }
39
40 Any& Any::operator=(Any&& rhs) noexcept
41 {
42 if (this != &rhs)
43 {
44 // rhs may be nested inside our current value; capture it before destroying that value.
45 Any incoming(std::move(rhs));
46 std::swap(mData, incoming.mData);
47 std::swap(mType, incoming.mType);
48 }
49 return *this;
50 }
51
52 bool Any::empty() const
53 {
54 return !mData;
55 }
56
57 const std::type_info& Any::getType() const
58 {
59 return mType ? mType->type : typeid(void);
60 }
61
62 bool Any::compare(const Any& other) const
63 {
64 if (empty() || other.empty())
65 return empty() == other.empty();
66 return mType->compare(mData, other.mData, other.mType->type);
67 }
68
69} // namespace MyGUI