1 // This is the STL wrapper for classlib/arrays.h from Borland's web site
2 // It has been modified to be compatible with vc++ (Paul Branann 5/7/98)
4 #ifndef STL_ARRAY_AS_VECTOR
5 #define STL_ARRAY_AS_VECTOR
8 #pragma warning(disable: 4786)
11 // #include <vector.h>
18 class TArrayAsVector
: public vector
<T
> {
20 const unsigned int growable
;
21 const size_type lowerbound
;
23 TArrayAsVector(size_type upper
,
29 { reserve(upper
-lower
+ 1);}
32 { // This call is unnecessary? (Paul Brannan 5/7/98)
33 // vector<T>::~vector( );
36 int Add(const T
& item
)
37 { if(!growable
&& size( ) == capacity( ))
43 int AddAt(const T
& item
, size_type index
)
45 ((size( ) == capacity( )) ||
46 (ZeroBase(index
> capacity( )) )))
48 if(ZeroBase(index
) > capacity( )) // out of bounds
50 ZeroBase(index
) - size( ), T( ));
51 insert(end( ), item
); }
53 { insert(begin( ) + ZeroBase(index
), item
); }
57 size_type
ArraySize( )
58 { return capacity( ); }
60 size_type
BoundBase(size_type location
) const
61 { if(location
== UINT_MAX
)
64 return location
+ lowerbound
; }
65 void Detach(size_type index
)
66 { erase(begin( ) + ZeroBase(index
)); }
68 void Detach(const T
& item
)
69 { Destroy(Find(item
)); }
71 void Destroy(size_type index
)
72 { erase(begin( ) + ZeroBase(index
)); }
74 void Destroy(const T
& item
)
75 { Destroy(Find(item
)); }
77 size_type
Find(const T
& item
) const
78 { const_iterator location
= find(begin( ),
80 if(location
!= end( ))
81 return BoundBase(size_type(location
-
86 size_type
GetItemsInContainer( )
89 void Grow(size_type index
)
90 { if( index
< lowerbound
)
91 Reallocate(ArraySize( ) + (index
-
93 else if( index
>= BoundBase(size( )))
94 Reallocate(ZeroBase(index
) ); }
96 int HasMember(const T
& item
)
97 { if(Find(item
) != INT_MAX
)
108 if(size( ) == capacity( ))
113 size_type
LowerBound( )
114 { return lowerbound
; }
116 T
& operator[] (size_type index
)
118 operator[](ZeroBase(index
)); }
120 const T
& operator[] (size_type index
) const
122 operator[](ZeroBase(index
)); }
126 // changed this to get it to work with VC++
127 // (Paul Brannan 5/7/98)
129 _Destroy(begin(), end());
132 destroy(begin( ), end( ));
134 // _M_finish = _M_start;
141 void Reallocate(size_type sz
,
142 size_type offset
= 0)
144 insert(begin( ), offset
, T( ));
146 erase(end( ) - offset
, end( )); }
148 void RemoveEntry(size_type index
)
151 void SetData(size_type index
, const T
& item
)
152 { (*this)[index
] = item
; }
154 size_type
UpperBound( )
155 { return BoundBase(capacity( )) - 1; }
157 size_type
ZeroBase(size_type index
) const
158 { return index
- lowerbound
; }
160 // The assignment operator is not inherited (Paul Brannan 5/25/98)
161 TArrayAsVector
& operator=(const TArrayAsVector
& v
) {
162 vector
<T
>::operator=(v
);
163 // should growable and lowerbound be copied as well?