1 //===-- MIUtilVariant.cpp----------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
10 #include "MIUtilVariant.h"
13 // Details: CDataObjectBase constructor.
19 CMIUtilVariant::CDataObjectBase::CDataObjectBase() {}
22 // Details: CDataObjectBase copy constructor.
24 // Args: vrOther - (R) The other object.
28 CMIUtilVariant::CDataObjectBase::CDataObjectBase(
29 const CDataObjectBase &vrOther) {
34 // Details: CDataObjectBase copy constructor.
36 // Args: vrOther - (R) The other object.
40 CMIUtilVariant::CDataObjectBase::CDataObjectBase(CDataObjectBase &vrOther) {
45 // Details: CDataObjectBase move constructor.
47 // Args: vrwOther - (R) The other object.
51 CMIUtilVariant::CDataObjectBase::CDataObjectBase(CDataObjectBase &&vrwOther) {
56 // Details: CDataObjectBase destructor.
57 // Type: Overrideable.
62 CMIUtilVariant::CDataObjectBase::~CDataObjectBase() { Destroy(); }
65 // Details: CDataObjectBase copy assignment.
67 // Args: vrOther - (R) The other object.
71 CMIUtilVariant::CDataObjectBase &CMIUtilVariant::CDataObjectBase::
72 operator=(const CDataObjectBase &vrOther) {
78 // Details: CDataObjectBase move assignment.
80 // Args: vrwOther - (R) The other object.
84 CMIUtilVariant::CDataObjectBase &CMIUtilVariant::CDataObjectBase::
85 operator=(CDataObjectBase &&vrwOther) {
92 // Details: Create a new copy of *this class.
93 // Type: Overrideable.
95 // Return: CDataObjectBase * - Pointer to a new object.
98 CMIUtilVariant::CDataObjectBase *
99 CMIUtilVariant::CDataObjectBase::CreateCopyOfSelf() {
100 // Override to implement copying of variant's data object
101 return new CDataObjectBase();
105 // Details: Determine if *this object is a derived from CDataObjectBase.
106 // Type: Overrideable.
108 // Return: bool - True = *this is derived from CDataObjectBase, false =
109 // *this is instance of the this base class.
112 bool CMIUtilVariant::CDataObjectBase::GetIsDerivedClass() const {
113 // Override to in the derived class and return true
118 // Details: Perform a bitwise copy of *this object.
119 // Type: Overrideable.
120 // Args: vrOther - (R) The other object.
124 void CMIUtilVariant::CDataObjectBase::Copy(const CDataObjectBase &vrOther) {
125 // Override to implement
130 // Details: Release any resources used by *this object.
131 // Type: Overrideable.
136 void CMIUtilVariant::CDataObjectBase::Destroy() {
137 // Do nothing - override to implement
142 // Details: CDataObject copy constructor.
144 // Args: T - The object's type.
145 // vrOther - (R) The other object.
149 template <typename T>
150 CMIUtilVariant::CDataObject<T>::CDataObject(const CDataObject &vrOther) {
151 if (this == &vrOther)
157 // Details: CDataObject copy constructor.
159 // Args: T - The object's type.
160 // vrOther - (R) The other object.
164 template <typename T>
165 CMIUtilVariant::CDataObject<T>::CDataObject(CDataObject &vrOther) {
166 if (this == &vrOther)
172 // Details: CDataObject move constructor.
174 // Args: T - The object's type.
175 // vrwOther - (R) The other object.
179 template <typename T>
180 CMIUtilVariant::CDataObject<T>::CDataObject(CDataObject &&vrwOther) {
181 if (this == &vrwOther)
188 // Details: CDataObject copy assignment.
190 // Args: T - The object's type.
191 // vrOther - (R) The other object.
195 template <typename T>
196 CMIUtilVariant::CDataObject<T> &CMIUtilVariant::CDataObject<T>::
197 operator=(const CDataObject &vrOther) {
198 if (this == &vrOther)
205 // Details: CDataObject move assignment.
207 // Args: T - The object's type.
208 // vrwOther - (R) The other object.
212 template <typename T>
213 CMIUtilVariant::CDataObject<T> &CMIUtilVariant::CDataObject<T>::
214 operator=(CDataObject &&vrwOther) {
215 if (this == &vrwOther)
224 // Details: CMIUtilVariant constructor.
230 CMIUtilVariant::CMIUtilVariant() : m_pDataObject(nullptr) {}
233 // Details: CMIUtilVariant copy constructor.
235 // Args: vrOther - (R) The other object.
239 CMIUtilVariant::CMIUtilVariant(const CMIUtilVariant &vrOther)
240 : m_pDataObject(nullptr) {
241 if (this == &vrOther)
248 // Details: CMIUtilVariant copy constructor.
250 // Args: vrOther - (R) The other object.
254 CMIUtilVariant::CMIUtilVariant(CMIUtilVariant &vrOther)
255 : m_pDataObject(nullptr) {
256 if (this == &vrOther)
263 // Details: CMIUtilVariant move constructor.
265 // Args: vrwOther - (R) The other object.
269 CMIUtilVariant::CMIUtilVariant(CMIUtilVariant &&vrwOther)
270 : m_pDataObject(nullptr) {
271 if (this == &vrwOther)
279 // Details: CMIUtilVariant destructor.
285 CMIUtilVariant::~CMIUtilVariant() { Destroy(); }
288 // Details: CMIUtilVariant copy assignment.
290 // Args: vrOther - (R) The other object.
294 CMIUtilVariant &CMIUtilVariant::operator=(const CMIUtilVariant &vrOther) {
295 if (this == &vrOther)
303 // Details: CMIUtilVariant move assignment.
305 // Args: vrwOther - (R) The other object.
309 CMIUtilVariant &CMIUtilVariant::operator=(CMIUtilVariant &&vrwOther) {
310 if (this == &vrwOther)
319 // Details: Release the resources used by *this object.
325 void CMIUtilVariant::Destroy() {
326 if (m_pDataObject != nullptr)
327 delete m_pDataObject;
328 m_pDataObject = nullptr;
332 // Details: Bitwise copy another data object to *this variant object.
334 // Args: vrOther - (R) The other object.
338 void CMIUtilVariant::Copy(const CMIUtilVariant &vrOther) {
341 if (vrOther.m_pDataObject != nullptr) {
342 m_pDataObject = vrOther.m_pDataObject->CreateCopyOfSelf();