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  Version 2.0.0 Beta 1, packaged on April 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 General Public License as published by
00011  the Free Software Foundation; either version 2 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 General Public License for more details.
00018 
00019  You should have received a copy of the GNU 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_world.h"
00028 #include "glc_structinstance.h"
00029 #include "glc_structreference.h"
00030 
00031 // Default constructor
00032 GLC_World::GLC_World()
00033 : m_pWorldHandle(new GLC_WorldHandle())
00034 , m_pRoot(new GLC_StructOccurence())
00035 {
00036         m_pRoot->setWorldHandle(m_pWorldHandle);
00037         //qDebug() << "GLC_World::GLC_World() : " << (*m_pNumberOfWorld) << " " << this;
00038 }
00039 
00040 // Copy constructor
00041 GLC_World::GLC_World(const GLC_World& world)
00042 : m_pWorldHandle(world.m_pWorldHandle)
00043 , m_pRoot(world.m_pRoot)
00044 {
00045         //qDebug() << "GLC_World::GLC_World() : " << (*m_pNumberOfWorld) << " " << this;
00046         // Increment the number of world
00047         m_pWorldHandle->increment();
00048 }
00049 
00050 GLC_World::~GLC_World()
00051 {
00052 
00053         // Decrement the number of world
00054         m_pWorldHandle->decrement();
00055         //qDebug() << "GLC_World::GLC_World() : " << (*m_pNumberOfWorld) << " " << this;
00056         if (m_pWorldHandle->isOrphan())
00057         {
00058                 // this is the last World, delete the root product and collection
00059                 //m_pWorldHandle->collection()->clear(); // Clear collection first (performance)
00060                 delete m_pRoot;
00061                 delete m_pWorldHandle;
00062         }
00063 }
00064 
00065 // Merge this world with another world
00066 void GLC_World::mergeWithAnotherWorld(GLC_World& anotherWorld)
00067 {
00068         qDebug() << "GLC_World::mergeWithAnotherWorld";
00069         GLC_StructOccurence* pAnotherRoot= anotherWorld.rootOccurence();
00070         if (pAnotherRoot->childCount() > 0)
00071         {
00072                 QList<GLC_StructOccurence*> childs= pAnotherRoot->children();
00073                 const int size= childs.size();
00074                 for (int i= 0; i < size; ++i)
00075                 {
00076                         m_pRoot->addChild(childs.at(i)->clone(m_pWorldHandle, true));
00077                 }
00078                 m_pRoot->updateChildrenAbsoluteMatrix();
00079         }
00080         else
00081         {
00082                 m_pRoot->addChild(anotherWorld.rootOccurence()->clone(m_pWorldHandle, true));
00083         }
00084 }
00085 
00086 // Assignment operator
00087 GLC_World& GLC_World::operator=(const GLC_World& world)
00088 {
00089         if (this != &world)
00090         {
00091                 // Decrement the number of world
00092                 m_pWorldHandle->decrement();
00093                 if (m_pWorldHandle->isOrphan())
00094                 {
00095                         // this is the last World, delete the root product and collection
00096                         //m_pWorldHandle->collection()->clear(); // Clear collection first (performance)
00097                         delete m_pRoot;
00098                         delete m_pWorldHandle;
00099                 }
00100                 m_pRoot= world.m_pRoot;
00101                 m_pWorldHandle= world.m_pWorldHandle;
00102                 m_pWorldHandle->increment();
00103         }
00104         return *this;
00105 }

SourceForge.net Logo

©2005 Laurent Ribon