glc_structinstance.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00024
00025 #include "glc_structinstance.h"
00026 #include "glc_structreference.h"
00027 #include "glc_structoccurence.h"
00028
00029
00030 GLC_StructInstance::GLC_StructInstance(GLC_StructReference* pStructReference)
00031 : m_pNumberOfInstance(NULL)
00032 , m_pStructReference(pStructReference)
00033 , m_ListOfOccurences()
00034 , m_RelativeMatrix()
00035 , m_Name()
00036 , m_pAttributes(NULL)
00037 {
00038 if (NULL == m_pStructReference)
00039 {
00040 m_pStructReference= new GLC_StructReference();
00041 }
00042 m_Name= m_pStructReference->name();
00043
00044 if (m_pStructReference->hasStructInstance())
00045 {
00046 m_pNumberOfInstance= m_pStructReference->firstInstanceHandle()->m_pNumberOfInstance;
00047 ++(*m_pNumberOfInstance);
00048 }
00049 else
00050 {
00051 m_pNumberOfInstance= new int(1);
00052 }
00053
00054 m_pStructReference->structInstanceCreated(this);
00055
00056 }
00057
00058
00059 GLC_StructInstance::GLC_StructInstance(GLC_Rep* pRep)
00060 : m_pNumberOfInstance(NULL)
00061 , m_pStructReference(new GLC_StructReference(pRep))
00062 , m_ListOfOccurences()
00063 , m_RelativeMatrix()
00064 , m_Name(m_pStructReference->name())
00065 , m_pAttributes(NULL)
00066 {
00067 if (m_pStructReference->hasStructInstance())
00068 {
00069 m_pNumberOfInstance= m_pStructReference->firstInstanceHandle()->m_pNumberOfInstance;
00070 ++(*m_pNumberOfInstance);
00071 }
00072 else
00073 {
00074 m_pNumberOfInstance= new int(1);
00075 }
00076
00077 m_pStructReference->structInstanceCreated(this);
00078 }
00079
00080
00081 GLC_StructInstance::GLC_StructInstance(const GLC_StructInstance& structInstance)
00082 : m_pNumberOfInstance(structInstance.m_pNumberOfInstance)
00083 , m_pStructReference(structInstance.m_pStructReference)
00084 , m_ListOfOccurences()
00085 , m_RelativeMatrix(structInstance.m_RelativeMatrix)
00086 , m_Name(structInstance.name())
00087 , m_pAttributes(NULL)
00088 {
00089
00090 Q_ASSERT(NULL != m_pStructReference);
00091
00092 if (NULL != structInstance.m_pAttributes)
00093 {
00094 m_pAttributes= new GLC_Attributes(*(structInstance.m_pAttributes));
00095 }
00096
00097 ++(*m_pNumberOfInstance);
00098
00099
00100 m_pStructReference->structInstanceCreated(this);
00101 }
00102
00103
00104 GLC_StructInstance::GLC_StructInstance(GLC_StructInstance* pStructInstance)
00105 : m_pNumberOfInstance(pStructInstance->m_pNumberOfInstance)
00106 , m_pStructReference(pStructInstance->m_pStructReference)
00107 , m_ListOfOccurences()
00108 , m_RelativeMatrix(pStructInstance->m_RelativeMatrix)
00109 , m_Name(pStructInstance->name())
00110 , m_pAttributes(NULL)
00111 {
00112
00113 Q_ASSERT(NULL != m_pStructReference);
00114
00115 if (NULL != pStructInstance->m_pAttributes)
00116 {
00117 m_pAttributes= new GLC_Attributes(*(pStructInstance->m_pAttributes));
00118 }
00119
00120 ++(*m_pNumberOfInstance);
00121
00122
00123 m_pStructReference->structInstanceCreated(this);
00124 }
00125
00126
00127 GLC_StructInstance::GLC_StructInstance(const QString& name)
00128 : m_pNumberOfInstance(NULL)
00129 , m_pStructReference(NULL)
00130 , m_ListOfOccurences()
00131 , m_RelativeMatrix()
00132 , m_Name(name)
00133 , m_pAttributes(NULL)
00134 {
00135 }
00136
00137
00138 void GLC_StructInstance::setReference(GLC_StructReference* pStructReference)
00139 {
00140 Q_ASSERT(NULL == m_pStructReference);
00141 Q_ASSERT(NULL == m_pNumberOfInstance);
00142 m_pStructReference= pStructReference;
00143 if (m_pStructReference->hasStructInstance())
00144 {
00145 m_pNumberOfInstance= m_pStructReference->firstInstanceHandle()->m_pNumberOfInstance;
00146 ++(*m_pNumberOfInstance);
00147 }
00148 else
00149 {
00150 m_pNumberOfInstance= new int(1);
00151 }
00152
00153 m_pStructReference->structInstanceCreated(this);
00154
00155 if (m_Name.isEmpty())
00156 {
00157 m_Name= pStructReference->name();
00158 }
00159 }
00160
00161
00162 GLC_StructInstance::~GLC_StructInstance()
00163 {
00164 if(m_pNumberOfInstance != NULL)
00165 {
00166
00167 if ((--(*m_pNumberOfInstance)) == 0)
00168 {
00169 delete m_pStructReference;
00170 delete m_pNumberOfInstance;
00171 }
00172 else
00173 {
00174
00175 m_pStructReference->structInstanceDeleted(this);
00176 Q_ASSERT(m_pStructReference->hasStructInstance());
00177 }
00178 delete m_pAttributes;
00179 }
00180 else qDebug() << "GLC_StructInstance::~GLC_StructInstance() of empty instance";
00181
00182 }