ReactOS  0.4.11-dev-946-g431643b
stl_bids.h
Go to the documentation of this file.
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 #pragma once
5 
6 #ifdef _MSC_VER
7 #pragma warning(disable: 4786)
8 #endif
9 
10 // #include <vector.h>
11 // #include <algo.h>
12 #include <vector>
13 #include <algorithm>
14 //#include <limits.h>
15 using namespace std;
16 
17 template <class T>
18 class TArrayAsVector : public vector<T> {
19 private:
20  const unsigned int growable;
21  typedef size_t size_type;
22  typedef typename vector<T>::const_iterator const_iterator;
23  const size_type lowerbound;
24 public:
25  TArrayAsVector(size_type upper,
26  size_type lower = 0,
27  int delta = 0) :
28  vector<T>( ),
29  growable(delta),
30  lowerbound(lower)
31  { vector<T>::reserve(upper-lower + 1);}
32 
34  { // This call is unnecessary? (Paul Brannan 5/7/98)
35  // vector<T>::~vector( );
36  }
37 
38  int Add(const T& item)
39  { if(!growable && vector<T>::size( ) == vector<T>::capacity( ))
40  return 0;
41  else
43  return 1; }
44 
45  int AddAt(const T& item, size_type index)
46  { if(!growable &&
47  ((vector<T>::size( ) == vector<T>::capacity( )) ||
48  (ZeroBase(index > vector<T>::capacity( )) )))
49  return 0;
50  if(ZeroBase(index) > vector<T>::capacity( )) // out of bounds
52  ZeroBase(index) - vector<T>::size( ), T( ));
54  else
55  { vector<T>::insert(vector<T>::begin( ) + ZeroBase(index), item); }
56  return 1;
57  }
58 
59  size_type ArraySize( )
60  { return vector<T>::capacity( ); }
61 
62  size_type BoundBase(size_type location) const
63  { if(location == UINT_MAX)
64  return INT_MAX;
65  else
66  return location + lowerbound; }
67  void Detach(size_type index)
68  { vector<T>::erase(vector<T>::begin( ) + ZeroBase(index)); }
69 
70  void Detach(const T& item)
71  { Destroy(Find(item)); }
72 
73  void Destroy(size_type index)
74  { vector<T>::erase(vector<T>::begin( ) + ZeroBase(index)); }
75 
76  void Destroy(const T& item)
77  { Destroy(Find(item)); }
78 
79  size_type Find(const T& item) const
80  { const_iterator location = find(vector<T>::begin( ),
81  vector<T>::end( ), item);
82  if(location != vector<T>::end( ))
83  return BoundBase(size_type(location -
84  vector<T>::begin( )));
85  else
86  return INT_MAX; }
87 
88  size_type GetItemsInContainer( )
89  { return vector<T>::size( ); }
90 
91  void Grow(size_type index)
92  { if( index < lowerbound )
93  Reallocate(ArraySize( ) + (index -
94  lowerbound));
95  else if( index >= BoundBase(vector<T>::size( )))
96  Reallocate(ZeroBase(index) ); }
97 
98  int HasMember(const T& item)
99  { if(Find(item) != INT_MAX)
100  return 1;
101  else
102  return 0; }
103 
104  int IsEmpty( )
105  { return vector<T>::empty( ); }
106 
107  int IsFull( )
108  { if(growable)
109  return 0;
110  if(vector<T>::size( ) == vector<T>::capacity( ))
111  return 1;
112  else
113  return 0; }
114 
115  size_type LowerBound( )
116  { return lowerbound; }
117 
118  T& operator[] (size_type index)
119  { return vector<T>::
120  operator[](ZeroBase(index)); }
121 
122  const T& operator[] (size_type index) const
123  { return vector<T>::
124  operator[](ZeroBase(index)); }
125 
126  void Flush( )
127  {
129  }
130 
131  void Reallocate(size_type sz,
132  size_type offset = 0)
133  { if(offset)
135  vector<T>::reserve(sz);
137 
138  void RemoveEntry(size_type index)
139  { Detach(index); }
140 
141  void SetData(size_type index, const T& item)
142  { (*this)[index] = item; }
143 
144  size_type UpperBound( )
145  { return BoundBase(vector<T>::capacity( )) - 1; }
146 
147  size_type ZeroBase(size_type index) const
148  { return index - lowerbound; }
149 
150  // The assignment operator is not inherited (Paul Brannan 5/25/98)
153  // should growable and lowerbound be copied as well?
154  return *this;
155  }
156 
157 };
size_type BoundBase(size_type location) const
Definition: stl_bids.h:62
#define INT_MAX
Definition: limits.h:40
const unsigned int growable
Definition: stl_bids.h:20
_Self & operator=(const _Self &__x)
Definition: _vector.c:182
GLintptr offset
Definition: glext.h:5920
void Detach(size_type index)
Definition: stl_bids.h:67
GLuint GLuint end
Definition: gl.h:1545
size_type ArraySize()
Definition: stl_bids.h:59
size_type Find(const T &item) const
Definition: stl_bids.h:79
Definition: features.h:417
void Reallocate(size_type sz, size_type offset=0)
Definition: stl_bids.h:131
#define T
Definition: mbstring.h:31
TArrayAsVector(size_type upper, size_type lower=0, int delta=0)
Definition: stl_bids.h:25
bool empty() const
Definition: _vector.h:200
int HasMember(const T &item)
Definition: stl_bids.h:98
iterator insert(iterator __pos, const _Tp &__x=_STLP_DEFAULT_CONSTRUCTED(_Tp))
Definition: _vector.c:223
void Flush()
Definition: stl_bids.h:126
GLuint index
Definition: glext.h:6031
static clock_t begin
Definition: xmllint.c:466
GLsizeiptr size
Definition: glext.h:5919
void RemoveEntry(size_type index)
Definition: stl_bids.h:138
size_type ZeroBase(size_type index) const
Definition: stl_bids.h:147
size_t size_type
Definition: stl_bids.h:21
iterator erase(iterator __pos)
Definition: _vector.h:620
#define index(s, c)
Definition: various.h:29
void Grow(size_type index)
Definition: stl_bids.h:91
#define UINT_MAX
Definition: limits.h:41
void SetData(size_type index, const T &item)
Definition: stl_bids.h:141
static ATOM item
Definition: dde.c:856
vector< T >::const_iterator const_iterator
Definition: stl_bids.h:22
const GLdouble * v
Definition: gl.h:2040
void Destroy(const T &item)
Definition: stl_bids.h:76
int Add(const T &item)
Definition: stl_bids.h:38
size_type GetItemsInContainer()
Definition: stl_bids.h:88
static TAGID TAGID find
Definition: db.cpp:143
size_type size() const
Definition: _vector.h:192
int IsFull()
Definition: stl_bids.h:107
size_type capacity() const
Definition: _vector.h:199
size_type UpperBound()
Definition: stl_bids.h:144
size_type LowerBound()
Definition: stl_bids.h:115
void clear()
Definition: _vector.h:650
int AddAt(const T &item, size_type index)
Definition: stl_bids.h:45
void Detach(const T &item)
Definition: stl_bids.h:70
int IsEmpty()
Definition: stl_bids.h:104
reference operator[](size_type __n)
Definition: _vector.h:202
const size_type lowerbound
Definition: stl_bids.h:23
void Destroy(size_type index)
Definition: stl_bids.h:73
void reserve(size_type __n)
Definition: _vector.c:62
TArrayAsVector & operator=(const TArrayAsVector &v)
Definition: stl_bids.h:151