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 //#else
136 // finish = start;
137 //#endif
138 #endif
139 }
140
141 void Reallocate(size_type sz,
142 size_type offset = 0)
143 { if(offset)
144 insert(begin( ), offset, T( ));
145 reserve(sz);
146 erase(end( ) - offset, end( )); }
147
148 void RemoveEntry(size_type index)
149 { Detach(index); }
150
151 void SetData(size_type index, const T& item)
152 { (*this)[index] = item; }
153
154 size_type UpperBound( )
155 { return BoundBase(capacity( )) - 1; }
156
157 size_type ZeroBase(size_type index) const
158 { return index - lowerbound; }
159
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?
164 return *this;
165 }
166
167 };
168
169 #endif