Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenstl_bids.h
Go to the documentation of this file.
00001 // This is the STL wrapper for classlib/arrays.h from Borland's web site 00002 // It has been modified to be compatible with vc++ (Paul Branann 5/7/98) 00003 00004 #pragma once 00005 00006 #ifdef _MSC_VER 00007 #pragma warning(disable: 4786) 00008 #endif 00009 00010 // #include <vector.h> 00011 // #include <algo.h> 00012 #include <vector> 00013 #include <algorithm> 00014 #include <limits.h> 00015 using namespace std; 00016 00017 template <class T> 00018 class TArrayAsVector : public vector<T> { 00019 private: 00020 const unsigned int growable; 00021 typedef size_t size_type; 00022 typedef typename vector<T>::const_iterator const_iterator; 00023 const size_type lowerbound; 00024 public: 00025 TArrayAsVector(size_type upper, 00026 size_type lower = 0, 00027 int delta = 0) : 00028 vector<T>( ), 00029 growable(delta), 00030 lowerbound(lower) 00031 { vector<T>::reserve(upper-lower + 1);} 00032 00033 ~TArrayAsVector( ) 00034 { // This call is unnecessary? (Paul Brannan 5/7/98) 00035 // vector<T>::~vector( ); 00036 } 00037 00038 int Add(const T& item) 00039 { if(!growable && vector<T>::size( ) == vector<T>::capacity( )) 00040 return 0; 00041 else 00042 vector<T>::insert(vector<T>::end( ), item); 00043 return 1; } 00044 00045 int AddAt(const T& item, size_type index) 00046 { if(!growable && 00047 ((vector<T>::size( ) == vector<T>::capacity( )) || 00048 (ZeroBase(index > vector<T>::capacity( )) ))) 00049 return 0; 00050 if(ZeroBase(index) > vector<T>::capacity( )) // out of bounds 00051 { vector<T>::insert(vector<T>::end( ), 00052 ZeroBase(index) - vector<T>::size( ), T( )); 00053 vector<T>::insert(vector<T>::end( ), item); } 00054 else 00055 { vector<T>::insert(vector<T>::begin( ) + ZeroBase(index), item); } 00056 return 1; 00057 } 00058 00059 size_type ArraySize( ) 00060 { return vector<T>::capacity( ); } 00061 00062 size_type BoundBase(size_type location) const 00063 { if(location == UINT_MAX) 00064 return INT_MAX; 00065 else 00066 return location + lowerbound; } 00067 void Detach(size_type index) 00068 { vector<T>::erase(vector<T>::begin( ) + ZeroBase(index)); } 00069 00070 void Detach(const T& item) 00071 { Destroy(Find(item)); } 00072 00073 void Destroy(size_type index) 00074 { vector<T>::erase(vector<T>::begin( ) + ZeroBase(index)); } 00075 00076 void Destroy(const T& item) 00077 { Destroy(Find(item)); } 00078 00079 size_type Find(const T& item) const 00080 { const_iterator location = find(vector<T>::begin( ), 00081 vector<T>::end( ), item); 00082 if(location != vector<T>::end( )) 00083 return BoundBase(size_type(location - 00084 vector<T>::begin( ))); 00085 else 00086 return INT_MAX; } 00087 00088 size_type GetItemsInContainer( ) 00089 { return vector<T>::size( ); } 00090 00091 void Grow(size_type index) 00092 { if( index < lowerbound ) 00093 Reallocate(ArraySize( ) + (index - 00094 lowerbound)); 00095 else if( index >= BoundBase(vector<T>::size( ))) 00096 Reallocate(ZeroBase(index) ); } 00097 00098 int HasMember(const T& item) 00099 { if(Find(item) != INT_MAX) 00100 return 1; 00101 else 00102 return 0; } 00103 00104 int IsEmpty( ) 00105 { return vector<T>::empty( ); } 00106 00107 int IsFull( ) 00108 { if(growable) 00109 return 0; 00110 if(vector<T>::size( ) == vector<T>::capacity( )) 00111 return 1; 00112 else 00113 return 0; } 00114 00115 size_type LowerBound( ) 00116 { return lowerbound; } 00117 00118 T& operator[] (size_type index) 00119 { return vector<T>:: 00120 operator[](ZeroBase(index)); } 00121 00122 const T& operator[] (size_type index) const 00123 { return vector<T>:: 00124 operator[](ZeroBase(index)); } 00125 00126 void Flush( ) 00127 { 00128 vector<T>::clear(); 00129 } 00130 00131 void Reallocate(size_type sz, 00132 size_type offset = 0) 00133 { if(offset) 00134 vector<T>::insert(vector<T>::begin( ), offset, T( )); 00135 vector<T>::reserve(sz); 00136 vector<T>::erase(vector<T>::end( ) - offset, vector<T>::end( )); } 00137 00138 void RemoveEntry(size_type index) 00139 { Detach(index); } 00140 00141 void SetData(size_type index, const T& item) 00142 { (*this)[index] = item; } 00143 00144 size_type UpperBound( ) 00145 { return BoundBase(vector<T>::capacity( )) - 1; } 00146 00147 size_type ZeroBase(size_type index) const 00148 { return index - lowerbound; } 00149 00150 // The assignment operator is not inherited (Paul Brannan 5/25/98) 00151 TArrayAsVector& operator=(const TArrayAsVector& v) { 00152 vector<T>::operator=(v); 00153 // should growable and lowerbound be copied as well? 00154 return *this; 00155 } 00156 00157 }; Generated on Fri May 25 2012 04:15:33 for ReactOS by
1.7.6.1
|