Fixes for real this time for new telnet client
[reactos.git] / rosapps / net / telnet / src / stl_bids.h
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)
3
4 #ifndef STL_ARRAY_AS_VECTOR
5 #define STL_ARRAY_AS_VECTOR
6
7 #ifdef _MSC_VER
8 #pragma warning(disable: 4786)
9 #endif
10
11 // #include <vector.h>
12 // #include <algo.h>
13 #include <vector>
14 #include <algorithm>
15 using namespace std;
16
17 template <class T>
18 class TArrayAsVector : public vector<T> {
19 private:
20 const unsigned int growable;
21 const size_type lowerbound;
22 public:
23 TArrayAsVector(size_type upper,
24 size_type lower = 0,
25 int delta = 0) :
26 vector<T>( ),
27 growable(delta),
28 lowerbound(lower)
29 { reserve(upper-lower + 1);}
30
31 ~TArrayAsVector( )
32 { // This call is unnecessary? (Paul Brannan 5/7/98)
33 // vector<T>::~vector( );
34 }
35
36 int Add(const T& item)
37 { if(!growable && size( ) == capacity( ))
38 return 0;
39 else
40 insert(end( ), item);
41 return 1; }
42
43 int AddAt(const T& item, size_type index)
44 { if(!growable &&
45 ((size( ) == capacity( )) ||
46 (ZeroBase(index > capacity( )) )))
47 return 0;
48 if(ZeroBase(index) > capacity( )) // out of bounds
49 { insert(end( ),
50 ZeroBase(index) - size( ), T( ));
51 insert(end( ), item); }
52 else
53 { insert(begin( ) + ZeroBase(index), item); }
54 return 1;
55 }
56
57 size_type ArraySize( )
58 { return capacity( ); }
59
60 size_type BoundBase(size_type location) const
61 { if(location == UINT_MAX)
62 return INT_MAX;
63 else
64 return location + lowerbound; }
65 void Detach(size_type index)
66 { erase(begin( ) + ZeroBase(index)); }
67
68 void Detach(const T& item)
69 { Destroy(Find(item)); }
70
71 void Destroy(size_type index)
72 { erase(begin( ) + ZeroBase(index)); }
73
74 void Destroy(const T& item)
75 { Destroy(Find(item)); }
76
77 size_type Find(const T& item) const
78 { const_iterator location = find(begin( ),
79 end( ), item);
80 if(location != end( ))
81 return BoundBase(size_type(location -
82 begin( )));
83 else
84 return INT_MAX; }
85
86 size_type GetItemsInContainer( )
87 { return size( ); }
88
89 void Grow(size_type index)
90 { if( index < lowerbound )
91 Reallocate(ArraySize( ) + (index -
92 lowerbound));
93 else if( index >= BoundBase(size( )))
94 Reallocate(ZeroBase(index) ); }
95
96 int HasMember(const T& item)
97 { if(Find(item) != INT_MAX)
98 return 1;
99 else
100 return 0; }
101
102 int IsEmpty( )
103 { return empty( ); }
104
105 int IsFull( )
106 { if(growable)
107 return 0;
108 if(size( ) == capacity( ))
109 return 1;
110 else
111 return 0; }
112
113 size_type LowerBound( )
114 { return lowerbound; }
115
116 T& operator[] (size_type index)
117 { return vector<T>::
118 operator[](ZeroBase(index)); }
119
120 const T& operator[] (size_type index) const
121 { return vector<T>::
122 operator[](ZeroBase(index)); }
123
124 void Flush( )
125 {
126 // changed this to get it to work with VC++
127 // (Paul Brannan 5/7/98)
128 #ifdef _MSC_VER
129 _Destroy(begin(), end());
130 _Last = _First;
131 #else
132 destroy(begin( ), end( ));
133 #ifdef __CYGWIN__
134 _M_finish = _M_start;
135 #endif
136 // finish = start; /* Removed for ReactOS */
137 #ifdef __REACTOS__
138 _M_finish = _M_start;
139 #endif
140 #endif
141 }
142
143 void Reallocate(size_type sz,
144 size_type offset = 0)
145 { if(offset)
146 insert(begin( ), offset, T( ));
147 reserve(sz);
148 erase(end( ) - offset, end( )); }
149
150 void RemoveEntry(size_type index)
151 { Detach(index); }
152
153 void SetData(size_type index, const T& item)
154 { (*this)[index] = item; }
155
156 size_type UpperBound( )
157 { return BoundBase(capacity( )) - 1; }
158
159 size_type ZeroBase(size_type index) const
160 { return index - lowerbound; }
161
162 // The assignment operator is not inherited (Paul Brannan 5/25/98)
163 TArrayAsVector& operator=(const TArrayAsVector& v) {
164 vector<T>::operator=(v);
165 // should growable and lowerbound be copied as well?
166 return *this;
167 }
168
169 };
170
171 #endif