Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.atnf.csiro.au/computing/software/casacore/casacore-1.2.0/doc/html/PoolStack_8h_source.html
Дата изменения: Unknown
Дата индексирования: Mon Feb 14 20:18:53 2011
Кодировка:

Поисковые слова: m 63
casacore: casa/Containers/PoolStack.h Source File

PoolStack.h

Go to the documentation of this file.
00001 //# PoolStack.h: A parameterized stack of re-usable objects
00002 //# Copyright (C) 2001,2002,2004
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: PoolStack.h 20551 2009-03-25 00:11:33Z Malte.Marquarding $
00027 
00028 #ifndef CASA_POOLSTACK_H
00029 #define CASA_POOLSTACK_H
00030 
00031 //# Includes
00032 #include <casa/aips.h>
00033 #include <casa/Containers/Block.h>
00034 
00035 namespace casa { //# NAMESPACE CASA - BEGIN
00036 
00037 //# Forward declarations
00038 
00039 // <summary>
00040 // A parameterized stack of re-usable objects
00041 // </summary>
00042 //
00043 // <use visibility=export>
00044 //
00045 // <reviewed reviewer="Ger van Diepen" date="2001/07/03" tests="tPoolStack.cc" demos="">
00046 // </reviewed>
00047 //
00048 // <prerequisite>
00049 // <li>
00050 // </prerequisite>
00051 //
00052 // <synopsis>
00053 // A PoolStack contains a set of pre-allocated Objects of the type
00054 // <src>T</src>, with a parameter <src>Key</src> (e.g. an object could be
00055 // a <src>Vector</src> of <src>T Double</src> with an <src>uInt Key</src>).
00056 // The stack is a very simple stack, without the
00057 // linking/unlinking of a normal Stack implementation.
00058 // This lightweight implementation was especially designed for use
00059 // with the <linkto class=ObjectPool>ObjectPool</linkto>
00060 // class, but can be used independently.
00061 //
00062 // Objects can be obtained with the <src>get()</src> method, and
00063 // returned for re-use with <src>release()</src>.
00064 //
00065 // Objects are not initialised when popped. The user should never delete the
00066 // object returned by get; but return it to the pool.
00067 // </synopsis>
00068 //
00069 // <example>
00070 // <srcblock>
00071 //   // Create a pool of length 5 vectors
00072 //   PoolStack<Vector<Double>, uInt> pool5(5);
00073 //   // Get an element
00074 //   Vector<Double> *elem(pool5.get());
00075 //   // Use it
00076 //   (*elem)(2) = 27;
00077 //   // Release it
00078 //   pool5.release(elem);
00079 // </srcblock>
00080 // </example>
00081 //
00082 // <motivation>
00083 // To improve the speed for the auto differentiating class.
00084 // </motivation>
00085 //
00086 // <templating arg=T>
00087 //  <li> the class T must have a constructor with a Key argument
00088 // </templating>
00089 //
00090 // <templating arg=Key>
00091 //  <li> the class Key must be usable as a constructor argument for T
00092 // </templating>
00093 //
00094 // <todo asof="2001/06/07">
00095 // <li> Nothing I know of
00096 // </todo>
00097 
00098 template <class T, class Key> class PoolStack {
00099  public:
00100   //# Constants
00101   // Number of default stack entries.
00102   static const uInt NDEF=8;
00103   //# Constructors
00104   // Create the stack with the default Key
00105   PoolStack();
00106   // Create the stack for the specified key
00107   explicit PoolStack(const Key &key);
00108   // Delete the stack
00109   ~PoolStack();
00110 
00111   //# Member functions
00112   // Get a pointer to an object in the stack. The stack will be extended if
00113   // no objects left. Extension is done with the NDEF number of elements.
00114   // Different extension can be done manually with the addElements() method.
00115   T *get() { if (!top_p) addElements(NDEF); T *tmp = stack_p[--top_p];
00116   stack_p[top_p] = 0; return tmp; };
00117 
00118   // Return an object to the stack for re-use
00119   void release(T *obj) {if (obj) stack_p[top_p++] = obj; };
00120 
00121   // Add n elements
00122   void addElements(const uInt n);
00123 
00124   // Decimate the stack by getting rid of all unused elements in it
00125   void clear();
00126 
00127   // Test if stack empty
00128   Bool empty() { return top_p == 0; };
00129 
00130   // Return the key belonging to the stack
00131   const Key &key() const { return key_p; } 
00132   // return the stack extend (for debugging use and checking mainly)
00133   uInt nelements() const { return stack_p.nelements(); };
00134 
00135 private:
00136   //# Data
00137   // Current pointer to top-of-stack
00138   uInt top_p;
00139   // The stack
00140   PtrBlock<T*> stack_p;
00141   // The key belonging to this stack
00142   Key key_p;
00143 
00144   //# Constructors
00145   // Copy and assignment constructors and assignment (not implemented)
00146   // <group>
00147   PoolStack(const PoolStack<T, Key> &other);
00148   PoolStack<T, Key> &operator=(const PoolStack<T, Key> &other);
00149   // </group>
00150 
00151   //# Member functions
00152 };
00153 
00154 
00155 } //# NAMESPACE CASA - END
00156 
00157 #ifndef CASACORE_NO_AUTO_TEMPLATES
00158 #include <casa/Containers/PoolStack.tcc>
00159 #endif //# CASACORE_NO_AUTO_TEMPLATES
00160 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines