glc_structinstance.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002 
00003  This file is part of the GLC-lib library.
00004  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
00005  Version 2.0.0, packaged on July 2010.
00006 
00007  http://glc-lib.sourceforge.net
00008 
00009  GLC-lib is free software; you can redistribute it and/or modify
00010  it under the terms of the GNU Lesser General Public License as published by
00011  the Free Software Foundation; either version 3 of the License, or
00012  (at your option) any later version.
00013 
00014  GLC-lib is distributed in the hope that it will be useful,
00015  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  GNU Lesser General Public License for more details.
00018 
00019  You should have received a copy of the GNU Lesser General Public License
00020  along with GLC-lib; if not, write to the Free Software
00021  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00022 
00023 *****************************************************************************/
00024 
00026 
00027 #include "glc_structinstance.h"
00028 #include "glc_structreference.h"
00029 #include "glc_structoccurence.h"
00030 
00031 // Default constructor
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         // Inform reference that an instance has been created
00056         m_pStructReference->structInstanceCreated(this);
00057         //qDebug() << "GLC_StructInstance::GLC_StructInstance : " << (*m_pNumberOfInstance) << " " << m_pNumberOfInstance;
00058 }
00059 
00060 // Create instance with a rep
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         // Inform reference that an instance has been created
00079         m_pStructReference->structInstanceCreated(this);
00080         //qDebug() << "GLC_StructInstance::GLC_StructInstance : " << (*m_pNumberOfInstance) << " " << m_pNumberOfInstance;
00081 }
00082 
00083 // Copy constructor
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         //qDebug() << "Instance Copy constructor";
00093         Q_ASSERT(NULL != m_pStructReference);
00094         // Copy attributes if necessary
00095         if (NULL != structInstance.m_pAttributes)
00096         {
00097                 m_pAttributes= new GLC_Attributes(*(structInstance.m_pAttributes));
00098         }
00099 
00100         ++(*m_pNumberOfInstance);
00101 
00102         // Inform reference that an instance has been created
00103         m_pStructReference->structInstanceCreated(this);
00104 }
00105 
00106 // Copy constructor
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         //qDebug() << "Instance Copy constructor";
00116         Q_ASSERT(NULL != m_pStructReference);
00117         // Copy attributes if necessary
00118         if (NULL != pStructInstance->m_pAttributes)
00119         {
00120                 m_pAttributes= new GLC_Attributes(*(pStructInstance->m_pAttributes));
00121         }
00122 
00123         ++(*m_pNumberOfInstance);
00124 
00125         // Inform reference that an instance has been created
00126         m_pStructReference->structInstanceCreated(this);
00127 }
00128 
00129 // Create empty instance
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 // Set the reference of an empty instance
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         // Inform reference that an instance has been created
00155         m_pStructReference->structInstanceCreated(this);
00156 
00157         if (m_Name.isEmpty())
00158         {
00159                 m_Name= pStructReference->name();
00160         }
00161         //qDebug() << "GLC_StructInstance::GLC_StructInstance : " << (*m_pNumberOfInstance) << " " << m_pNumberOfInstance;
00162 }
00163 
00164 // Destructor
00165 GLC_StructInstance::~GLC_StructInstance()
00166 {
00167         if(m_pNumberOfInstance != NULL)
00168         {
00169                 // Inform reference that an instance has been deleted
00170                 m_pStructReference->structInstanceDeleted(this);
00171 
00172                 // Update number of instance
00173                 if ((--(*m_pNumberOfInstance)) == 0)
00174                 {
00175                         //qDebug() << "Delete structInstance";
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 }

SourceForge.net Logo

©2005-2010 Laurent Ribon