1//===-- MIUtilVariant.cpp----------------------------------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10// In-house headers: 11#include "MIUtilVariant.h" 12 13//++ ------------------------------------------------------------------------------------ 14// Details: CDataObjectBase constructor. 15// Type: Method. 16// Args: None. 17// Return: None. 18// Throws: None. 19//-- 20CMIUtilVariant::CDataObjectBase::CDataObjectBase() 21{ 22} 23 24//++ ------------------------------------------------------------------------------------ 25// Details: CDataObjectBase copy constructor. 26// Type: Method. 27// Args: vrOther - (R) The other object. 28// Return: None. 29// Throws: None. 30//-- 31CMIUtilVariant::CDataObjectBase::CDataObjectBase(const CDataObjectBase &vrOther) 32{ 33 MIunused(vrOther); 34} 35 36//++ ------------------------------------------------------------------------------------ 37// Details: CDataObjectBase copy constructor. 38// Type: Method. 39// Args: vrOther - (R) The other object. 40// Return: None. 41// Throws: None. 42//-- 43CMIUtilVariant::CDataObjectBase::CDataObjectBase(CDataObjectBase &vrOther) 44{ 45 MIunused(vrOther); 46} 47 48//++ ------------------------------------------------------------------------------------ 49// Details: CDataObjectBase move constructor. 50// Type: Method. 51// Args: vrwOther - (R) The other object. 52// Return: None. 53// Throws: None. 54//-- 55CMIUtilVariant::CDataObjectBase::CDataObjectBase(CDataObjectBase &&vrwOther) 56{ 57 MIunused(vrwOther); 58} 59 60//++ ------------------------------------------------------------------------------------ 61// Details: CDataObjectBase destructor. 62// Type: Overrideable. 63// Args: None. 64// Return: None. 65// Throws: None. 66//-- 67CMIUtilVariant::CDataObjectBase::~CDataObjectBase() 68{ 69 Destroy(); 70} 71 72//++ ------------------------------------------------------------------------------------ 73// Details: CDataObjectBase copy assignment. 74// Type: Method. 75// Args: vrOther - (R) The other object. 76// Return: None. 77// Throws: None. 78//-- 79CMIUtilVariant::CDataObjectBase &CMIUtilVariant::CDataObjectBase::operator=(const CDataObjectBase &vrOther) 80{ 81 Copy(vrOther); 82 return *this; 83} 84 85//++ ------------------------------------------------------------------------------------ 86// Details: CDataObjectBase move assignment. 87// Type: Method. 88// Args: vrwOther - (R) The other object. 89// Return: None. 90// Throws: None. 91//-- 92CMIUtilVariant::CDataObjectBase &CMIUtilVariant::CDataObjectBase::operator=(CDataObjectBase &&vrwOther) 93{ 94 Copy(vrwOther); 95 vrwOther.Destroy(); 96 return *this; 97} 98 99//++ ------------------------------------------------------------------------------------ 100// Details: Create a new copy of *this class. 101// Type: Overrideable. 102// Args: None. 103// Return: CDataObjectBase * - Pointer to a new object. 104// Throws: None. 105//-- 106CMIUtilVariant::CDataObjectBase * 107CMIUtilVariant::CDataObjectBase::CreateCopyOfSelf() 108{ 109 // Override to implement copying of variant's data object 110 return new CDataObjectBase(); 111} 112 113//++ ------------------------------------------------------------------------------------ 114// Details: Determine if *this object is a derived from CDataObjectBase. 115// Type: Overrideable. 116// Args: None. 117// Return: bool - True = *this is derived from CDataObjectBase, false = *this is instance of the this base class. 118// Throws: None. 119//-- 120bool 121CMIUtilVariant::CDataObjectBase::GetIsDerivedClass() const 122{ 123 // Override to in the derived class and return true 124 return false; 125} 126 127//++ ------------------------------------------------------------------------------------ 128// Details: Perform a bitwise copy of *this object. 129// Type: Overrideable. 130// Args: vrOther - (R) The other object. 131// Return: None. 132// Throws: None. 133//-- 134void 135CMIUtilVariant::CDataObjectBase::Copy(const CDataObjectBase &vrOther) 136{ 137 // Override to implement 138 MIunused(vrOther); 139} 140 141//++ ------------------------------------------------------------------------------------ 142// Details: Release any resources used by *this object. 143// Type: Overrideable. 144// Args: None. 145// Return: None. 146// Throws: None. 147//-- 148void 149CMIUtilVariant::CDataObjectBase::Destroy() 150{ 151 // Do nothing - override to implement 152} 153 154//--------------------------------------------------------------------------------------- 155//--------------------------------------------------------------------------------------- 156//--------------------------------------------------------------------------------------- 157 158//++ ------------------------------------------------------------------------------------ 159// Details: CDataObject copy constructor. 160// Type: Method. 161// Args: T - The object's type. 162// vrOther - (R) The other object. 163// Return: None. 164// Throws: None. 165//-- 166template <typename T> CMIUtilVariant::CDataObject<T>::CDataObject(const CDataObject &vrOther) 167{ 168 if (this == &vrOther) 169 return; 170 Copy(vrOther); 171} 172 173//++ ------------------------------------------------------------------------------------ 174// Details: CDataObject copy constructor. 175// Type: Method. 176// Args: T - The object's type. 177// vrOther - (R) The other object. 178// Return: None. 179// Throws: None. 180//-- 181template <typename T> CMIUtilVariant::CDataObject<T>::CDataObject(CDataObject &vrOther) 182{ 183 if (this == &vrOther) 184 return; 185 Copy(vrOther); 186} 187 188//++ ------------------------------------------------------------------------------------ 189// Details: CDataObject move constructor. 190// Type: Method. 191// Args: T - The object's type. 192// vrwOther - (R) The other object. 193// Return: None. 194// Throws: None. 195//-- 196template <typename T> CMIUtilVariant::CDataObject<T>::CDataObject(CDataObject &&vrwOther) 197{ 198 if (this == &vrwOther) 199 return; 200 Copy(vrwOther); 201 vrwOther.Destroy(); 202} 203 204//++ ------------------------------------------------------------------------------------ 205// Details: CDataObject copy assignment. 206// Type: Method. 207// Args: T - The object's type. 208// vrOther - (R) The other object. 209// Return: None. 210// Throws: None. 211//-- 212template <typename T> CMIUtilVariant::CDataObject<T> &CMIUtilVariant::CDataObject<T>::operator=(const CDataObject &vrOther) 213{ 214 if (this == &vrOther) 215 return *this; 216 Copy(vrOther); 217 return *this; 218} 219 220//++ ------------------------------------------------------------------------------------ 221// Details: CDataObject move assignment. 222// Type: Method. 223// Args: T - The object's type. 224// vrwOther - (R) The other object. 225// Return: None. 226// Throws: None. 227//-- 228template <typename T> CMIUtilVariant::CDataObject<T> &CMIUtilVariant::CDataObject<T>::operator=(CDataObject &&vrwOther) 229{ 230 if (this == &vrwOther) 231 return *this; 232 Copy(vrwOther); 233 vrwOther.Destroy(); 234 return *this; 235} 236 237//--------------------------------------------------------------------------------------- 238//--------------------------------------------------------------------------------------- 239//--------------------------------------------------------------------------------------- 240 241//++ ------------------------------------------------------------------------------------ 242// Details: CMIUtilVariant constructor. 243// Type: Method. 244// Args: None. 245// Return: None. 246// Throws: None. 247//-- 248CMIUtilVariant::CMIUtilVariant() 249 : m_pDataObject(nullptr) 250{ 251} 252 253//++ ------------------------------------------------------------------------------------ 254// Details: CMIUtilVariant copy constructor. 255// Type: Method. 256// Args: vrOther - (R) The other object. 257// Return: None. 258// Throws: None. 259//-- 260CMIUtilVariant::CMIUtilVariant(const CMIUtilVariant &vrOther) 261 : m_pDataObject(nullptr) 262{ 263 if (this == &vrOther) 264 return; 265 266 Copy(vrOther); 267} 268 269//++ ------------------------------------------------------------------------------------ 270// Details: CMIUtilVariant copy constructor. 271// Type: Method. 272// Args: vrOther - (R) The other object. 273// Return: None. 274// Throws: None. 275//-- 276CMIUtilVariant::CMIUtilVariant(CMIUtilVariant &vrOther) 277 : m_pDataObject(nullptr) 278{ 279 if (this == &vrOther) 280 return; 281 282 Copy(vrOther); 283} 284 285//++ ------------------------------------------------------------------------------------ 286// Details: CMIUtilVariant move constructor. 287// Type: Method. 288// Args: vrwOther - (R) The other object. 289// Return: None. 290// Throws: None. 291//-- 292CMIUtilVariant::CMIUtilVariant(CMIUtilVariant &&vrwOther) 293 : m_pDataObject(nullptr) 294{ 295 if (this == &vrwOther) 296 return; 297 298 Copy(vrwOther); 299 vrwOther.Destroy(); 300} 301 302//++ ------------------------------------------------------------------------------------ 303// Details: CMIUtilVariant destructor. 304// Type: Method. 305// Args: None. 306// Return: None. 307// Throws: None. 308//-- 309CMIUtilVariant::~CMIUtilVariant() 310{ 311 Destroy(); 312} 313 314//++ ------------------------------------------------------------------------------------ 315// Details: CMIUtilVariant copy assignment. 316// Type: Method. 317// Args: vrOther - (R) The other object. 318// Return: None. 319// Throws: None. 320//-- 321CMIUtilVariant &CMIUtilVariant::operator=(const CMIUtilVariant &vrOther) 322{ 323 if (this == &vrOther) 324 return *this; 325 326 Copy(vrOther); 327 return *this; 328} 329 330//++ ------------------------------------------------------------------------------------ 331// Details: CMIUtilVariant move assignment. 332// Type: Method. 333// Args: vrwOther - (R) The other object. 334// Return: None. 335// Throws: None. 336//-- 337CMIUtilVariant &CMIUtilVariant::operator=(CMIUtilVariant &&vrwOther) 338{ 339 if (this == &vrwOther) 340 return *this; 341 342 Copy(vrwOther); 343 vrwOther.Destroy(); 344 return *this; 345} 346 347//++ ------------------------------------------------------------------------------------ 348// Details: Release the resources used by *this object. 349// Type: Method. 350// Args: None. 351// Return: None. 352// Throws: None. 353//-- 354void 355CMIUtilVariant::Destroy() 356{ 357 if (m_pDataObject != nullptr) 358 delete m_pDataObject; 359 m_pDataObject = nullptr; 360} 361 362//++ ------------------------------------------------------------------------------------ 363// Details: Bitwise copy another data object to *this variant object. 364// Type: Method. 365// Args: vrOther - (R) The other object. 366// Return: None. 367// Throws: None. 368//-- 369void 370CMIUtilVariant::Copy(const CMIUtilVariant &vrOther) 371{ 372 Destroy(); 373 374 if (vrOther.m_pDataObject != nullptr) 375 { 376 m_pDataObject = vrOther.m_pDataObject->CreateCopyOfSelf(); 377 } 378} 379