Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Vector_T.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //==========================================================================
00004 /**
00005  *  @file    Vector_T.h
00006  *
00007  *  $Id: Vector_T.h,v 1.1.1.1 2003/02/21 18:36:32 chad Exp $
00008  *
00009  *  @author Craig L. Ching <cching@mqsoftware.com>
00010  *  @author Gonzalo Diethelm <gonzalo.diethelm@aditiva.com>
00011  */
00012 //==========================================================================
00013 
00014 #ifndef ACE_VECTOR_T_H
00015 #define ACE_VECTOR_T_H
00016 
00017 #include "ace/pre.h"
00018 
00019 #include "ace/Array.h"
00020 
00021 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00022 # pragma once
00023 #endif /* ACE_LACKS_PRAGMA_ONCE */
00024 
00025 /*
00026  * Default size for an ACE_Vector.
00027  */
00028 const size_t ACE_VECTOR_DEFAULT_SIZE = 32;
00029 
00030 /**
00031  * @class ACE_Vector
00032  *
00033  * @brief Defines an STL-like vector container.
00034  *
00035  * This is an STL-like template vector container, a wrapper around
00036  * ACE_Array.  It provides at least the basic std::vector look and
00037  * feel: push_back(), clear(), resize(), capacity().  This template
00038  * class uses the copy semantic paradigm, though it is okay to use
00039  * reference counted smart pointers (see ACE_Ptr&lt;T&gt;) with this
00040  * template class.
00041  *
00042  * <b> Requirements and Performance Characteristics</b>
00043  *   - Internal Structure
00044  *       ACE_Array
00045  *   - Duplicates allowed?
00046  *       Yes
00047  *   - Random access allowed?
00048  *       No
00049  *   - Search speed
00050  *       N/A
00051  *   - Insert/replace speed
00052  *       Linear
00053  *   - Iterator still valid after change to container?
00054  *       Yes
00055  *   - Frees memory for removed elements?
00056  *       No
00057  *   - Items inserted by
00058  *       Value
00059  *   - Requirements for contained type
00060  *       -# Default constructor
00061  *       -# Copy constructor
00062  *       -# operator=
00063  */
00064 template<class T, size_t DEFAULT_SIZE = ACE_VECTOR_DEFAULT_SIZE>
00065 class ACE_Vector : public ACE_Array<T>
00066 {
00067 public:
00068   /**
00069    * A short name for iterator for ACE_Vector.
00070    */
00071   typedef ACE_Array_Iterator<T> Iterator;
00072 
00073 
00074   /**
00075    * General constructor.
00076    *
00077    * @param init_size Initial size of the vector with the default
00078    *                  value of DEFAULT_SIZE
00079    * @param alloc Pointer to an ACE allocator.  If it is NULL then the
00080    *              default ACE allocator is used
00081    */
00082   ACE_Vector (const size_t init_size = DEFAULT_SIZE,
00083               ACE_Allocator* alloc = 0);
00084 
00085   /**
00086    * Destructor.
00087    */
00088   ~ACE_Vector ();
00089 
00090   /**
00091    * Returns the current vector capacity, that is, the currently
00092    * allocated buffer size.
00093    *
00094    * @return Current buffer size of the vector
00095    */
00096   size_t capacity (void) const;
00097 
00098   /**
00099    * Returns the vector's dynamic size / actual current size of the
00100    * vector.  Do not confuse it with ACE_Array::size(), which returns
00101    * the array's capacity.  Unfortunately, ACE is not very consistent
00102    * with the function names.
00103    *
00104    * @return Dynamic size / actual current size of the vector.
00105    */
00106   size_t size (void) const;
00107 
00108   /**
00109    * Clears out the vector.  It does not reallocate the vector's
00110    * buffer, it is just sets the vector's dynamic size to 0.
00111    */
00112   void clear (void);
00113 
00114   /**
00115    * Resizes the vector to the new capacity.  If the vector's current
00116    * capacity is smaller than the size to be specified, then the
00117    * buffer gets reallocated.  If the new capacity is less than the
00118    * current capacity of the vector, the buffer size stays the same.
00119    *
00120    * @param new_size New capacity of the vector
00121    * @param t A filler value (of the class T) for initializing the
00122    *          elements of the vector with.  By default, if this
00123    *          parameter is not specified, the default value of the
00124    *          class T will be used (for more detail, see the
00125    *          initialization clause for this parameter).
00126    */
00127   void resize (const size_t new_size,
00128                const T& t);
00129 
00130   /**
00131    * Appends a new element to the vector ("push back").  If the
00132    * dynamic size of the vector is equal to the capacity of the vector
00133    * (vector is at capacity), the vector automatically doubles its
00134    * capacity.
00135    *
00136    * @param elem A reference to the new element to be appended.  By
00137    *             default, this parameters gets initialized with the
00138    *             default value of the class T.
00139    */
00140   void push_back (const T& elem);
00141 
00142   /**
00143    * Deletes the last element from the vector ("pop back").  What this
00144    * function really does is decrement the dynamic size of the
00145    * vector.  The vector's buffer does not get reallocated for
00146    * performance.
00147    */
00148   void pop_back (void);
00149 
00150   /**
00151    * This function dumps the content of the vector.  TO BE MOVED out
00152    * of this class.  It needs to be implemented as a global template
00153    * function that accepts a const ACE_Vector&lt;T&gt;, in order to
00154    * make instances of this class compile on Linux, AIX.  G++ and xlC
00155    * have template instantiation algoriths, which are different from
00156    * the one in Visual C++.  The algorithms try to instantiate ALL
00157    * methods declared in the template class, regardless of whether the
00158    * functions are used or not.  That is, all of the classes, that are
00159    * used as elements in ACE_Vector's, have to have the dump() methods
00160    * defined in them (seems to be overkill).
00161    *
00162    * This function calls T::dump() for each element of the vector.
00163    */
00164   void dump (void) const;
00165 
00166 protected:
00167 
00168   /**
00169    * Dynamic size (length) of the vector.
00170    */
00171   size_t length_;
00172 
00173   /**
00174    * Current capacity (buffer size) of the vector.
00175    */
00176   size_t curr_max_size_;
00177 };
00178 
00179 #if 0
00180 /*
00181  * Not sure about including these functions, if for no other reason,
00182  * because they polute the global namespace!
00183  */
00184 
00185 /**
00186  * Compare two vectors in the range of [from_ndx..to_ndx].  This
00187  * template function requires class T to have the operator!=()
00188  * declared in the class.  It is safe to define vectors of scalar data
00189  * types, like int, double, etc., including class ACE_TString.
00190  *
00191  * @param v1 The first vector (out of the two) to be compared.
00192  * @param v2 The Second vector (out of the two) to be compared.
00193  * @param from_ndx Compare vector v1 and v2, starting with the
00194  *                 "from_ndx" index .
00195  * @param to_ndx Compare vector v1 and v2, from "from_ndx" to
00196  *               "to_ndx".
00197  * @return Returns true if v1==v2 in the specified index range,
00198  *          returns false otherwise.  Also, returns false in case if
00199  *          v1's size is not equal to v2's size.
00200  */
00201 template<class T>
00202 int compare (const ACE_Vector<T>& v1,
00203               const ACE_Vector<T>& v2,
00204               const size_t from_ndx,
00205               const size_t to_ndx);
00206 
00207 /**
00208  * Does a partial comparison of two vectors in the range of
00209  * [from_ndx..to_ndx].  The only difference between this function and
00210  * the template compare&lt;T&gt; function is that this function does
00211  * not require v1 and v2 to be of equal size.
00212  *
00213  * @param v1 The first vector (out of the two) to be compared.
00214  * @param v2 The Second vector (out of the two) to be compared.
00215  * @param from_ndx Compare vector v1 and v2, starting with the
00216  *                 "from_ndx" index .
00217  * @param to_ndx Compare vector v1 and v2, from "from_ndx" to
00218  *               "to_ndx".
00219  * @return Returns true if vector v1 and v2 are equal in the specified
00220  *         index range.
00221  */
00222 
00223 template<class T>
00224 int partial_compare (const ACE_Vector<T>& v1,
00225                       const ACE_Vector<T>& v2,
00226                       const size_t from_ndx,
00227                       const size_t to_ndx);
00228 #endif /* 0 */
00229 
00230 #if defined (__ACE_INLINE__)
00231 #include "ace/Vector_T.i"
00232 #endif /* __ACE_INLINE__ */
00233 
00234 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
00235 #include "ace/Vector_T.cpp"
00236 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
00237 
00238 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
00239 #pragma implementation ("Vector_T.cpp")
00240 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
00241 
00242 #include "ace/post.h"
00243 
00244 #endif /* ACE_VECTOR_T_H */

Generated on Mon Jun 16 11:22:04 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002