freCollectionBase.txx

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   F.R.E.E. - flexible registration evaluation engine
00004   Version:   v.1.0.0
00005   Date:      $Date: 2006/09/01 12:00:00 $
00006   Module:    $RCSfile: freCollectionBase.txx,v $
00007   Language:  C++
00008 
00009 
00010 
00011   Copyright (c) 2007 Ralf o Floca (Department of Medical Informatics,
00012   Institute for Medical Biometry and Informatics, University of Heidelberg,
00013   Germany). All rights reserved.
00014   See FREECopyright.txt or http://www.mi.med.uni-hd.de/free/copyright.htm
00015   for details.
00016 
00017      This software is distributed WITHOUT ANY WARRANTY; without even 
00018      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00019      PURPOSE.  See the above copyright notices for more information.
00020 
00021 =========================================================================*/
00022 
00023 #ifndef __freCollectionBase_txx
00024 #define __freCollectionBase_txx
00025 
00026 #include "freCollectionBase.h"
00027 
00028 namespace FREE
00029 {
00030 
00032         template <class TElement, class TStorageType>
00033                 void
00034                 CollectionBase< TElement, TStorageType>::
00035                 Reset()
00036         {
00037     while (m_Elements.size()) this->DeleteElement(0);
00038         };
00039 
00040         template <class TElement, class TStorageType>
00041                 CollectionBase< TElement, TStorageType>& 
00042                 CollectionBase< TElement, TStorageType>::
00043 		operator = (const CollectionBase& rCollection)
00044         {
00045                 if ( this == &rCollection) return *this;
00046 
00047     Reset();
00048     AddElements(rCollection);
00049 
00050                 return *this;
00051         };
00052 
00054         template <class TElement, class TStorageType>
00055                 CollectionBase< TElement, TStorageType>& 
00056                 CollectionBase< TElement, TStorageType>::
00057     operator + (const CollectionBase& collection)
00058         {
00059     AddElements(collection);
00060                 return *this;
00061         };
00062 
00063         template <class TElement, class TStorageType>
00064         typename CollectionBase< TElement, TStorageType>::ElementType*  
00065                 CollectionBase< TElement, TStorageType>::
00066 		GetElement(const ElementsCountType& index) const
00067         {
00068                 if ((index>=0)&(index<m_Elements.size()))
00069                 {
00070                         return m_Elements[index];
00071                 };
00072                 return NULL;
00073         };
00074 
00075         template <class TElement, class TStorageType>
00076                 void
00077                 CollectionBase< TElement, TStorageType>::
00078 		DeleteElement(const ElementsCountType& index)
00079         {
00080                 if ((index>=0)&(index<m_Elements.size()))
00081                 {
00082                         m_Elements.erase(m_Elements.begin()+index);
00083                 };
00084         };
00085 
00086         template <class TElement, class TStorageType>
00087                 typename CollectionBase< TElement, TStorageType>::ElementsCountType
00088                 CollectionBase< TElement, TStorageType>::
00089 		AddElement(ElementType* pElement)
00090         {
00091                 if (!pElement) throwExceptionMacro("Error; passed element is NULL.");
00092 
00093                 m_Elements.push_back(pElement);
00094                 return m_Elements.size()-1;
00095         };
00096 
00097         template <class TElement, class TStorageType>
00098                 void
00099                 CollectionBase< TElement, TStorageType>::
00100     AddElements(const CollectionBase& collection)
00101         {
00102     ElementsCountType max = collection.Size(); //needed to avoid recursion this+this
00103                 for (ElementsCountType i = 0; i<max; i++)
00104                 {
00105                         AddElement(*(collection.GetElement(i)));
00106                 }
00107         }
00108 
00109 }//end of namespace FREE
00110 
00111 #endif

Generated at Sat Oct 13 15:38:38 2007 for f.r.e.e. - Flexible Registration and Evaluation Engine by doxygen 1.5.3 written by Dimitri van Heesch, © 1997-2000