MyGUI  3.4.1
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 
10 namespace MyGUI
11 {
12 
13  Any::AnyEmpty Any::Null;
14 
16  mContent(nullptr)
17  {
18  }
19 
20  Any::Any(const Any::AnyEmpty& value) :
21  mContent(nullptr)
22  {
23  }
24 
25  Any::Any(const Any& other) :
26  mContent(other.mContent ? other.mContent->clone() : nullptr)
27  {
28  }
29 
31  {
32  delete mContent;
33  }
34 
35  Any& Any::swap(Any& rhs)
36  {
37  std::swap(mContent, rhs.mContent);
38  return *this;
39  }
40 
42  {
43  delete mContent;
44  mContent = nullptr;
45  return *this;
46  }
47 
48  Any& Any::operator = (const Any& rhs)
49  {
50  Any(rhs).swap(*this);
51  return *this;
52  }
53 
54  bool Any::empty() const
55  {
56  return !mContent;
57  }
58 
59  const std::type_info& Any::getType() const
60  {
61  return mContent ? mContent->getType() : typeid(void);
62  }
63 
64 #if defined(__clang__)
65  // That's the point of unsafe cast
66  __attribute__((no_sanitize("vptr")))
67 #endif
68  void* Any::castUnsafe() const
69  {
70  return mContent ? static_cast<Any::Holder<void*> *>(this->mContent)->held : nullptr;
71  }
72 
73  bool Any::compare(const Any& other) const
74  {
75  if (mContent == nullptr && other.mContent == nullptr)
76  return true;
77  return mContent != nullptr && other.mContent != nullptr && mContent->compare(other.mContent);
78  }
79 
80 } // namespace MyGUI
Any & swap(Any &rhs)
Definition: MyGUI_Any.cpp:35
void * castUnsafe() const
Definition: MyGUI_Any.cpp:68
const std::type_info & getType() const
Definition: MyGUI_Any.cpp:59
static AnyEmpty Null
Definition: MyGUI_Any.h:59
bool empty() const
Definition: MyGUI_Any.cpp:54
bool compare(const Any &other) const
Definition: MyGUI_Any.cpp:73
Any & operator=(const ValueType &rhs)
Definition: MyGUI_Any.h:76