GgepBlock.cpp

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 2005-2007 by Peter Dimov.
00004 
00005 This file is part of Calitko (http://www.calitko.org).
00006 
00007 Calitko is free software; you can redistribute it and/or modify
00008 it under the terms of the GNU General Public License as published by
00009 the Free Software Foundation; either version 2 of the License, or
00010 (at your option) any later version.
00011 
00012 Calitko 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 General Public License for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Calitko; if not, write to the Free Software
00019 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020 
00021 */
00022 
00023 #include "Qt.h"
00024 #include "GgepBlock.h"
00025 #include "Ggep.h"
00026 #include "Imports.cpp"
00027 
00029 GgepBlock::GgepBlock()
00030  : extensions_()
00031 {
00032 }
00033 
00035 GgepBlock::GgepBlock (const GgepBlock &block)
00036  : extensions_()
00037 {
00038     foreach (const Ggep *extension, block.extensions_)
00039         addExtension (*extension);
00040 }
00041 
00042 GgepBlock& GgepBlock::operator= (const GgepBlock &block)
00043 {
00044     if (this == &block)
00045         return *this;
00046 
00047     foreach (const Ggep *extension, extensions_)
00048         delete extension;
00049 
00050     // \todo exception safety: addExtension could throw! strong guarantee?
00051     extensions_.clear();
00052     foreach (const Ggep *extension, block.extensions_)
00053         addExtension (*extension);
00054 
00055     return *this;
00056 }
00057 
00058 bool GgepBlock::operator== (const GgepBlock &block) const
00059 {
00060     if(extensions_.size() != block.extensions().size()) return false;
00061     for (int i = 0; i < extensions_.size(); ++i) {
00062             const Ggep *ggep    = extensions_.at(i);
00063             const Ggep *rggep   = block.extensions().at(i);
00064             if((*ggep) != (*rggep)) return false;
00065     }
00066     return true;
00067 }
00068 
00069 bool GgepBlock::operator != (const GgepBlock &other) const
00070 {
00071     return !operator== (other);
00072 }
00073 
00074 GgepBlock::~GgepBlock()
00075 {
00076     deleteExtensions();
00077 }
00078 
00080 void GgepBlock::deleteExtensions()
00081 {
00082     foreach (const Ggep *extension, extensions_)
00083         delete extension;
00084     extensions_.clear();
00085 }
00086 
00088 GgepBlock & GgepBlock::addExtension (const Ggep &extension)
00089 {
00090     Ggep *newExtension = extension.copy();
00091     extensions_.append (newExtension);
00092     return *this;
00093 }
00094 
00096 
00107 GgepBlock::Extensions GgepBlock::extensions() const
00108 {
00109     return extensions_;
00110 }