Документ взят из кэша поисковой машины. Адрес
оригинального документа
: http://www.atnf.csiro.au/computing/software/casacore/casacore-1.2.0/doc/html/ObjectPool_8h_source.html
Дата изменения: Unknown Дата индексирования: Mon Feb 14 20:37:38 2011 Кодировка: |
00001 //# ObjectPool.h: A parameterized stack of re-usable objects 00002 //# Copyright (C) 2001,2002 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have received a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be addressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# 00026 //# $Id: ObjectPool.h 20551 2009-03-25 00:11:33Z Malte.Marquarding $ 00027 00028 #ifndef CASA_OBJECTPOOL_H 00029 #define CASA_OBJECTPOOL_H 00030 00031 //# Includes 00032 #include <casa/aips.h> 00033 #include <casa/Containers/PoolStack.h> 00034 #include <casa/Containers/SimOrdMap.h> 00035 00036 namespace casa { //# NAMESPACE CASA - BEGIN 00037 00038 //# Forward declarations 00039 00040 // <summary> 00041 // A parameterized stack of re-usable objects 00042 // </summary> 00043 // 00044 // <use visibility=export> 00045 // 00046 // <reviewed reviewer="Ger van Diepen" date="2001/07/04" tests="tObjectPool.cc" demos=""> 00047 // </reviewed> 00048 // 00049 // <prerequisite> 00050 // <li> <linkto class=PoolStack>PoolStack</linkto> 00051 // </prerequisite> 00052 // 00053 // <synopsis> 00054 // An ObjectPool contains a set of pre-allocated Objects of the type 00055 // <src>T</src>. A Map based on the <src>Key</src> values contains 00056 // a stack of objects for each key value. 00057 // 00058 // As an example, a <src><Vector<Double>, uInt></src> ObjectPool contains 00059 // a <src>SimpleOrderedMap<uInt,PoolStack<Vector<Double>,uInt>* ></src> 00060 // map. Each Stack will contain a stack of <src>Vector<Double></src> 00061 // objects, with a length of the key value each. 00062 // 00063 // When an object is asked for with the <src>get</src> method, the 00064 // correct stack is found using the parameter key. If no entry in the map 00065 // exists, a new stack is created. If the relevant stack is empty, new elements 00066 // are added to the stack. 00067 // </synopsis> 00068 // 00069 // <example> 00070 // <srcblock> 00071 // // Create a pool of vectors 00072 // ObjectPool<Vector<Double>, uInt> pool; 00073 // // Get a pointer to a pre-defined vector of length 5 00074 // Vector<Double> *el5(pool.get(5)); 00075 // // and one of length 10 00076 // Vector<Double> *el10(pool.get(10)); 00077 // ... 00078 // // Release the objects for re-use 00079 // pool.release(el5, 5); 00080 // pool.release(el10, 10); 00081 // </srcblock> 00082 // </example> 00083 // 00084 // <motivation> 00085 // To improve the speed for the auto differentiating class. 00086 // </motivation> 00087 // 00088 // <templating arg=T> 00089 // <li> the class T must have a constructor with a Key argument 00090 // </templating> 00091 // 00092 // <templating arg=Key> 00093 // <li> the class Key must be sortable to be used as a key in the Map 00094 // </templating> 00095 // 00096 // <todo asof="2001/06/07"> 00097 // <li> Nothing at the moment 00098 // </todo> 00099 00100 template <class T, class Key> class ObjectPool { 00101 public: 00102 //# Constructors 00103 // Create the pool 00104 ObjectPool(); 00105 // Delete the pool 00106 ~ObjectPool(); 00107 00108 //# Member functions 00109 // Get a pointer to an object in the pool with the specified parameter. The 00110 // object is detached from the stack, and has to be returned with the 00111 // <src>release</src> method. The object should not be deleted by caller. 00112 // <group> 00113 T *get(const Key key=Key()) { return getStack(key).get(); }; 00114 // </group> 00115 00116 // Get the object stack for the given key 00117 PoolStack<T, Key> &getStack(const Key key); 00118 00119 // Release an object obtained from the pool through <src>get</src> for 00120 // re-use. 00121 void release(T *obj, const Key key=Key()); 00122 00123 // Get the number of object stacks in the pool 00124 uInt nelements() const { return map_p.ndefined(); }; 00125 00126 // Decimate the stacks by deleting all unused objects. 00127 // <group> 00128 void clearStacks(); 00129 void clearStack(const Key key=Key()); 00130 // </group> 00131 00132 // Decimate the stacks and remove any map entry that is completely unused 00133 void clear(); 00134 00135 private: 00136 //# Data 00137 // The default key and stack, and the last referenced one (for caching 00138 // purposes) 00139 // <group> 00140 Key defKey_p; 00141 PoolStack<T, Key> *defStack_p; 00142 Key cacheKey_p; 00143 PoolStack<T, Key> *cacheStack_p; 00144 // </group> 00145 00146 // The pool map 00147 SimpleOrderedMap<Key, PoolStack<T, Key>* > map_p; 00148 00149 //# Constructors 00150 // Copy and assignment constructors and assignment (not implemented) 00151 // <group> 00152 ObjectPool(const ObjectPool<T, Key> &other); 00153 ObjectPool<T, Key> &operator=(const ObjectPool<T, Key> &other); 00154 // </group> 00155 00156 //# Member functions 00157 }; 00158 00159 00160 } //# NAMESPACE CASA - END 00161 00162 #ifndef CASACORE_NO_AUTO_TEMPLATES 00163 #include <casa/Containers/ObjectPool.tcc> 00164 #endif //# CASACORE_NO_AUTO_TEMPLATES 00165 #endif