glc_world.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  http://glc-lib.sourceforge.net
00006 
00007  GLC-lib is free software; you can redistribute it and/or modify
00008  it under the terms of the GNU Lesser General Public License as published by
00009  the Free Software Foundation; either version 3 of the License, or
00010  (at your option) any later version.
00011 
00012  GLC-lib is distributed in the hope that it will be useful,
00013  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  GNU Lesser General Public License for more details.
00016 
00017  You should have received a copy of the GNU Lesser General Public License
00018  along with GLC-lib; if not, write to the Free Software
00019  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00020 
00021 *****************************************************************************/
00022 
00024 
00025 #include "glc_world.h"
00026 #include "glc_structinstance.h"
00027 #include "glc_structreference.h"
00028 
00029 // Default constructor
00030 GLC_World::GLC_World()
00031 : m_pWorldHandle(new GLC_WorldHandle())
00032 , m_pRoot(new GLC_StructOccurence())
00033 {
00034         m_pRoot->setWorldHandle(m_pWorldHandle);
00035 }
00036 
00037 // Copy constructor
00038 GLC_World::GLC_World(const GLC_World& world)
00039 : m_pWorldHandle(world.m_pWorldHandle)
00040 , m_pRoot(world.m_pRoot)
00041 {
00042         //qDebug() << "GLC_World::GLC_World() : " << (*m_pNumberOfWorld) << " " << this;
00043         // Increment the number of world
00044         m_pWorldHandle->increment();
00045 
00046 }
00047 
00048 GLC_World::~GLC_World()
00049 {
00050         // Decrement the number of world
00051         m_pWorldHandle->decrement();
00052         if (m_pWorldHandle->isOrphan())
00053         {
00054                 // this is the last World, delete the root product and collection
00055                 //m_pWorldHandle->collection()->clear(); // Clear collection first (performance)
00056                 delete m_pRoot;
00057                 delete m_pWorldHandle;
00058         }
00059 }
00060 
00061 // Merge this world with another world
00062 void GLC_World::mergeWithAnotherWorld(GLC_World& anotherWorld)
00063 {
00064         GLC_StructOccurence* pAnotherRoot= anotherWorld.rootOccurence();
00065         if (pAnotherRoot->childCount() > 0)
00066         {
00067                 QList<GLC_StructOccurence*> childs= pAnotherRoot->children();
00068                 const int size= childs.size();
00069                 for (int i= 0; i < size; ++i)
00070                 {
00071                         m_pRoot->addChild(childs.at(i)->clone(m_pWorldHandle, false));
00072                 }
00073                 m_pRoot->updateChildrenAbsoluteMatrix();
00074         }
00075         else
00076         {
00077                 m_pRoot->addChild(anotherWorld.rootOccurence()->clone(m_pWorldHandle, false));
00078         }
00079 }
00080 
00081 // Assignment operator
00082 GLC_World& GLC_World::operator=(const GLC_World& world)
00083 {
00084         if (this != &world)
00085         {
00086                 // Decrement the number of world
00087                 m_pWorldHandle->decrement();
00088                 if (m_pWorldHandle->isOrphan())
00089                 {
00090                         // this is the last World, delete the root product and collection
00091                         //m_pWorldHandle->collection()->clear(); // Clear collection first (performance)
00092                         delete m_pRoot;
00093                         delete m_pWorldHandle;
00094                 }
00095                 m_pRoot= world.m_pRoot;
00096                 m_pWorldHandle= world.m_pWorldHandle;
00097                 m_pWorldHandle->increment();
00098         }
00099         return *this;
00100 }

SourceForge.net Logo

©2005-2011 Laurent Ribon