1 //===-- MIUtilVariant.cpp----------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 #include "MIUtilVariant.h"
14 //------------------------------------------------------------------------------------
15 // Details: CDataObjectBase constructor.
21 CMIUtilVariant::CDataObjectBase::CDataObjectBase() {}
24 //------------------------------------------------------------------------------------
25 // Details: CDataObjectBase copy constructor.
27 // Args: vrOther - (R) The other object.
31 CMIUtilVariant::CDataObjectBase::CDataObjectBase(
32 const CDataObjectBase &vrOther) {
37 //------------------------------------------------------------------------------------
38 // Details: CDataObjectBase copy constructor.
40 // Args: vrOther - (R) The other object.
44 CMIUtilVariant::CDataObjectBase::CDataObjectBase(CDataObjectBase &vrOther) {
49 //------------------------------------------------------------------------------------
50 // Details: CDataObjectBase move constructor.
52 // Args: vrwOther - (R) The other object.
56 CMIUtilVariant::CDataObjectBase::CDataObjectBase(CDataObjectBase &&vrwOther) {
61 //------------------------------------------------------------------------------------
62 // Details: CDataObjectBase destructor.
63 // Type: Overrideable.
68 CMIUtilVariant::CDataObjectBase::~CDataObjectBase() { Destroy(); }
71 //------------------------------------------------------------------------------------
72 // Details: CDataObjectBase copy assignment.
74 // Args: vrOther - (R) The other object.
78 CMIUtilVariant::CDataObjectBase &CMIUtilVariant::CDataObjectBase::
79 operator=(const CDataObjectBase &vrOther) {
85 //------------------------------------------------------------------------------------
86 // Details: CDataObjectBase move assignment.
88 // Args: vrwOther - (R) The other object.
92 CMIUtilVariant::CDataObjectBase &CMIUtilVariant::CDataObjectBase::
93 operator=(CDataObjectBase &&vrwOther) {
100 //------------------------------------------------------------------------------------
101 // Details: Create a new copy of *this class.
102 // Type: Overrideable.
104 // Return: CDataObjectBase * - Pointer to a new object.
107 CMIUtilVariant::CDataObjectBase *
108 CMIUtilVariant::CDataObjectBase::CreateCopyOfSelf() {
109 // Override to implement copying of variant's data object
110 return new CDataObjectBase();
114 //------------------------------------------------------------------------------------
115 // Details: Determine if *this object is a derived from CDataObjectBase.
116 // Type: Overrideable.
118 // Return: bool - True = *this is derived from CDataObjectBase, false =
119 // *this is instance of the this base class.
122 bool CMIUtilVariant::CDataObjectBase::GetIsDerivedClass() const {
123 // Override to in the derived class and return true
128 //------------------------------------------------------------------------------------
129 // Details: Perform a bitwise copy of *this object.
130 // Type: Overrideable.
131 // Args: vrOther - (R) The other object.
135 void CMIUtilVariant::CDataObjectBase::Copy(const CDataObjectBase &vrOther) {
136 // Override to implement
141 //------------------------------------------------------------------------------------
142 // Details: Release any resources used by *this object.
143 // Type: Overrideable.
148 void CMIUtilVariant::CDataObjectBase::Destroy() {
149 // Do nothing - override to implement
152 //---------------------------------------------------------------------------------------
153 //---------------------------------------------------------------------------------------
154 //---------------------------------------------------------------------------------------
157 //------------------------------------------------------------------------------------
158 // Details: CDataObject copy constructor.
160 // Args: T - The object's type.
161 // vrOther - (R) The other object.
165 template <typename T>
166 CMIUtilVariant::CDataObject<T>::CDataObject(const CDataObject &vrOther) {
167 if (this == &vrOther)
173 //------------------------------------------------------------------------------------
174 // Details: CDataObject copy constructor.
176 // Args: T - The object's type.
177 // vrOther - (R) The other object.
181 template <typename T>
182 CMIUtilVariant::CDataObject<T>::CDataObject(CDataObject &vrOther) {
183 if (this == &vrOther)
189 //------------------------------------------------------------------------------------
190 // Details: CDataObject move constructor.
192 // Args: T - The object's type.
193 // vrwOther - (R) The other object.
197 template <typename T>
198 CMIUtilVariant::CDataObject<T>::CDataObject(CDataObject &&vrwOther) {
199 if (this == &vrwOther)
206 //------------------------------------------------------------------------------------
207 // Details: CDataObject copy assignment.
209 // Args: T - The object's type.
210 // vrOther - (R) The other object.
214 template <typename T>
215 CMIUtilVariant::CDataObject<T> &CMIUtilVariant::CDataObject<T>::
216 operator=(const CDataObject &vrOther) {
217 if (this == &vrOther)
224 //------------------------------------------------------------------------------------
225 // Details: CDataObject move assignment.
227 // Args: T - The object's type.
228 // vrwOther - (R) The other object.
232 template <typename T>
233 CMIUtilVariant::CDataObject<T> &CMIUtilVariant::CDataObject<T>::
234 operator=(CDataObject &&vrwOther) {
235 if (this == &vrwOther)
242 //---------------------------------------------------------------------------------------
243 //---------------------------------------------------------------------------------------
244 //---------------------------------------------------------------------------------------
247 //------------------------------------------------------------------------------------
248 // Details: CMIUtilVariant constructor.
254 CMIUtilVariant::CMIUtilVariant() : m_pDataObject(nullptr) {}
257 //------------------------------------------------------------------------------------
258 // Details: CMIUtilVariant copy constructor.
260 // Args: vrOther - (R) The other object.
264 CMIUtilVariant::CMIUtilVariant(const CMIUtilVariant &vrOther)
265 : m_pDataObject(nullptr) {
266 if (this == &vrOther)
273 //------------------------------------------------------------------------------------
274 // Details: CMIUtilVariant copy constructor.
276 // Args: vrOther - (R) The other object.
280 CMIUtilVariant::CMIUtilVariant(CMIUtilVariant &vrOther)
281 : m_pDataObject(nullptr) {
282 if (this == &vrOther)
289 //------------------------------------------------------------------------------------
290 // Details: CMIUtilVariant move constructor.
292 // Args: vrwOther - (R) The other object.
296 CMIUtilVariant::CMIUtilVariant(CMIUtilVariant &&vrwOther)
297 : m_pDataObject(nullptr) {
298 if (this == &vrwOther)
306 //------------------------------------------------------------------------------------
307 // Details: CMIUtilVariant destructor.
313 CMIUtilVariant::~CMIUtilVariant() { Destroy(); }
316 //------------------------------------------------------------------------------------
317 // Details: CMIUtilVariant copy assignment.
319 // Args: vrOther - (R) The other object.
323 CMIUtilVariant &CMIUtilVariant::operator=(const CMIUtilVariant &vrOther) {
324 if (this == &vrOther)
332 //------------------------------------------------------------------------------------
333 // Details: CMIUtilVariant move assignment.
335 // Args: vrwOther - (R) The other object.
339 CMIUtilVariant &CMIUtilVariant::operator=(CMIUtilVariant &&vrwOther) {
340 if (this == &vrwOther)
349 //------------------------------------------------------------------------------------
350 // Details: Release the resources used by *this object.
356 void CMIUtilVariant::Destroy() {
357 if (m_pDataObject != nullptr)
358 delete m_pDataObject;
359 m_pDataObject = nullptr;
363 //------------------------------------------------------------------------------------
364 // Details: Bitwise copy another data object to *this variant object.
366 // Args: vrOther - (R) The other object.
370 void CMIUtilVariant::Copy(const CMIUtilVariant &vrOther) {
373 if (vrOther.m_pDataObject != nullptr) {
374 m_pDataObject = vrOther.m_pDataObject->CreateCopyOfSelf();