00001 00002 00003 00014 00015 // Copyright (C) 1997-2010 by Pawel Pilarczyk. 00016 // 00017 // This file is part of the Homology Library. This library is free software; 00018 // you can redistribute it and/or modify it under the terms of the GNU 00019 // General Public License as published by the Free Software Foundation; 00020 // either version 2 of the License, or (at your option) any later version. 00021 // 00022 // This library is distributed in the hope that it will be useful, 00023 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00024 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00025 // GNU General Public License for more details. 00026 // 00027 // You should have received a copy of the GNU General Public License along 00028 // with this software; see the file "license.txt". If not, write to the 00029 // Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, 00030 // MA 02111-1307, USA. 00031 00032 // Started on August 13, 2007. Last revision: August 13, 2007. 00033 00034 00035 #ifndef _CHOMP_STRUCT_POOL_H_ 00036 #define _CHOMP_STRUCT_POOL_H_ 00037 00038 00039 #include <chomp/struct/multitab.h> 00040 00041 00042 namespace chomp { 00043 namespace homology { 00044 00045 00046 // -------------------------------------------------- 00047 // ---------------------- POOL ---------------------- 00048 // -------------------------------------------------- 00049 00054 template <class element> 00055 class pool 00056 { 00057 public: 00059 pool (); 00060 00062 ~pool (); 00063 00066 int get (); 00067 00069 element &operator [] (int number); 00070 00073 void release (int number); 00074 00075 private: 00077 pool (const pool<element> &); 00078 00080 pool<element> &operator = (const pool<element> &); 00081 00083 multitable<element> elem; 00084 00086 int elemCount; 00087 00089 multitable<int> unused; 00090 00092 int unusedCount; 00093 00094 }; /* class pool */ 00095 00096 // -------------------------------------------------- 00097 00098 template <class element> 00099 inline pool<element>::pool (): elemCount (0), unusedCount (0) 00100 { 00101 return; 00102 } /* pool::pool */ 00103 00104 template <class element> 00105 inline pool<element>::~pool () 00106 { 00107 return; 00108 } /* pool::~pool */ 00109 00110 template <class element> 00111 inline pool<element>::pool (const pool<element> &) 00112 { 00113 throw "Copy constructor for a pool not implemented."; 00114 return; 00115 } /* pool::pool */ 00116 00117 template <class element> 00118 inline pool<element> &pool<element>::operator = (const pool<element> &) 00119 { 00120 throw "Assignment operator for a pool not implemented."; 00121 return *this; 00122 } /* pool::operator = */ 00123 00124 template <class element> 00125 inline int pool<element>::get () 00126 { 00127 if (unusedCount) 00128 return unused [-- unusedCount]; 00129 else 00130 return elemCount ++; 00131 } /* pool::get */ 00132 00133 template <class element> 00134 inline element &pool<element>::operator [] (int n) 00135 { 00136 return elem [n]; 00137 } /* pool::operator [] */ 00138 00139 template <class element> 00140 inline void pool<element>::release (int n) 00141 { 00142 if (n == elemCount - 1) 00143 -- elemCount; 00144 else 00145 unused [unusedCount ++] = n; 00146 return; 00147 } /* pool::release */ 00148 00149 00150 } // namespace homology 00151 } // namespace chomp 00152 00153 #endif // _CHOMP_STRUCT_POOL_H_ 00154 00156