Wm4TSmallUnorderedSet.h

Go to the documentation of this file.
00001 // Wild Magic Source Code
00002 // David Eberly
00003 // http://www.geometrictools.com
00004 // Copyright (c) 1998-2007
00005 //
00006 // This library is free software; you can redistribute it and/or modify it
00007 // under the terms of the GNU Lesser General Public License as published by
00008 // the Free Software Foundation; either version 2.1 of the License, or (at
00009 // your option) any later version.  The license is available for reading at
00010 // either of the locations:
00011 //     http://www.gnu.org/copyleft/lgpl.html
00012 //     http://www.geometrictools.com/License/WildMagicLicense.pdf
00013 // The license applies to versions 0 through 4 of Wild Magic.
00014 //
00015 // Version: 4.0.0 (2006/06/28)
00016 
00017 #ifndef WM4TSET_H
00018 #define WM4TSET_H
00019 
00020 #include "Wm4FoundationLIB.h"
00021 #include "Wm4Memory.h"
00022 
00023 // This template class is for unordered sets of objects.  The intent is that
00024 // the sets are not too large.  If you do not plan on searching the set and
00025 // you know that the elements to be added are unique, then the size of the
00026 // set is irrelevant since a member function is provided that inserts an
00027 // element without checking to see if one already exists.
00028 //
00029 // The class T is either native data or is class data that has the following
00030 // member functions:
00031 //   T::T ()
00032 //   T::T (const T&);
00033 //   T& T::operator= (const T&)
00034 
00035 namespace Wm4
00036 {
00037 
00038 template <class T>
00039 class TSmallUnorderedSet
00040 {
00041 public:
00042     // construction and destruction
00043     TSmallUnorderedSet ();
00044     TSmallUnorderedSet (int iMaxQuantity, int iGrowBy);
00045     TSmallUnorderedSet (const TSmallUnorderedSet& rkSet);
00046     ~TSmallUnorderedSet ();
00047 
00048     // assignment
00049     TSmallUnorderedSet& operator= (const TSmallUnorderedSet& rkSet);
00050 
00051     // member access
00052     int GetMaxQuantity () const;
00053     int GetGrowBy () const;
00054     int GetQuantity () const;
00055     T* GetElements ();
00056     const T* GetElements () const;
00057     T& operator[] (int i);
00058     const T& operator[] (int i) const;
00059 
00060     // insertion, removal, searching
00061     bool Insert (const T& rkElement);
00062     void InsertNoCheck (const T& rkElement);
00063     bool Remove (const T& rkElement);
00064     bool Exists (const T& rkElement);
00065 
00066     // make empty set, keep quantity and growth parameters
00067     void Clear ();
00068 
00069     // make empty set, reallocate using new quantity and growth parameters
00070     void Clear (int iMaxQuantity, int iGrowBy);
00071 
00072 private:
00073     int m_iQuantity, m_iMaxQuantity, m_iGrowBy;
00074     T* m_atElement;
00075 };
00076 
00077 }
00078 
00079 #include "Wm4TSmallUnorderedSet.inl"
00080 
00081 #endif

Generated on Wed Nov 23 19:01:10 2011 for FreeCAD by  doxygen 1.6.1