GLC_lib  2.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
glc_structinstance.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 
3  This file is part of the GLC-lib library.
4  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
5  http://glc-lib.sourceforge.net
6 
7  GLC-lib is free software; you can redistribute it and/or modify
8  it under the terms of the GNU Lesser General Public License as published by
9  the Free Software Foundation; either version 3 of the License, or
10  (at your option) any later version.
11 
12  GLC-lib is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with GLC-lib; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21 *****************************************************************************/
22 
24 
25 #include "glc_structinstance.h"
26 #include "glc_structreference.h"
27 #include "glc_structoccurence.h"
28 
29 // Default constructor
31 : m_pNumberOfInstance(NULL)
32 , m_pStructReference(pStructReference)
33 , m_ListOfOccurences()
34 , m_RelativeMatrix()
35 , m_Name()
36 , m_pAttributes(NULL)
37 {
38  if (NULL == m_pStructReference)
39  {
41  }
43 
45  {
47  ++(*m_pNumberOfInstance);
48  }
49  else
50  {
51  m_pNumberOfInstance= new int(1);
52  }
53  // Inform reference that an instance has been created
55  //qDebug() << "GLC_StructInstance::GLC_StructInstance : " << (*m_pNumberOfInstance) << " " << m_pNumberOfInstance;
56 }
57 
58 // Create instance with a rep
60 : m_pNumberOfInstance(NULL)
61 , m_pStructReference(new GLC_StructReference(pRep))
62 , m_ListOfOccurences()
63 , m_RelativeMatrix()
64 , m_Name(m_pStructReference->name())
65 , m_pAttributes(NULL)
66 {
68  {
70  ++(*m_pNumberOfInstance);
71  }
72  else
73  {
74  m_pNumberOfInstance= new int(1);
75  }
76  // Inform reference that an instance has been created
78 }
79 
80 // Copy constructor
82 : m_pNumberOfInstance(structInstance.m_pNumberOfInstance)
83 , m_pStructReference(structInstance.m_pStructReference)
84 , m_ListOfOccurences()
85 , m_RelativeMatrix(structInstance.m_RelativeMatrix)
86 , m_Name(structInstance.name())
87 , m_pAttributes(NULL)
88 {
89  //qDebug() << "Instance Copy constructor";
90  Q_ASSERT(NULL != m_pStructReference);
91  // Copy attributes if necessary
92  if (NULL != structInstance.m_pAttributes)
93  {
94  m_pAttributes= new GLC_Attributes(*(structInstance.m_pAttributes));
95  }
96 
97  ++(*m_pNumberOfInstance);
98 
99  // Inform reference that an instance has been created
101 }
102 
103 // Copy constructor
105 : m_pNumberOfInstance(pStructInstance->m_pNumberOfInstance)
106 , m_pStructReference(pStructInstance->m_pStructReference)
107 , m_ListOfOccurences()
108 , m_RelativeMatrix(pStructInstance->m_RelativeMatrix)
109 , m_Name(pStructInstance->name())
110 , m_pAttributes(NULL)
111 {
112  //qDebug() << "Instance Copy constructor";
113  Q_ASSERT(NULL != m_pStructReference);
114  // Copy attributes if necessary
115  if (NULL != pStructInstance->m_pAttributes)
116  {
117  m_pAttributes= new GLC_Attributes(*(pStructInstance->m_pAttributes));
118  }
119 
120  ++(*m_pNumberOfInstance);
121 
122  // Inform reference that an instance has been created
124 }
125 
126 // Create empty instance
128 : m_pNumberOfInstance(NULL)
129 , m_pStructReference(NULL)
130 , m_ListOfOccurences()
131 , m_RelativeMatrix()
132 , m_Name(name)
133 , m_pAttributes(NULL)
134 {
135 }
136 
137 // Set the reference of an empty instance
139 {
140  Q_ASSERT(NULL == m_pStructReference);
141  Q_ASSERT(NULL == m_pNumberOfInstance);
142  m_pStructReference= pStructReference;
144  {
146  ++(*m_pNumberOfInstance);
147  }
148  else
149  {
150  m_pNumberOfInstance= new int(1);
151  }
152  // Inform reference that an instance has been created
154 
155  if (m_Name.isEmpty())
156  {
157  m_Name= pStructReference->name();
158  }
159 }
160 
161 // Destructor
163 {
164  if(m_pNumberOfInstance != NULL)
165  {
166  // Update number of instance
167  if ((--(*m_pNumberOfInstance)) == 0)
168  {
169  delete m_pStructReference;
170  delete m_pNumberOfInstance;
171  }
172  else
173  {
174  // Inform reference that an instance has been deleted
177  }
178  delete m_pAttributes;
179  }
180  else qDebug() << "GLC_StructInstance::~GLC_StructInstance() of empty instance";
181 
182 }
183 
185 {
186  const int occurenceCount= m_ListOfOccurences.count();
187  for (int i= 0; i < occurenceCount; ++i)
188  {
189  m_ListOfOccurences.at(i)->updateChildrenAbsoluteMatrix();
190  }
191 }

©2005-2013 Laurent Ribon