summaryrefslogtreecommitdiff
path: root/STL
diff options
context:
space:
mode:
authorirfan <irfan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1996-12-01 06:19:11 +0000
committerirfan <irfan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1996-12-01 06:19:11 +0000
commitcd136206c84738a63c0f67e29eb3856c7798c29b (patch)
tree83a385977408b3da5041c1746b16e4820615510e /STL
parent8407bcd88835f9a2a38a9485581e91cee4613477 (diff)
downloadATCD-cd136206c84738a63c0f67e29eb3856c7798c29b.tar.gz
*** empty log message ***
Diffstat (limited to 'STL')
-rw-r--r--STL/ACE_Changes53
-rw-r--r--STL/algobase.h2
-rw-r--r--STL/bstring.h12
-rw-r--r--STL/bvector.cpp80
-rw-r--r--STL/bvector.h492
-rw-r--r--STL/defalloc.h67
-rw-r--r--STL/deque.h8
-rw-r--r--STL/iterator.h24
-rw-r--r--STL/list.h366
-rw-r--r--STL/queue.h1
-rw-r--r--STL/readme2.stl272
-rw-r--r--STL/tree.h40
-rw-r--r--STL/vector.h11
13 files changed, 916 insertions, 512 deletions
diff --git a/STL/ACE_Changes b/STL/ACE_Changes
new file mode 100644
index 00000000000..902fb94c94c
--- /dev/null
+++ b/STL/ACE_Changes
@@ -0,0 +1,53 @@
+This version of STL was obtained from
+http://www.rahul.net/terris/. This is a modified version of the
+implementation that comes with VC++4.0. Please see readme2.stl for
+details.
+
+The following modification have been made for compilation with VC++4.x
+
+________________________________________
+
+vector.h (line 85)
+________________________________________
+
+
+ /*
+ * This is cause the VC++ compiler sucks
+ * and does not recognize nested classes properly
+ *
+ */
+#if !defined (VC_PLUS_PLUS_NESTED_CLASS_PROBLEM)
+ vector(size_type n, const T& value = T()) {
+ start = static_allocator.allocate(n);
+ uninitialized_fill_n(start, n, value);
+ finish = start + n;
+ end_of_storage = finish;
+ }
+#endif /* VC_PLUS_PLUS_NESTED_CLASS_PROBLEM */
+
+
+________________________________________
+
+bstring.h (line 1102)
+________________________________________
+
+
+ /*
+ * This should be correctly scoped
+ *
+ * if (cap == ::reserve)
+ */
+
+ if (cap == std::reserve)
+ {
+ len = 0;
+ res = size;
+ ptr = new charT [res];
+ }
+ /*
+ * This should be correctly scoped
+ *
+ * else if ((cap == ::default_size) && (size != NPOS))
+ */
+
+ else if ((cap == std::default_size) && (size != NPOS))
diff --git a/STL/algobase.h b/STL/algobase.h
index 24c6f7d398f..b3f5fbbb697 100644
--- a/STL/algobase.h
+++ b/STL/algobase.h
@@ -48,7 +48,6 @@ inline void swap(T& a, T& b) {
b = tmp;
}
-/*
template <class T>
inline const T& min(const T& a, const T& b) {
return b < a ? b : a;
@@ -68,7 +67,6 @@ template <class T, class Compare>
inline const T& max(const T& a, const T& b, Compare comp) {
return comp(a, b) ? b : a;
}
-*/
template <class InputIterator, class Distance>
void __distance(InputIterator first, InputIterator last, Distance& n,
diff --git a/STL/bstring.h b/STL/bstring.h
index bcab7de632c..dd53a07e25c 100644
--- a/STL/bstring.h
+++ b/STL/bstring.h
@@ -1099,12 +1099,24 @@ template <class charT>
basic_string_ref<charT>::basic_string_ref (size_t size, capacity cap)
_THROW_ALLOC_LENGTH
{
+ /*
+ * This should be correctly scoped
+ *
+ * if (cap == ::reserve)
+ */
+
if (cap == std::reserve)
{
len = 0;
res = size;
ptr = new charT [res];
}
+ /*
+ * This should be correctly scoped
+ *
+ * else if ((cap == ::default_size) && (size != NPOS))
+ */
+
else if ((cap == std::default_size) && (size != NPOS))
{
res = len = size;
diff --git a/STL/bvector.cpp b/STL/bvector.cpp
new file mode 100644
index 00000000000..86b134c4b5e
--- /dev/null
+++ b/STL/bvector.cpp
@@ -0,0 +1,80 @@
+#define STL_BVECTOR
+#define SA_STD std
+#include <bvector.h>
+
+namespace std
+{
+
+Allocator<unsigned int> bit_vector::static_allocator;
+
+inline bool operator==(const bit_vector& x, const bit_vector& y) {
+ return x.size() == y.size() && equal(x.begin(), x.end(), y.begin());
+}
+
+inline bool operator<(const bit_vector& x, const bit_vector& y) {
+ return lexicographical_compare(x.begin(), x.end(), y.begin(), y.end());
+}
+
+void swap(bit_vector::reference x, bit_vector::reference y) {
+ bool tmp = x;
+ x = y;
+ y = tmp;
+}
+
+void bit_vector::insert_aux(iterator position, bool x) {
+ if (finish.p != end_of_storage) {
+ copy_backward(position, finish - 1, finish);
+ *position = x;
+ ++finish;
+ } else {
+ size_type len = size() ? 2 * size() : __WORD_BIT;
+ unsigned int* q = bit_alloc(len);
+ iterator i = copy(begin(), position, iterator(q, 0));
+ *i++ = x;
+ finish = copy(position, end(), i);
+ static_allocator.deallocate(start.p);
+ end_of_storage = q + (len + __WORD_BIT - 1)/__WORD_BIT;
+ start = iterator(q, 0);
+ }
+}
+
+void bit_vector::insert(iterator position, size_type n, bool x) {
+ if (n == 0) return;
+ if (capacity() - size() >= n) {
+ copy_backward(position, end(), finish + n);
+ fill(position, position + n, x);
+ finish += n;
+ } else {
+ size_type len = size() + max(size(), n);
+ unsigned int* q = bit_alloc(len);
+ iterator i = copy(begin(), position, iterator(q, 0));
+ fill_n(i, n, x);
+ finish = copy(position, end(), i + n);
+ static_allocator.deallocate(start.p);
+ end_of_storage = q + (n + __WORD_BIT - 1)/__WORD_BIT;
+ start = iterator(q, 0);
+ }
+}
+
+void bit_vector::insert(iterator position, const_iterator first,
+ const_iterator last) {
+ if (first == last) return;
+ size_type n = 0;
+ distance(first, last, n);
+ if (capacity() - size() >= n) {
+ copy_backward(position, end(), finish + n);
+ copy(first, last, position);
+ finish += n;
+ } else {
+ size_type len = size() + max(size(), n);
+ unsigned int* q = bit_alloc(len);
+ iterator i = copy(begin(), position, iterator(q, 0));
+ i = copy(first, last, i);
+ finish = copy(position, end(), i);
+ static_allocator.deallocate(start.p);
+ end_of_storage = q + (len + __WORD_BIT - 1)/__WORD_BIT;
+ start = iterator(q, 0);
+ }
+}
+
+} \ No newline at end of file
diff --git a/STL/bvector.h b/STL/bvector.h
index b206a40f36d..01f66ecddd3 100644
--- a/STL/bvector.h
+++ b/STL/bvector.h
@@ -55,182 +55,182 @@ public:
friend class iterator;
friend class const_iterator;
protected:
- unsigned int* p;
- unsigned int mask;
- reference(unsigned int* x, unsigned int y) : p(x), mask(y) {}
+ unsigned int* p;
+ unsigned int mask;
+ reference(unsigned int* x, unsigned int y) : p(x), mask(y) {}
public:
- reference() : p(0), mask(0) {}
- operator bool() const { return !(!(*p & mask)); }
- reference& operator=(bool x) {
- if (x)
- *p |= mask;
- else
- *p &= ~mask;
- return *this;
- }
- reference& operator=(const reference& x) { return *this = bool(x); }
- bool operator==(const reference& x) const {
- return bool(*this) == bool(x);
- }
- bool operator<(const reference& x) const {
- return bool(*this) < bool(x);
- }
- void flip() { *p ^= mask; }
+ reference() : p(0), mask(0) {}
+ operator bool() const { return !(!(*p & mask)); }
+ reference& operator=(bool x) {
+ if (x)
+ *p |= mask;
+ else
+ *p &= ~mask;
+ return *this;
+ }
+ reference& operator=(const reference& x) { return *this = bool(x); }
+ bool operator==(const reference& x) const {
+ return bool(*this) == bool(x);
+ }
+ bool operator<(const reference& x) const {
+ return bool(*this) < bool(x);
+ }
+ void flip() { *p ^= mask; }
};
typedef bool const_reference;
class iterator : public random_access_iterator<bool, difference_type> {
friend class bit_vector;
friend class const_iterator;
protected:
- unsigned int* p;
- unsigned int offset;
- void bump_up() {
- if (offset++ == __WORD_BIT - 1) {
- offset = 0;
- ++p;
- }
- }
+ unsigned int* p;
+ unsigned int offset;
+ void bump_up() {
+ if (offset++ == __WORD_BIT - 1) {
+ offset = 0;
+ ++p;
+ }
+ }
void bump_down() {
- if (offset-- == 0) {
- offset = __WORD_BIT - 1;
- --p;
- }
+ if (offset-- == 0) {
+ offset = __WORD_BIT - 1;
+ --p;
+ }
}
public:
- iterator() : p(0), offset(0) {}
- iterator(unsigned int* x, unsigned int y) : p(x), offset(y) {}
- reference operator*() const { return reference(p, 1U << offset); }
- iterator& operator++() {
- bump_up();
- return *this;
- }
- iterator operator++(int) {
- iterator tmp = *this;
- bump_up();
- return tmp;
- }
- iterator& operator--() {
- bump_down();
- return *this;
- }
- iterator operator--(int) {
- iterator tmp = *this;
- bump_down();
- return tmp;
- }
- iterator& operator+=(difference_type i) {
- difference_type n = i + offset;
- p += n / __WORD_BIT;
- n = n % __WORD_BIT;
- if (n < 0) {
- offset = n + __WORD_BIT;
- --p;
- } else
- offset = n;
- return *this;
- }
- iterator& operator-=(difference_type i) {
- *this += -i;
- return *this;
- }
- iterator operator+(difference_type i) const {
- iterator tmp = *this;
- return tmp += i;
- }
- iterator operator-(difference_type i) const {
- iterator tmp = *this;
- return tmp -= i;
- }
- difference_type operator-(iterator x) const {
- return __WORD_BIT * (p - x.p) + offset - x.offset;
- }
- reference operator[](difference_type i) { return *(*this + i); }
- bool operator==(const iterator& x) const {
- return p == x.p && offset == x.offset;
- }
- bool operator<(iterator x) const {
- return p < x.p || (p == x.p && offset < x.offset);
- }
+ iterator() : p(0), offset(0) {}
+ iterator(unsigned int* x, unsigned int y) : p(x), offset(y) {}
+ reference operator*() const { return reference(p, 1U << offset); }
+ iterator& operator++() {
+ bump_up();
+ return *this;
+ }
+ iterator operator++(int) {
+ iterator tmp = *this;
+ bump_up();
+ return tmp;
+ }
+ iterator& operator--() {
+ bump_down();
+ return *this;
+ }
+ iterator operator--(int) {
+ iterator tmp = *this;
+ bump_down();
+ return tmp;
+ }
+ iterator& operator+=(difference_type i) {
+ difference_type n = i + offset;
+ p += n / __WORD_BIT;
+ n = n % __WORD_BIT;
+ if (n < 0) {
+ offset = n + __WORD_BIT;
+ --p;
+ } else
+ offset = n;
+ return *this;
+ }
+ iterator& operator-=(difference_type i) {
+ *this += -i;
+ return *this;
+ }
+ iterator operator+(difference_type i) const {
+ iterator tmp = *this;
+ return tmp += i;
+ }
+ iterator operator-(difference_type i) const {
+ iterator tmp = *this;
+ return tmp -= i;
+ }
+ difference_type operator-(iterator x) const {
+ return __WORD_BIT * (p - x.p) + offset - x.offset;
+ }
+ reference operator[](difference_type i) { return *(*this + i); }
+ bool operator==(const iterator& x) const {
+ return p == x.p && offset == x.offset;
+ }
+ bool operator<(iterator x) const {
+ return p < x.p || (p == x.p && offset < x.offset);
+ }
};
class const_iterator
- : public random_access_iterator<bool, difference_type> {
+ : public random_access_iterator<bool, difference_type> {
friend class bit_vector;
protected:
- unsigned int* p;
- unsigned int offset;
- void bump_up() {
- if (offset++ == __WORD_BIT - 1) {
- offset = 0;
- ++p;
- }
- }
+ unsigned int* p;
+ unsigned int offset;
+ void bump_up() {
+ if (offset++ == __WORD_BIT - 1) {
+ offset = 0;
+ ++p;
+ }
+ }
void bump_down() {
- if (offset-- == 0) {
- offset = __WORD_BIT - 1;
- --p;
- }
+ if (offset-- == 0) {
+ offset = __WORD_BIT - 1;
+ --p;
+ }
}
public:
- const_iterator() : p(0), offset(0) {}
- const_iterator(unsigned int* x, unsigned int y) : p(x), offset(y) {}
- const_iterator(const iterator& x) : p(x.p), offset(x.offset) {}
- const_reference operator*() const {
- return reference(p, 1U << offset);
- }
- const_iterator& operator++() {
- bump_up();
- return *this;
- }
- const_iterator operator++(int) {
- const_iterator tmp = *this;
- bump_up();
- return tmp;
- }
- const_iterator& operator--() {
- bump_down();
- return *this;
- }
- const_iterator operator--(int) {
- const_iterator tmp = *this;
- bump_down();
- return tmp;
- }
- const_iterator& operator+=(difference_type i) {
- difference_type n = i + offset;
- p += n / __WORD_BIT;
- n = n % __WORD_BIT;
- if (n < 0) {
- offset = n + __WORD_BIT;
- --p;
- } else
- offset = n;
- return *this;
- }
- const_iterator& operator-=(difference_type i) {
- *this += -i;
- return *this;
- }
- const_iterator operator+(difference_type i) const {
- const_iterator tmp = *this;
- return tmp += i;
- }
- const_iterator operator-(difference_type i) const {
- const_iterator tmp = *this;
- return tmp -= i;
- }
- difference_type operator-(const_iterator x) const {
- return __WORD_BIT * (p - x.p) + offset - x.offset;
- }
- const_reference operator[](difference_type i) {
- return *(*this + i);
- }
- bool operator==(const const_iterator& x) const {
- return p == x.p && offset == x.offset;
- }
- bool operator<(const_iterator x) const {
- return p < x.p || (p == x.p && offset < x.offset);
- }
+ const_iterator() : p(0), offset(0) {}
+ const_iterator(unsigned int* x, unsigned int y) : p(x), offset(y) {}
+ const_iterator(const iterator& x) : p(x.p), offset(x.offset) {}
+ const_reference operator*() const {
+ return reference(p, 1U << offset);
+ }
+ const_iterator& operator++() {
+ bump_up();
+ return *this;
+ }
+ const_iterator operator++(int) {
+ const_iterator tmp = *this;
+ bump_up();
+ return tmp;
+ }
+ const_iterator& operator--() {
+ bump_down();
+ return *this;
+ }
+ const_iterator operator--(int) {
+ const_iterator tmp = *this;
+ bump_down();
+ return tmp;
+ }
+ const_iterator& operator+=(difference_type i) {
+ difference_type n = i + offset;
+ p += n / __WORD_BIT;
+ n = n % __WORD_BIT;
+ if (n < 0) {
+ offset = n + __WORD_BIT;
+ --p;
+ } else
+ offset = n;
+ return *this;
+ }
+ const_iterator& operator-=(difference_type i) {
+ *this += -i;
+ return *this;
+ }
+ const_iterator operator+(difference_type i) const {
+ const_iterator tmp = *this;
+ return tmp += i;
+ }
+ const_iterator operator-(difference_type i) const {
+ const_iterator tmp = *this;
+ return tmp -= i;
+ }
+ difference_type operator-(const_iterator x) const {
+ return __WORD_BIT * (p - x.p) + offset - x.offset;
+ }
+ const_reference operator[](difference_type i) {
+ return *(*this + i);
+ }
+ bool operator==(const const_iterator& x) const {
+ return p == x.p && offset == x.offset;
+ }
+ bool operator<(const_iterator x) const {
+ return p < x.p || (p == x.p && offset < x.offset);
+ }
};
typedef reverse_iterator<const_iterator, value_type, const_reference,
@@ -244,13 +244,13 @@ protected:
iterator finish;
unsigned int* end_of_storage;
unsigned int* bit_alloc(size_type n) {
- return static_allocator.allocate((n + __WORD_BIT - 1)/__WORD_BIT);
+ return static_allocator.allocate((n + __WORD_BIT - 1)/__WORD_BIT);
}
void initialize(size_type n) {
- unsigned int* q = bit_alloc(n);
- end_of_storage = q + (n + __WORD_BIT - 1)/__WORD_BIT;
- start = iterator(q, 0);
- finish = start + n;
+ unsigned int* q = bit_alloc(n);
+ end_of_storage = q + (n + __WORD_BIT - 1)/__WORD_BIT;
+ start = iterator(q, 0);
+ finish = start + n;
}
void insert_aux(iterator position, bool x);
typedef bit_vector self;
@@ -272,157 +272,99 @@ public:
size_type size() const { return size_type(end() - begin()); }
size_type max_size() const { return static_allocator.max_size(); }
size_type capacity() const {
- return size_type(const_iterator(end_of_storage, 0) - begin());
+ return size_type(const_iterator(end_of_storage, 0) - begin());
}
bool empty() const { return begin() == end(); }
reference operator[](size_type n) { return *(begin() + n); }
const_reference operator[](size_type n) const { return *(begin() + n); }
bit_vector() : start(iterator()), finish(iterator()), end_of_storage(0) {}
bit_vector(size_type n, bool value = bool()) {
- initialize(n);
- fill(start.p, end_of_storage, value ? ~0 : 0);
+ initialize(n);
+ fill(start.p, end_of_storage, value ? ~0 : 0);
}
bit_vector(const self& x) {
- initialize(x.size());
- copy(x.begin(), x.end(), start);
+ initialize(x.size());
+ copy(x.begin(), x.end(), start);
}
bit_vector(const_iterator first, const_iterator last) {
- size_type n = 0;
- distance(first, last, n);
- initialize(n);
- copy(first, last, start);
+ size_type n = 0;
+ distance(first, last, n);
+ initialize(n);
+ copy(first, last, start);
}
~bit_vector() { static_allocator.deallocate(start.p); }
self& operator=(const self& x) {
- if (&x == this) return *this;
- if (x.size() > capacity()) {
- static_allocator.deallocate(start.p);
- initialize(x.size());
- }
- copy(x.begin(), x.end(), begin());
- finish = begin() + x.size();
- return *this;
+ if (&x == this) return *this;
+ if (x.size() > capacity()) {
+ static_allocator.deallocate(start.p);
+ initialize(x.size());
+ }
+ copy(x.begin(), x.end(), begin());
+ finish = begin() + x.size();
+ return *this;
}
void reserve(size_type n) {
- if (capacity() < n) {
- unsigned int* q = bit_alloc(n);
- finish = copy(begin(), end(), iterator(q, 0));
- static_allocator.deallocate(start.p);
- start = iterator(q, 0);
- end_of_storage = q + (n + __WORD_BIT - 1)/__WORD_BIT;
- }
+ if (capacity() < n) {
+ unsigned int* q = bit_alloc(n);
+ finish = copy(begin(), end(), iterator(q, 0));
+ static_allocator.deallocate(start.p);
+ start = iterator(q, 0);
+ end_of_storage = q + (n + __WORD_BIT - 1)/__WORD_BIT;
+ }
}
reference front() { return *begin(); }
const_reference front() const { return *begin(); }
reference back() { return *(end() - 1); }
const_reference back() const { return *(end() - 1); }
void push_back(bool x) {
- if (finish.p != end_of_storage)
- *finish++ = x;
- else
- insert_aux(end(), x);
+ if (finish.p != end_of_storage)
+ *finish++ = x;
+ else
+ insert_aux(end(), x);
}
void swap(bit_vector& x) {
- std::swap(start, x.start);
- std::swap(finish, x.finish);
- std::swap(end_of_storage, x.end_of_storage);
+ std::swap(start, x.start);
+ std::swap(finish, x.finish);
+ std::swap(end_of_storage, x.end_of_storage);
}
iterator insert(iterator position, bool x) {
- size_type n = position - begin();
- if (finish.p != end_of_storage && position == end())
- *finish++ = x;
- else
- insert_aux(position, x);
- return begin() + n;
+ size_type n = position - begin();
+ if (finish.p != end_of_storage && position == end())
+ *finish++ = x;
+ else
+ insert_aux(position, x);
+ return begin() + n;
}
void insert(iterator position, const_iterator first,
- const_iterator last);
+ const_iterator last);
void insert(iterator position, size_type n, bool x);
void pop_back() { --finish; }
void erase(iterator position) {
- if (position + 1 != end())
- copy(position + 1, end(), position);
- --finish;
+ if (position + 1 != end())
+ copy(position + 1, end(), position);
+ --finish;
}
void erase(iterator first, iterator last) {
- finish = copy(last, end(), first);
+ finish = copy(last, end(), first);
}
};
-Allocator<unsigned int> bit_vector::static_allocator;
+// Code moved to bvector.cpp by Terris
-inline bool operator==(const bit_vector& x, const bit_vector& y) {
- return x.size() == y.size() && equal(x.begin(), x.end(), y.begin());
-}
-
-inline bool operator<(const bit_vector& x, const bit_vector& y) {
- return lexicographical_compare(x.begin(), x.end(), y.begin(), y.end());
-}
-
-void swap(bit_vector::reference x, bit_vector::reference y) {
- bool tmp = x;
- x = y;
- y = tmp;
-}
-
-void bit_vector::insert_aux(iterator position, bool x) {
- if (finish.p != end_of_storage) {
- copy_backward(position, finish - 1, finish);
- *position = x;
- ++finish;
- } else {
- size_type len = size() ? 2 * size() : __WORD_BIT;
- unsigned int* q = bit_alloc(len);
- iterator i = copy(begin(), position, iterator(q, 0));
- *i++ = x;
- finish = copy(position, end(), i);
- static_allocator.deallocate(start.p);
- end_of_storage = q + (len + __WORD_BIT - 1)/__WORD_BIT;
- start = iterator(q, 0);
- }
-}
+// Added by Terris --begin--
+bool operator==(const bit_vector& x, const bit_vector& y);
+bool operator<(const bit_vector& x, const bit_vector& y);
+void swap(bit_vector::reference x, bit_vector::reference y);
+// Added by Terris --end--
-void bit_vector::insert(iterator position, size_type n, bool x) {
- if (n == 0) return;
- if (capacity() - size() >= n) {
- copy_backward(position, end(), finish + n);
- fill(position, position + n, x);
- finish += n;
- } else {
- size_type len = size() + max(size(), n);
- unsigned int* q = bit_alloc(len);
- iterator i = copy(begin(), position, iterator(q, 0));
- fill_n(i, n, x);
- finish = copy(position, end(), i + n);
- static_allocator.deallocate(start.p);
- end_of_storage = q + (n + __WORD_BIT - 1)/__WORD_BIT;
- start = iterator(q, 0);
- }
-}
-
-void bit_vector::insert(iterator position, const_iterator first,
- const_iterator last) {
- if (first == last) return;
- size_type n = 0;
- distance(first, last, n);
- if (capacity() - size() >= n) {
- copy_backward(position, end(), finish + n);
- copy(first, last, position);
- finish += n;
- } else {
- size_type len = size() + max(size(), n);
- unsigned int* q = bit_alloc(len);
- iterator i = copy(begin(), position, iterator(q, 0));
- i = copy(first, last, i);
- finish = copy(position, end(), i);
- static_allocator.deallocate(start.p);
- end_of_storage = q + (len + __WORD_BIT - 1)/__WORD_BIT;
- start = iterator(q, 0);
- }
-}
+// Added by Terris --begin--
+#ifndef STL_BVECTOR
#undef Allocator
#undef __WORD_BIT
+#endif
+
+// Added by Terris --end--
/*
@@ -434,5 +376,3 @@ void bit_vector::insert(iterator position, const_iterator first,
*/
#endif
-
-
diff --git a/STL/defalloc.h b/STL/defalloc.h
index 56c5e692e96..c0e2e04998d 100644
--- a/STL/defalloc.h
+++ b/STL/defalloc.h
@@ -39,8 +39,8 @@ inline T* allocate(ptrdiff_t size, T*) {
set_new_handler(0);
T* tmp = (T*)(::operator new((size_t)(size * sizeof(T))));
if (tmp == 0) {
- cerr << "out of memory" << endl;
- exit(1);
+ cerr << "out of memory" << endl;
+ exit(1);
}
return tmp;
}
@@ -54,26 +54,47 @@ namespace std {
* End change by Terris
*/
+/*
+* Added by Terris (#if out code)
+ */
+#if 0
+/*
+ * Added by Terris End
+ */
template <class T>
inline T* allocate(int size, T*) {
- set_new_handler(0);
- T* tmp = (T*)(::operator new((unsigned int)(size * sizeof(T))));
- if (tmp == 0) {
- cerr << "out of memory" << endl;
- exit(1);
+ set_new_handler(0);
+ T* tmp = (T*)(::operator new((unsigned int)(size * sizeof(T))));
+ if (tmp == 0) {
+ cerr << "out of memory" << endl;
+ exit(1);
}
return tmp;
}
+/*
+ * Added by Terris
+ */
+#endif
+/*
+ * Added by Terris End
+ */
template <class T>
-inline T* allocate(long size, T*) {
- set_new_handler(0);
- T* tmp = (T*)(::operator new((unsigned long)(size * sizeof(T))));
- if (tmp == 0) {
- cerr << "out of memory" << endl;
- exit(1);
- }
- return tmp;
+inline T* allocate(int size, T*) { // Changed by Terris -- was long.
+/*
+ * Begin Change by Terris
+ */
+// set_new_handler(0);
+// T* tmp = (T*)(::operator new((unsigned long)(size * sizeof(T))));
+// if (tmp == 0) {
+// cerr << "out of memory" << endl;
+// exit(1);
+// }
+// return tmp;
+/*
+ * End Change by Terris
+ */
+ return (T*)(::operator new((unsigned long)(size * sizeof(T))));
}
template <class T>
@@ -156,26 +177,18 @@ public:
typedef ptrdiff_t difference_type;
pointer allocate(size_type n) {
- return std::allocate((difference_type)n, (pointer)0);
+ return std::allocate((difference_type)n, (pointer)0);
}
void deallocate(pointer p) { std::deallocate(p); }
pointer address(reference x) { return (pointer)&x; }
const_pointer const_address(const_reference x) {
- return (const_pointer)&x;
- }
- /*
- size_type init_page_size() {
- return max(size_type(1), size_type(4096/sizeof(T)));
- }
- size_type max_size() const {
- return max(size_type(1), size_type(UINT_MAX/sizeof(T)));
+ return (const_pointer)&x;
}
- */
size_type init_page_size() {
- return size_type(4096/sizeof(T));
+ return max(size_type(1), size_type(4096/sizeof(T)));
}
size_type max_size() const {
- return size_type(UINT_MAX/sizeof(T));
+ return max(size_type(1), size_type(UINT_MAX/sizeof(T)));
}
};
diff --git a/STL/deque.h b/STL/deque.h
index 2f273e76c44..1eddbc7f7c8 100644
--- a/STL/deque.h
+++ b/STL/deque.h
@@ -33,11 +33,11 @@
/*
- *Added by d:\Terris\convert.pl --begin--
+ *Added by d:\\convert.pl --begin--
*/
namespace std {
/*
- *Added by d:\Terris\convert.pl --end--
+ *Added by d:\\convert.pl --end--
*/
template <class T>
@@ -576,11 +576,11 @@ void deque<T>::erase(iterator first, iterator last) {
/*
- *Added by d:\Terris\convert.pl --begin--
+ *Added by d:\\convert.pl --begin--
*/
}
/*
- *Added by d:\Terris\convert.pl --end--
+ *Added by d:\\convert.pl --end--
*/
#endif
diff --git a/STL/iterator.h b/STL/iterator.h
index bf29871192d..bf16eb0f40e 100644
--- a/STL/iterator.h
+++ b/STL/iterator.h
@@ -130,14 +130,14 @@ protected:
Container& container;
public:
back_insert_iterator(Container& x) : container(x) {}
- back_insert_iterator<Container>&
+ back_insert_iterator &
operator=(const Container::value_type& value) {
container.push_back(value);
return *this;
}
- back_insert_iterator<Container>& operator*() { return *this; }
- back_insert_iterator<Container>& operator++() { return *this; }
- back_insert_iterator<Container>& operator++(int) { return *this; }
+ back_insert_iterator & operator*() { return *this; }
+ back_insert_iterator & operator++() { return *this; }
+ back_insert_iterator & operator++(int) { return *this; }
};
template <class Container>
@@ -151,14 +151,14 @@ protected:
Container& container;
public:
front_insert_iterator(Container& x) : container(x) {}
- front_insert_iterator<Container>&
+ front_insert_iterator&
operator=(const Container::value_type& value) {
container.push_front(value);
return *this;
}
- front_insert_iterator<Container>& operator*() { return *this; }
- front_insert_iterator<Container>& operator++() { return *this; }
- front_insert_iterator<Container>& operator++(int) { return *this; }
+ front_insert_iterator& operator*() { return *this; }
+ front_insert_iterator& operator++() { return *this; }
+ front_insert_iterator& operator++(int) { return *this; }
};
template <class Container>
@@ -174,15 +174,15 @@ protected:
public:
insert_iterator(Container& x, Container::iterator i)
: container(x), iter(i) {}
- insert_iterator<Container>&
+ insert_iterator &
operator=(const Container::value_type& value) {
iter = container.insert(iter, value);
++iter;
return *this;
}
- insert_iterator<Container>& operator*() { return *this; }
- insert_iterator<Container>& operator++() { return *this; }
- insert_iterator<Container>& operator++(int) { return *this; }
+ insert_iterator& operator*() { return *this; }
+ insert_iterator& operator++() { return *this; }
+ insert_iterator& operator++(int) { return *this; }
};
template <class Container, class Iterator>
diff --git a/STL/list.h b/STL/list.h
index 095962f6c51..b86184a777f 100644
--- a/STL/list.h
+++ b/STL/list.h
@@ -33,11 +33,11 @@
/*
- *Added by d:\Terris\convert.pl --begin--
+ *Added by d:\\convert.pl --begin--
*/
namespace std {
/*
- *Added by d:\Terris\convert.pl --end--
+ *Added by d:\\convert.pl --end--
*/
template <class T>
@@ -47,9 +47,9 @@ protected:
struct list_node;
friend list_node;
struct list_node {
- void_pointer next;
- void_pointer prev;
- T data;
+ void_pointer next;
+ void_pointer prev;
+ T data;
};
static Allocator<list_node> list_node_allocator;
static Allocator<T> value_allocator;
@@ -65,13 +65,13 @@ public:
typedef Allocator<list_node>::difference_type difference_type;
protected:
size_type buffer_size() {
- return list_node_allocator.init_page_size();
+ return list_node_allocator.init_page_size();
}
struct list_node_buffer;
friend list_node_buffer;
struct list_node_buffer {
- void_pointer next_buffer;
- link_type buffer;
+ void_pointer next_buffer;
+ link_type buffer;
};
public:
typedef Allocator<list_node_buffer> buffer_allocator_type;
@@ -86,12 +86,12 @@ protected:
/*static*/ link_type next_avail;
/*static*/ link_type last;
void add_new_buffer() {
- buffer_pointer tmp = buffer_allocator.allocate((size_type)1);
- tmp->buffer = list_node_allocator.allocate(buffer_size());
- tmp->next_buffer = buffer_list;
- buffer_list = tmp;
- next_avail = buffer_list->buffer;
- last = next_avail + buffer_size();
+ buffer_pointer tmp = buffer_allocator.allocate((size_type)1);
+ tmp->buffer = list_node_allocator.allocate(buffer_size());
+ tmp->next_buffer = buffer_list;
+ buffer_list = tmp;
+ next_avail = buffer_list->buffer;
+ last = next_avail + buffer_size();
}
/*
* Changed by Terris
@@ -99,15 +99,15 @@ protected:
/*static*/ size_type number_of_lists;
void deallocate_buffers();
link_type get_node() {
- link_type tmp = free_list;
- return free_list ? (free_list = (link_type)(free_list->next), tmp)
- : (next_avail == last ? (add_new_buffer(), next_avail++)
- : next_avail++);
- // ugly code for inlining - avoids multiple returns
+ link_type tmp = free_list;
+ return free_list ? (free_list = (link_type)(free_list->next), tmp)
+ : (next_avail == last ? (add_new_buffer(), next_avail++)
+ : next_avail++);
+ // ugly code for inlining - avoids multiple returns
}
void put_node(link_type p) {
- p->next = free_list;
- free_list = p;
+ p->next = free_list;
+ free_list = p;
}
protected:
@@ -121,63 +121,63 @@ public:
friend class const_iterator;
// friend bool operator==(const iterator& x, const iterator& y);
protected:
- link_type node;
- iterator(link_type x) : node(x) {}
+ link_type node;
+ iterator(link_type x) : node(x) {}
public:
- iterator() {}
- bool operator==(const iterator& x) const { return node == x.node; }
- reference operator*() const { return (*node).data; }
- iterator& operator++() {
- node = (link_type)((*node).next);
- return *this;
- }
- iterator operator++(int) {
- iterator tmp = *this;
- ++*this;
- return tmp;
- }
- iterator& operator--() {
- node = (link_type)((*node).prev);
- return *this;
- }
- iterator operator--(int) {
- iterator tmp = *this;
- --*this;
- return tmp;
- }
+ iterator() {}
+ bool operator==(const iterator& x) const { return node == x.node; }
+ reference operator*() const { return (*node).data; }
+ iterator& operator++() {
+ node = (link_type)((*node).next);
+ return *this;
+ }
+ iterator operator++(int) {
+ iterator tmp = *this;
+ ++*this;
+ return tmp;
+ }
+ iterator& operator--() {
+ node = (link_type)((*node).prev);
+ return *this;
+ }
+ iterator operator--(int) {
+ iterator tmp = *this;
+ --*this;
+ return tmp;
+ }
};
class const_iterator : public bidirectional_iterator<T, difference_type> {
friend class list<T>;
protected:
- link_type node;
- const_iterator(link_type x) : node(x) {}
+ link_type node;
+ const_iterator(link_type x) : node(x) {}
public:
- const_iterator() {}
- const_iterator(const iterator& x) : node(x.node) {}
- bool operator==(const const_iterator& x) const { return node == x.node; }
- const_reference operator*() const { return (*node).data; }
- const_iterator& operator++() {
- node = (link_type)((*node).next);
- return *this;
- }
- const_iterator operator++(int) {
- const_iterator tmp = *this;
- ++*this;
- return tmp;
- }
- const_iterator& operator--() {
- node = (link_type)((*node).prev);
- return *this;
- }
- const_iterator operator--(int) {
- const_iterator tmp = *this;
- --*this;
- return tmp;
- }
+ const_iterator() {}
+ const_iterator(const iterator& x) : node(x.node) {}
+ bool operator==(const const_iterator& x) const { return node == x.node; }
+ const_reference operator*() const { return (*node).data; }
+ const_iterator& operator++() {
+ node = (link_type)((*node).next);
+ return *this;
+ }
+ const_iterator operator++(int) {
+ const_iterator tmp = *this;
+ ++*this;
+ return tmp;
+ }
+ const_iterator& operator--() {
+ node = (link_type)((*node).prev);
+ return *this;
+ }
+ const_iterator operator--(int) {
+ const_iterator tmp = *this;
+ --*this;
+ return tmp;
+ }
};
typedef reverse_bidirectional_iterator<const_iterator, value_type,
const_reference, difference_type>
- const_reverse_iterator;
+ const_reverse_iterator;
typedef reverse_bidirectional_iterator<iterator, value_type, reference,
difference_type>
reverse_iterator;
@@ -185,10 +185,10 @@ public:
* Changed by Terris
*/
list() : length(0), free_list(0), buffer_list(0), next_avail(0), last(0), number_of_lists(0) {
- ++number_of_lists;
- node = get_node();
- (*node).next = node;
- (*node).prev = node;
+ ++number_of_lists;
+ node = get_node();
+ (*node).next = node;
+ (*node).prev = node;
}
iterator begin() { return (link_type)((*node).next); }
const_iterator begin() const { return (link_type)((*node).next); }
@@ -210,109 +210,119 @@ public:
reference back() { return *(--end()); }
const_reference back() const { return *(--end()); }
void swap(list<T>& x) {
- std::swap(node, x.node);
- std::swap(length, x.length);
- }
+ std::swap(node, x.node);
+ std::swap(length, x.length);
+ /*
+ * Added By Terris
+ */
+ std::swap(buffer_list, x.buffer_list);
+ std::swap(free_list, x.free_list);
+ std::swap(next_avail, x.next_avail);
+ std::swap(last, x.last);
+ /*
+ * Added By Terris
+ */
+ }
iterator insert(iterator position, const T& x) {
- link_type tmp = get_node();
- construct(value_allocator.address((*tmp).data), x);
- (*tmp).next = position.node;
- (*tmp).prev = (*position.node).prev;
- (*(link_type((*position.node).prev))).next = tmp;
- (*position.node).prev = tmp;
- ++length;
- return tmp;
+ link_type tmp = get_node();
+ construct(value_allocator.address((*tmp).data), x);
+ (*tmp).next = position.node;
+ (*tmp).prev = (*position.node).prev;
+ (*(link_type((*position.node).prev))).next = tmp;
+ (*position.node).prev = tmp;
+ ++length;
+ return tmp;
}
void insert(iterator position, const T* first, const T* last);
void insert(iterator position, const_iterator first,
- const_iterator last);
+ const_iterator last);
void insert(iterator position, size_type n, const T& x);
void push_front(const T& x) { insert(begin(), x); }
void push_back(const T& x) { insert(end(), x); }
void erase(iterator position) {
- (*(link_type((*position.node).prev))).next = (*position.node).next;
- (*(link_type((*position.node).next))).prev = (*position.node).prev;
- destroy(value_allocator.address((*position.node).data));
- put_node(position.node);
- --length;
+ (*(link_type((*position.node).prev))).next = (*position.node).next;
+ (*(link_type((*position.node).next))).prev = (*position.node).prev;
+ destroy(value_allocator.address((*position.node).data));
+ put_node(position.node);
+ --length;
}
void erase(iterator first, iterator last);
void pop_front() { erase(begin()); }
void pop_back() {
- iterator tmp = end();
- erase(--tmp);
+ iterator tmp = end();
+ erase(--tmp);
}
/*
* Changed by Terris
*/
list(size_type n, const T& value = T()) : length(0), free_list(0), buffer_list(0), next_avail(0), last(0), number_of_lists(0) {
- ++number_of_lists;
- node = get_node();
- (*node).next = node;
- (*node).prev = node;
- insert(begin(), n, value);
+ ++number_of_lists;
+ node = get_node();
+ (*node).next = node;
+ (*node).prev = node;
+ insert(begin(), n, value);
}
/*
* Changed by Terris
*/
list(const T* first, const T* last) : length(0), free_list(0), buffer_list(0), next_avail(0), last(0), number_of_lists(0) {
- ++number_of_lists;
- node = get_node();
- (*node).next = node;
- (*node).prev = node;
- insert(begin(), first, last);
+ ++number_of_lists;
+ node = get_node();
+ (*node).next = node;
+ (*node).prev = node;
+ insert(begin(), first, last);
}
/*
* Changed by Terris
*/
list(const list<T>& x) : length(0), free_list(0), buffer_list(0), next_avail(0), last(0), number_of_lists(0) {
- ++number_of_lists;
- node = get_node();
- (*node).next = node;
- (*node).prev = node;
- insert(begin(), x.begin(), x.end());
+ ++number_of_lists;
+ node = get_node();
+ (*node).next = node;
+ (*node).prev = node;
+ insert(begin(), x.begin(), x.end());
}
~list() {
- erase(begin(), end());
- put_node(node);
- if (--number_of_lists == 0) deallocate_buffers();
+ erase(begin(), end());
+ put_node(node);
+ if (--number_of_lists == 0) deallocate_buffers();
}
list<T>& operator=(const list<T>& x);
protected:
void transfer(iterator position, iterator first, iterator last) {
- (*(link_type((*last.node).prev))).next = position.node;
- (*(link_type((*first.node).prev))).next = last.node;
- (*(link_type((*position.node).prev))).next = first.node;
- link_type tmp = link_type((*position.node).prev);
- (*position.node).prev = (*last.node).prev;
- (*last.node).prev = (*first.node).prev;
- (*first.node).prev = tmp;
+ (*(link_type((*last.node).prev))).next = position.node;
+ (*(link_type((*first.node).prev))).next = last.node;
+ (*(link_type((*position.node).prev))).next = first.node;
+ link_type tmp = link_type((*position.node).prev);
+ (*position.node).prev = (*last.node).prev;
+ (*last.node).prev = (*first.node).prev;
+ (*first.node).prev = tmp;
}
public:
void splice(iterator position, list<T>& x) {
- if (!x.empty()) {
- transfer(position, x.begin(), x.end());
- length += x.length;
- x.length = 0;
- }
+ if (!x.empty()) {
+ transfer(position, x.begin(), x.end());
+ length += x.length;
+ x.length = 0;
+ }
}
void splice(iterator position, list<T>& x, iterator i) {
- iterator j = i;
- if (position == i || position == ++j) return;
- transfer(position, i, j);
- ++length;
- --x.length;
+ iterator j = i;
+ if (position == i || position == ++j) return;
+ transfer(position, i, j);
+ ++length;
+ --x.length;
}
void splice(iterator position, list<T>& x, iterator first, iterator last) {
- if (first != last) {
- if (&x != this) {
- difference_type n = 0;
- distance(first, last, n);
- x.length -= n;
- length += n;
- }
- transfer(position, first, last);
- }
+ if (first != last) {
+ if (&x != this) {
+ difference_type n = 0;
+ distance(first, last, n);
+ x.length -= n;
+ length += n;
+ }
+ transfer(position, first, last);
+ }
}
void remove(const T& value);
void unique();
@@ -375,10 +385,10 @@ inline bool operator<(const list<T>& x, const list<T>& y) {
template <class T>
void list<T>::deallocate_buffers() {
while (buffer_list) {
- buffer_pointer tmp = buffer_list;
- buffer_list = (buffer_pointer)(buffer_list->next_buffer);
- list_node_allocator.deallocate(tmp->buffer);
- buffer_allocator.deallocate(tmp);
+ buffer_pointer tmp = buffer_list;
+ buffer_list = (buffer_pointer)(buffer_list->next_buffer);
+ list_node_allocator.deallocate(tmp->buffer);
+ buffer_allocator.deallocate(tmp);
}
free_list = 0;
next_avail = 0;
@@ -389,10 +399,10 @@ template <class T>
void list<T>::insert(iterator position, const T* first, const T* last) {
while (first != last) insert(position, *first++);
}
-
+
template <class T>
void list<T>::insert(iterator position, const_iterator first,
- const_iterator last) {
+ const_iterator last) {
while (first != last) insert(position, *first++);
}
@@ -409,15 +419,15 @@ void list<T>::erase(iterator first, iterator last) {
template <class T>
list<T>& list<T>::operator=(const list<T>& x) {
if (this != &x) {
- iterator first1 = begin();
- iterator last1 = end();
- const_iterator first2 = x.begin();
- const_iterator last2 = x.end();
- while (first1 != last1 && first2 != last2) *first1++ = *first2++;
- if (first2 == last2)
- erase(first1, last1);
- else
- insert(last1, first2, last2);
+ iterator first1 = begin();
+ iterator last1 = end();
+ const_iterator first2 = x.begin();
+ const_iterator last2 = x.end();
+ while (first1 != last1 && first2 != last2) *first1++ = *first2++;
+ if (first2 == last2)
+ erase(first1, last1);
+ else
+ insert(last1, first2, last2);
}
return *this;
}
@@ -427,10 +437,10 @@ void list<T>::remove(const T& value) {
iterator first = begin();
iterator last = end();
while (first != last) {
- iterator next = first;
- ++next;
- if (*first == value) erase(first);
- first = next;
+ iterator next = first;
+ ++next;
+ if (*first == value) erase(first);
+ first = next;
}
}
@@ -441,11 +451,11 @@ void list<T>::unique() {
if (first == last) return;
iterator next = first;
while (++next != last) {
- if (*first == *next)
- erase(next);
- else
- first = next;
- next = first;
+ if (*first == *next)
+ erase(next);
+ else
+ first = next;
+ next = first;
}
}
@@ -456,12 +466,12 @@ void list<T>::merge(list<T>& x) {
iterator first2 = x.begin();
iterator last2 = x.end();
while (first1 != last1 && first2 != last2)
- if (*first2 < *first1) {
- iterator next = first2;
- transfer(first1, first2, ++next);
- first2 = next;
- } else
- ++first1;
+ if (*first2 < *first1) {
+ iterator next = first2;
+ transfer(first1, first2, ++next);
+ first2 = next;
+ } else
+ ++first1;
if (first2 != last2) transfer(last1, first2, last2);
length += x.length;
x.length= 0;
@@ -471,8 +481,8 @@ template <class T>
void list<T>::reverse() {
if (size() < 2) return;
for (iterator first = ++begin(); first != end();) {
- iterator old = first++;
- transfer(begin(), old, first);
+ iterator old = first++;
+ transfer(begin(), old, first);
}
}
@@ -483,14 +493,14 @@ void list<T>::sort() {
list<T> counter[64];
int fill = 0;
while (!empty()) {
- carry.splice(carry.begin(), *this, begin());
- int i = 0;
- while(i < fill && !counter[i].empty()) {
- counter[i].merge(carry);
- carry.swap(counter[i++]);
- }
- carry.swap(counter[i]);
- if (i == fill) ++fill;
+ carry.splice(carry.begin(), *this, begin());
+ int i = 0;
+ while(i < fill && !counter[i].empty()) {
+ counter[i].merge(carry);
+ carry.swap(counter[i++]);
+ }
+ carry.swap(counter[i]);
+ if (i == fill) ++fill;
}
while(fill--) merge(counter[fill]);
}
@@ -500,11 +510,11 @@ void list<T>::sort() {
/*
- *Added by d:\Terris\convert.pl --begin--
+ *Added by d:\\convert.pl --begin--
*/
}
/*
- *Added by d:\Terris\convert.pl --end--
+ *Added by d:\\convert.pl --end--
*/
#endif
diff --git a/STL/queue.h b/STL/queue.h
new file mode 100644
index 00000000000..2c539450a61
--- /dev/null
+++ b/STL/queue.h
@@ -0,0 +1 @@
+#include <stack.h>
diff --git a/STL/readme2.stl b/STL/readme2.stl
new file mode 100644
index 00000000000..5132bc1189b
--- /dev/null
+++ b/STL/readme2.stl
@@ -0,0 +1,272 @@
+STL2.ZIP
+
+Standard Template Library for Visual C++ 4.0
+and Related Classes
+
+Revised 10/15/96 - Bug fixes and change to bit_vector.
+
+This version supports DLLs and threading. You must use critical
+sections around code that uses the same container in different
+threads. These features come at a price -- since memory
+usage is not optimal, this code may use more memory and
+may be slower.
+
++ General strategy: Remove all statics except the
+ static allocator objects.
++ Vectors were not affected.
++ Major changes made to tree.h
++ Stability: Very stable.
+
+This code should be considered for experimental use only. There
+are still statics lurking in some functions; these functions
+are not thread-safe.
+
+-------------------------
+Fix for bit_vector
+-------------------------
+This version also has a fix for bit_vector, which doesn't really
+work with VC++ 4.x. Please include bvector.cpp in your
+project if you use bit_vector. This fixes the linker errors
+that occur if you use bector.h in multiple .cpp files.
+
+-------------------------
+Disclaimer
+-------------------------
+Code is provided without warranty, liability, or technical support.
+
+STL.H and PTR.H are freely distributable and can be
+modified in any way.
+
+--------------------------------
+STRING.H does not compile.
+--------------------------------
+
+"D. Pirzadeh" <ddp@crl.com> Explains how to fix:
+
+First, I got compile errors in "bstring.h"
+and changed it as follows to correct:
+ line 1104 "::reserve" -> "std::reserve"
+ line 1110 "::default_size" -> "std::default_size"
+
+Also, I got an INTERNAL COMPILER ERROR with Visual C++ v4.0 when I did the fol-
+lowing:
+ class xyz : public std::string { }
+
+I fixed it with:
+ typedef std::string XyzString;
+ class xyz : public XyzString { }
+
+--------------------------------
+Changes made to STL distribution
+--------------------------------
+
+These files were modified from the STL distribution shipped with
+Microsoft Visual C++ 4.0. The files here are a complete,
+working version of the STL. These files have been tested with
+MFC applications.
+
+Changes were made to practically all header files. Look for
+comments like:
+
+*Added by...
+*Changed by...
+
+------------------
+Usage Instructions
+------------------
+
+Set the preprocessor variable NOMINMAX.
+
+As Microsoft recommends, the STL is compiled in the std namespace.
+
+When including these files, do **not** do this:
+
+ namespace std
+ {
+ #include <vector.h>
+ }
+
+Instead, do this:
+
+ #include <vector.h>
+
+Recommended usage:
+
+ First, include:
+
+ #include <afxwin.h>
+ #include <afxext.h>
+ #include <afxtempl.h>
+
+ Then include the STL header files.
+
+-------------------
+Support for CString
+-------------------
+The stl.h file contains code written by me. The file contains
+operators that will allow you to use CString objects with STL
+containers and functions.
+
+!!!! CString will not work with STL unless you include <stl.h> !!!!
+
+-------------------------------------------
+Helper functions for pointers-in-containers
+-------------------------------------------
+There is a file called stl.h which contains two functions:
+ SequenceDelete
+ MapDelete
+These functions send "delete" to all of the objects in a container.
+
+If you don't like this approach, you can use a supplied "pointer
+wrapper" class.
+
+There is a file called ptr.h which contains a class called Ptr
+that can be used exactly like a pointer. The object has a pointer
+inside it that points to an object of any class. When a Ptr object
+is deleted, "delete" is sent to its underlying pointer. Ptr can be
+used with any STL container, as it has a copy constructor and
+assignment operator, which transfers "ownership" of the pointer from
+the source object to the destination object. Ptr is from the book
+Design Patterns by Gamma et al -- see the Proxy pattern.
+
+The Ptr class makes memory leaks impossible, because it deletes
+objects automatically when the container is deleted, or when
+functions like "delete" are used.
+
+Example:
+
+ This is a vector of CStrings:
+
+ std::vector< Ptr<CString> > StringVector;
+
+ StringVector.push_back( Ptr( new CString( "hello" ) ) );
+ StringVector.push_back( Ptr( new CString( "This is another string" ) ) );
+
+------------------------
+Common Problems with STL
+------------------------
+
+1) Compiler error: != is ambiguous
+
+ Solution: put the following line at the beginning of the method
+ that caused the error:
+
+ using namespace std;
+
+2) When using maps, the debugger crashes.
+
+ This is because symbols for maps (actually, for the "pair")
+ get truncated to 255 characters. Solution: Turn off the
+ variables window in the debugger. Don't try to look at
+ a symbol that has been truncated. This is not an STL-specific
+ bug -- It's a bug in the debugger.
+
+3) All sorts of compile errors in STL header files
+
+ Make sure the preprocessor variable NOMINMAX is defined
+
+
+4) Compiler errors about "operator < is not available", etc.
+ The class involved has global comparison operators.
+
+ Solution:
+ Write "routers" in the std namespace to the global namespace.
+ Example (see also stl.h - this is how CString is able
+ to work with STL):
+
+ namespace std
+ {
+ BOOL operator < ( const MyClass & rLhs,
+ const AnotherClass & rRhs )
+ {
+ return ::operator < ( rLhs, rRhs );
+ }
+ }
+
+ See also 5.
+
+5) When you use find() or another algorithm, the compiler
+ complains that it cannot find the == or < operators.
+
+If your code compiles without any error messages, then disregard
+this section. However, if you get errors like "cannot convert
+first argument from const class X" then read on.
+
+I am assuming that your code is calling an STL algorithm like
+std::sort() or std::find(). If you're not, I can't help
+you.
+
+There is apparently a bug in the Microsoft compiler regarding
+namespaces. Namespaces cannot locate global
+functions that reside in the global namespace. For example,
+the binary == operator.
+
+Maybe this is a bug, maybe it isn't. This is not clear
+to me. However, I do know what works and have tried many other
+approaches that do not work. If you have a better solution I
+would appreciate it if you could let me know about it.
+
+So, if you declare your own class and want to use algorithms
+like find() on an STL container, you have two choices:
+
+(1) Declare == as a member function.
+(2) Declare global operators == and !=.
+
+(1) simply works. There will come a time, however, when (1)
+won't satisfy your needs. If A == B, then B == A. You can't
+do this using member functions if A and B are from different
+classes.
+
+If you choose (2), you must add the != operator to the std
+namespace. There are two ways to do this. First, you can do
+this:
+ namespace std
+ {
+ inline operator != ( const MyClass &rLhs, const MyClass &rRhs )
+ {
+ return ::operator != ( rLhs, rRhs );
+ }
+ }
+This "routes" != from the std namespace to the global namespace.
+
+Note that ( lhs != rhs ) can be derived from the == operator
+as !( lhs == rhs ). There is a macro in STL.H,
+STL_DECLARE_GLOBAL_NE, that does this derivation.
+This derivation will not work when for whatever reason, !(lhs == rhs)
+is not the same as ( lhs != rhs ).
+
+The following example shows what you have to do for find(). Other
+algorithms require you to declare <, <=, and >= too. See the
+macros STL_DECLARE_GLOBAL_GE, STL_DECLARE_GLOBAL_LT, and
+STL_GLOBAL_LE. These macros derive new comparison operators
+from "operator <( const T&, const T& )".
+
+class MyClass
+{
+ public:
+
+ int units;
+ CString description;
+};
+
+// We want to be able to test two MyClass objects against each other
+// in STL. Need to create a global operator for this purpose.
+// Since we use find(), we need to declare not-equal too.
+bool operator == ( const MyClass &, const MyClass & );
+STL_DECLARE_GLOBAL_NE( MyClass, MyClass )
+
+// These operators test for a matching description.
+// We do A == B and B == A to be consistent.
+bool operator == ( const MyClass&, const CString & );
+bool operator == ( const CString&, const MyClass & );
+STL_DECLARE_GLOBAL_NE( MyClass, CString )
+STL_DECLARE_GLOBAL_NE( CString, MyClass )
+
+6. Errors when creating vectors that have vectors and deques
+ that have deques.
+
+ Solution: Provide atruments to the constructor.
+
+ std::vector< std::vector<int> >
+ TwoDimensional( 0, std::vector<int>() );
+
diff --git a/STL/tree.h b/STL/tree.h
index 71568ec7807..dc91484b535 100644
--- a/STL/tree.h
+++ b/STL/tree.h
@@ -48,11 +48,11 @@ iterators invalidated are those referring to the deleted node.
#endif
/*
- *Added by d:\Terris\convert.pl --begin--
+ *Added by d:\\convert.pl --begin--
*/
namespace std {
/*
- *Added by d:\Terris\convert.pl --end--
+ *Added by d:\\convert.pl --end--
*/
template <class Key, class Value, class KeyOfValue, class Compare>
@@ -204,7 +204,10 @@ public:
link_type node;
iterator(link_type x, link_type NIL) : node(x), NIL(NIL) {}
public:
- iterator() {}
+/*
+ * Changed by Terris
+ */
+ iterator() { NIL = NULL; }
bool operator==(const iterator& y) const { return node == y.node; }
reference operator*() const { return value(node); }
iterator& operator++() {
@@ -275,8 +278,14 @@ public:
link_type node;
const_iterator(link_type x, link_type NIL) : node(x), NIL(NIL) {}
public:
- const_iterator() {}
- const_iterator(const iterator& x) : node(x.node) {}
+/*
+ * Changed by Terris
+ */
+ const_iterator() { NIL = NULL; }
+/*
+ * Changed by Terris
+ */
+ const_iterator(const iterator& x) : node(x.node), NIL(x.NIL) {}
bool operator==(const const_iterator& y) const {
return node == y.node;
}
@@ -338,7 +347,7 @@ public:
reverse_iterator;
typedef reverse_bidirectional_iterator<const_iterator, value_type,
const_reference, difference_type>
- const_reverse_iterator;
+ const_reverse_iterator;
private:
iterator __insert(link_type x, link_type y, const value_type& v);
/*
@@ -410,7 +419,7 @@ public:
leftmost() = header;
rightmost() = header;
} else {
- leftmost() = minimum(root());
+ leftmost() = minimum(root());
rightmost() = maximum(root());
}
}
@@ -466,6 +475,17 @@ public:
std::swap(node_count, t.node_count);
std::swap(insert_always, t.insert_always);
std::swap(key_compare, t.key_compare);
+ /*
+ * Added By Terris
+ */
+ std::swap(NIL, t.NIL);
+ std::swap(buffer_list, t.buffer_list);
+ std::swap(free_list, t.free_list);
+ std::swap(next_avail, t.next_avail);
+ std::swap(last, t.last);
+ /*
+ * Added By Terris
+ */
}
// insert/erase
@@ -584,7 +604,7 @@ operator=(const rb_tree<Key, Value, KeyOfValue, Compare>& x) {
leftmost() = header;
rightmost() = header;
} else {
- leftmost() = minimum(root());
+ leftmost() = minimum(root());
rightmost() = maximum(root());
}
node_count = x.node_count;
@@ -1058,11 +1078,11 @@ rb_tree<Key, Value, KeyOfValue, Compare>::rotate_right(link_type x) {
/*
- *Added by d:\Terris\convert.pl --begin--
+ *Added by d:\\convert.pl --begin--
*/
}
/*
- *Added by d:\Terris\convert.pl --end--
+ *Added by d:\\convert.pl --end--
*/
#endif
diff --git a/STL/vector.h b/STL/vector.h
index c1da703e508..66973a70333 100644
--- a/STL/vector.h
+++ b/STL/vector.h
@@ -82,14 +82,19 @@ public:
reference operator[](size_type n) { return *(begin() + n); }
const_reference operator[](size_type n) const { return *(begin() + n); }
vector() : start(0), finish(0), end_of_storage(0) {}
- /*
- vector(size_type n, const T& value = T()) {
+ /*
+ * This is cause the VC++ compiler sucks
+ * and does not recognize nested classes properly
+ *
+ */
+#if !defined (VC_PLUS_PLUS_NESTED_CLASS_PROBLEM)
+ vector(size_type n, const T& value = T()) {
start = static_allocator.allocate(n);
uninitialized_fill_n(start, n, value);
finish = start + n;
end_of_storage = finish;
}
- */
+#endif /* VC_PLUS_PLUS_NESTED_CLASS_PROBLEM */
vector(const vector<T>& x) {
start = static_allocator.allocate(x.end() - x.begin());
finish = uninitialized_copy(x.begin(), x.end(), start);