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