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

uvector.h

Go to the documentation of this file.
00001 /*
00002 **********************************************************************
00003 *   Copyright (C) 1999, International Business Machines
00004 *   Corporation and others.  All Rights Reserved.
00005 **********************************************************************
00006 *   Date        Name        Description
00007 *   10/22/99    alan        Creation.  This is an internal header.
00008 *                           It should not be exported.
00009 **********************************************************************
00010 */
00011 
00012 #ifndef UVECTOR_H
00013 #define UVECTOR_H
00014 
00015 #include "unicode/utypes.h"
00016 
00067 class U_COMMON_API UVector {
00068 public:
00069     typedef void (*Deleter)(void*);
00070     typedef UBool (*Comparer)(void*, void*);
00071 
00072 private:
00073     int32_t count;
00074 
00075     int32_t capacity;
00076 
00077     void** elements;
00078 
00079     Deleter deleter;
00080 
00081     Comparer comparer;
00082 
00083     static UBool outOfMemory;
00084 
00085 public:
00086     UVector(int32_t initialCapacity = 8);
00087 
00088     UVector(Deleter d, Comparer c, int32_t initialCapacity = 8);
00089 
00090     ~UVector();
00091 
00092     //------------------------------------------------------------
00093     // java.util.Vector API
00094     //------------------------------------------------------------
00095 
00096     void addElement(void* obj);
00097 
00098     void setElementAt(void* obj, int32_t index);
00099 
00100     void insertElementAt(void* obj, int32_t index);
00101 
00102     void* elementAt(int32_t index) const;
00103 
00104     void* firstElement(void) const;
00105 
00106     void* lastElement(void) const;
00107 
00108     int32_t indexOf(void* obj, int32_t startIndex = 0) const;
00109 
00110     UBool contains(void* obj) const;
00111 
00112     void removeElementAt(int32_t index);
00113 
00114     UBool removeElement(void* obj);
00115 
00116     void removeAllElements();
00117 
00118     int32_t size(void) const;
00119 
00120     UBool isEmpty(void) const;
00121 
00122     UBool ensureCapacity(int32_t minimumCapacity);
00123 
00124     //------------------------------------------------------------
00125     // New API
00126     //------------------------------------------------------------
00127 
00128     Deleter setDeleter(Deleter d);
00129 
00130     Comparer setComparer(Comparer c);
00131 
00132     static UBool isOutOfMemory(void);
00133 
00134     void* operator[](int32_t index) const;
00135 
00145     void* orphanElementAt(int32_t index);
00146 
00147 private:
00148     void _init(int32_t initialCapacity);
00149 
00150     // Disallow
00151     UVector(const UVector&);
00152 
00153     // Disallow
00154     UVector& operator=(const UVector&);
00155 };
00156 
00157 
00174 class U_COMMON_API UStack : public UVector {
00175 public:
00176     UStack(int32_t initialCapacity = 8);
00177 
00178     UStack(Deleter d, Comparer c, int32_t initialCapacity = 8);
00179 
00180     // It's okay not to have a virtual destructor (in UVector)
00181     // because UStack has no special cleanup to do.
00182 
00183     UBool empty(void) const;
00184 
00185     void* peek(void) const;
00186     
00187     void* pop(void);
00188     
00189     void* push(void* obj);
00190 
00191     int32_t search(void* obj) const;
00192 
00193 private:
00194     // Disallow
00195     UStack(const UStack&);
00196 
00197     // Disallow
00198     UStack& operator=(const UStack&);
00199 };
00200 
00201 
00202 // UVector inlines
00203 
00204 inline int32_t UVector::size(void) const {
00205     return count;
00206 }
00207 
00208 inline UBool UVector::isEmpty(void) const {
00209     return count == 0;
00210 }
00211 
00212 inline UBool UVector::contains(void* obj) const {
00213     return indexOf(obj) >= 0;
00214 }
00215 
00216 inline void* UVector::firstElement(void) const {
00217     return elementAt(0);
00218 }
00219 
00220 inline void* UVector::lastElement(void) const {
00221     return elementAt(count-1);
00222 }
00223 
00224 inline void* UVector::operator[](int32_t index) const {
00225     return elementAt(index);
00226 }
00227 
00228 // UStack inlines
00229 
00230 inline UBool UStack::empty(void) const {
00231     return isEmpty();
00232 }
00233 
00234 inline void* UStack::peek(void) const {
00235     return lastElement();
00236 }
00237 
00238 inline void* UStack::push(void* obj) {
00239     addElement(obj);
00240     return obj;
00241 }
00242 
00243 #endif

Generated at Tue Dec 5 17:55:38 2000 for ICU by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000