This is a header file ~~~~~~~~~~~~~~~~~
#ifndef __vector_h # define __vector_h # Pragma Option Push -b -A8 -PC -VX- -VE - -A- -W-INL-W-AUS -W-SIG / / - * - C - * - / *** *********************************************************** ********************** * * Vector - Declarations for the standard library vector class * **************** *********************************************************** ********* * * Copyright (c) 1994 * Hewlett-Packard Company * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, * provided that the above copyright notice appear in all copies and * that both that copyright notice and this permission notice appear * in supporting documentation. Hewlett-Packard Company makes no * representations about the suitability of this software for any * purpose. It is provided " AS IS
WITHOUT Express or Implied Warranty. * * *********************************************************** ******************************** * * Copyright (C) 1994-1999 Rogue Wave Software, Inc. All Rights Reserved. * * This computer software is owned by Rogue Wave Software, Inc. and is * protected by US copyright laws and other laws and by international * treaties. This computer software is furnished by Rogue Wave Software, * Inc. pursuant to a written license agreement and may be used, copied, * transmitted, and stored only in accordance with the terms of such * license and with the inclusion of the above copyright notice. This * computer software or any other copies thereof may not be provided or * otherwise made available to any other person. * * US Government Restricted Rights. This computer software is provided * with Restricted Rights. Use, duplication, or disclosure by the * Government is subject to restrictions as set forth in subparagraph (c) * (1) (ii) of the rights in Technical Data and C omputer Software clause * at DFARS 252.227-7013 or subparagraphs (c) (1) and (2) of the * Commercial Computer Software? Restricted Rights at 48 CFR 52.227-19, * as applicable. Manufacturer is Rogue Wave Software, Inc., 5500 * flatiron Parkway, Boulder, Colorado 80301 USA. * ************************************************* ********************************************** / # ifndef __STD_Vector __ # define __std_vector__
#include
#include
#ifndef Vector # define Vector Vector # Endif
#ifndef _RWSTD_NO_NAMESPACENAMESPACE STD {#ENDIF
//// Note That _RWSTD_COMPLEX_DEFAULT (X) // WILL Expand to: '= x', or nothing, // depending on your compiler's capabilities and / or // flag settings (see stdcomp.h) .// Template
Public: // // Types. // Typedef T value_type; typef allocator allocator_type;
#ifndef _RWSTD_NO_COMPLICATED_TYPEDEF typedef _TYPENAME _RWSTD_ALLOC_SIZE_TYPE size_type; typedef _TYPENAME _RWSTD_ALLOC_DIFF_TYPE difference_type; typedef _TYPENAME __value_alloc_type :: pointer iterator; typedef _TYPENAME __value_alloc_type :: const_pointer const_iterator; typedef _TYPENAME __value_alloc_type :: reference reference; typedef _TYPENAME __value_alloc_type :: const_reference const_reference; typedef _TYPENAME __value_alloc_type :: pointer pointer; typedef _TYPENAME __value_alloc_type :: const_pointer const_pointer; #else typedef size_t size_type; typedef ptrdiff_t difference_type; typedef T * iterator; typedef const T * const_iterator; typedef T & reference; typedef const T & const_reference; typedef T * pointer; typedef const T * const_pointer; #endif // _ rwstd_no_complicated_typedef
#ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC typedef _RW_STD :: reverse_iterator
Size_type __buffer_size; itrator __start; itrator __finish; __rwstd :: __ rw_basis
void __insert_aux (iterator position, const T & x); void __insert_aux (iterator position, size_type n, const T & x); # ifndef _RWSTD_NO_MEMBER_TEMPLATES template
Void __destroy (iterator start, iterator finish {while (start! = finish) __value_alloc_type (__ end_of_storage) .destroy (Start );}
// // Allocate buffers and fill with n values // void __initn (size_type n, const T & value) {__init (); __start = __value_alloc_type (__ end_of_storage) .allocate (n, 0); # ifndef _RWSTD_NO_EXCEPTIONS try {uninitialized_fill_n (__ start , n, value);} catch (...) {__value_alloc_type (__ end_of_storage) .deallocate (__ start, n); throw;} #else uninitialized_fill_n (__ start, n, value); # endif // _RWSTD_NO_EXCEPTIONS __finish = __start n ; __end_of_storage = __finish;} void __init () {__buffer_size = max ((size_type) 1, __ RWSTD :: __ rw_allocation_size ((value_type *) 0, (size_type) 0, (size_type) 0));} public: // // Construct / COPY / DESTROY / / / _EXPLICIT VECTOR (const allocator& alloc _rwstd_default_arg (allocator ())): __start (0), __finish (0), __end_of_storage (0, alloc) {__init ();}
#ifdef _RWSTD_NO_DEFAULT_TEMPLATE_ARGS Vector: __start (0), __finish (0), __end_of_storage (0, allocator ()) {;
Vector (size_type n, const t & value): __start (0), __finish (0), __end_of_storage (0, allocator ()) {__initn (n, value);} #ENDIF
_EXPLICIT VECTOR (size_type n): __start (0), __Finish (0), __end_of_storage (0, allocator ()) {t value = t (); __initn (n, value);}
#ifndef _RWSTD_NO_MEMBER_TEMPLATES
template
vector (const_iterator first, const_iterator last, const Allocator & alloc _RWSTD_DEFAULT_ARG (Allocator ())): __start (0), __finish (0), __end_of_storage (0, alloc) {size_type n; __init (); __initialize (n, size_type (0 )); distance (first, last, n); __start = __value_alloc_type (__ end_of_storage) .allocate (n, 0); # ifndef _RWSTD_NO_EXCEPTIONS try {__finish = uninitialized_copy (first, last, __start);} catch (...) { __value_alloc_type (__ end_of_storage) .deallocate (__ start, n); throw;} #else __finish = uninitialized_copy (first, last, __start); # endif // _RWSTD_NO_EXCEPTIONS __end_of_storage = __finish;} #ifdef _RWSTD_NO_DEFAULT_TEMPLATE_ARGS vector (const_iterator first, const_iterator last): __start (0), __Finish (0), __end_of_storage (0, allocator ()) {size_type n; __init (); __initialize (n, size_type (0)); Distance (first, last, n); __start = __Value_alloc_type (__ end_of_s torage) .allocate (n, 0); # ifndef _RWSTD_NO_EXCEPTIONS try {__finish = uninitialized_copy (first, last, __start);} catch (...) {__value_alloc_type (__ end_of_storage) .deallocate (__ start, n); throw;} # else __finish = uninitialized_copy (first, last, __start); # endif // _RWSTD_NO_EXCEPTIONS __end_of_storage = __finish;} #endif // _RWSTD_NO_DEFAULT_TEMPLATE_ARGS # endif // _RWSTD_NO_MEMBER_TEMPLATES
Vector (Const Vector
Vector
#ifndef _RWSTD_NO_MEMBER_TEMPLATES template
Allocator_type get_allocator () const {return (allocator_type) __ end_of_storage;}
// // ipurin () {return __start;} const_iterator begin () const {return __start;} iterator end () {return__finish;} const_iterator end () const {return__finish;}
reverse_iterator rbegin () {reverse_iterator tmp (end ()); return tmp;} const_reverse_iterator rbegin () const {const_reverse_iterator tmp (end ()); return tmp;} reverse_iterator rend () {reverse_iterator tmp (begin ()); return tmp ;} const_reverse_iterator rend () const {const_reverse_iterator tmp (begin ()); return tmp;} // // Capacity // size_type size () const {return size_type (end () - begin ());.} size_type max_size ( Const {RETURN __VALUE_ALLOC_TYPE (__ End_Of_Storage) .max_size ();} void resize; void resize (size_type new_size, t value);
size_type capacity () const {return size_type (__ end_of_storage.data () - begin ());} bool empty () const {return begin () == end ();} void reserve (size_type n) {_RWSTD_THROW (n> max_size (), length_error, __rwstd :: eXcept_msg_string (__ rwstd :: __ rwse_invalidsizeparam, "Vector :: RESERVE (SIZE_T)", N, Max_Size ()). msgstr ());
if (capacity ()
} Const_reference operator [] (size_type n) const {#ifdef _RWSTD_BOUNDS_CHECKING _RWSTD_THROW (n> = size (), out_of_range, __RWSTD :: except_msg_string (__ RWSTD :: rwse_OutOfRange, "vector :: operator [] (size_t) const", n, . size ()) msgstr ()); # endif return * (begin () n);} reference at (size_type n) {_RWSTD_THROW (n> = size (), out_of_range, __RWSTD :: except_msg_string (__ RWSTD :: rwse_OutOfRange "Vector :: at (size_t)", n, size ()); msgstr ()); return * (begin () n);} const_reference at (size_type n) const {_rwstd_throw (n> = size () , out_of_range, __rwstd :: eXcept_msg_string (__ rwstd :: rwse_outofrange, "vector :: at (size_t) const", n, size ()). msgstr ()); returnity * (begin () n);} Reference Front ) {RETURN * begin ();} const_reference front () const {return * begin ();} refrence back () { RETURN * (end () - 1);} const_reference back () const {return * (end () - 1);} ///Modifiers. // void push_back (const t & x) {ix (__finish! = __END_OF_Storage .data ()) {__value_alloc_type (__ end_of_storage) .construct (__ finish, x); __finish ;} else __insert_aux (end (), x);} void pop_back () {--__ finish; __value_alloc_type (__ end_of_storage) .destroy (__ finish) }
// // Itert x at position. // iposition, const t & x) {size_type n = position - begin (); if (__finish! = __END_OF_STORAGE.DATA () && position == end ()) { __value_alloc_type (__ end_of_storage) .construct (__ finish, x); __finish ;} else __insert_aux (position, x); return begin () n;} #ifndef _RWSTD_NO_MEMBER_TEMPLATES template
Iterator erase {if (position 1! = end ()) COPY (Position 1, end (), position; --__ finish; __value_alloc_type (__ end_storage) .destroy (__ finish); return position;} itemator ERASE (Iterator First, Iterator Last) {Iterator I = Copy (Last, End (), First); Iterator TMP = __finish; __finish = __finish - (Last - First); __DESTROY (I, TMP); Return First;}
void swap (vector
#ifndef _RWSTD_STRICT_ANSI // Non-standard function for setting buffer allocation size size_type allocation_size () {return __buffer_size;} size_type allocation_size (size_type new_size) {size_type tmp = __buffer_size; __buffer_size = max ((size_type) 1, new_size); return tmp; } #ENDIF / / _RWSTD_STRICT_ANSI};
Template
Template
#if! defined (_RWSTD_NO_NAMESPACE) ||! defined (_RWSTD_NO_PART_SPEC_OVERLOAD) template
Template Template Template #include #ifndef _RWSTD_NO_NAMESPACENAMESPACE STD {#ENDIF #ENDIF / / (_RWSTD_NO_TEMPLATE_REPOSTORY) && Defined (__borlandc__) //// if Bool Is a Builtin Type, We provide a vector #ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC Template #ELSE // Use a macro to mutate allocator into allocator _RWSTD_TEMPLATE _RWSTDEXPORT Vector #ENDIF / / _RWSTD_NO_CLASS_PARTIAL_SPEC public: // // types // typedef Allocator allocator_type; typedef bool value_type; private:! #if defined (_RWSTD_ALLOCATOR) && defined (_HPACC _) # ifdef _RWSTD_NO_CLASS_PARTIAL_SPEC typedef _TYPENAME allocator_type :: template rebind public: #ifdef _RWSTD_NO_EMBEDDED_TYPEDEF typedef allocator protected: #ifdef _RWSTD_NO_CLASS_PARTIAL_SPEC typedef __value_alloc_type :: pointer pointer; typedef __value_alloc_type :: const_pointer const_pointer; #else typedef _TYPENAME __value_alloc_type :: pointer pointer; typedef _TYPENAME __value_alloc_type :: const_pointer const_pointer; #endif PUBLIC: ///////. ' // // bit reference // class reference {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 ) {} 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) {RETURN * this = BOOL (x);} #ifndef _rwstd_strict_ansi bool operator == (Const Reference & X ) const {return bool (* this) == BOOL (X);} Bool Operator <(const reference & x) const {#if! defined (_msc_ver) || defined (__ borlandc__) Return Bool (* this) void flip () {* p ^ = mask;}}; typedef bool const_reference; // // Definition of our iterator // class iterator:. public _RW_STD :: iterator Unsigned int * p; unsigned int offset Void __bump_up () {if (Offset == _RWSTD_WORD_BIT - 1) {OFFSET = 0; P;}} void __bump_down ()} void __bump_down () {= _rwstd_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); {__Bump_UP (); return * this;} {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 / _rwstd_word_bit; n = n% _RWSTD_WORD_bit; if (n <0) {offset = n _rwstd_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 t MP = * this; return tmp - = i;} Difference_Type Operator- (item x) const {return _RWSTD_WORD_BIT * (P - XP) Offset - x.offset;} Reference Operator [] (Difference_Type i) {Return * (* THIS I);} Bool Operator == (Const Iterator & X) Const {Return P == XP && Offset == x.offset;} BOOL Operator <(const itrator & x) const {return P x) const {return! (* this == x);} Bool Operator> (const itrator & x) const {return x <* this;} Bool Operator> = (const itrator & x) const {return! (* this Unsigned int * p; unsigned int offset; void __bump_up () {if (Offset == _RWSTD_WORD_BIT - 1) {OFFSET = 0; P;}} void __bump_down ()} void __bump_down ()}} VOID __BUMP_DOWN ()} VOID __Bump_Down ()} = _RWSTD_WORD_BIT - 1; --P;}} Public: const_iterator (): p (0), offset (0) {} const_iterator (unsigned int * x, unsigned int y): p (x), offset (y) {} #if! defined (_msc_ver) || defined (__BORLANDC __) # ifdef _RWSTD_NO_CLASS_PARTIAL_SPEC const_iterator (const vector } Const_iterator operator- (difference_type i) const {const_iterator tmp = * this; return tmp - = i;} difference_type operator- (const_iterator x) const {return _RWSTD_WORD_BIT * (p - xp) offset - x.offset;} const_reference operator [] (DIFEERENCE_TYPE I) {RETURN * (* this i);} Bool Operator == (const const_iterator & x) const {return p == xp && offset == x.offset;} BOOL Operator <(const const_iterator & x) Const {RETURN P private: // // These private functions are replicas of generic algorithms // We provide them here to avoid putting instantiations of // the generic algorithms into an archive or shared library // This gives you full flexibilty in deciding where you want.. . // to put particular instantiations of the generic // algorithms // void __fill (iterator first, iterator last, const bool & value) {while (first = last!) * first = value;} void __fill_n (iterator first, size_type n , const bool & value) {while (n--> 0) * first = value;}! #ifndef _RWSTD_NO_MEMBER_TEMPLATES template } Iterator __copy_backward (const bool * limited, iterator result) {while (first! = Last) * - result = * - last; returnrate;} #ENDIFPROTECTED: Iterator __start; itrator __finish; __rwstd :: __ rw_basis unsigned int * __bit_alloc (size_type n) {return __value_alloc_type (__ end_of_storage) .allocate ((n _RWSTD_WORD_BIT - 1) / _ RWSTD_WORD_BIT, __ start.p);} void __init (size_type n) {unsigned int * q = __bit_alloc (n); __END_OF_STORAGE = Q (N _RWSTD_WORD_BIT - 1) / _ rwstd_word_bit; __start = Iterator (q, 0); __finish = __Start N;} void __insert_aux (item position, bool x); PUBLIC: // // construct / copy / destroy // vector Vector #ifndef _RWSTD_NO_MEMBER_TEMPLATES template INSERT (Begin (), first, last);} #ENDIFVOID ASSIGN (SIZE_TYPE N, Const Bool & T = BOOL ()) {ERAS (Begin (), End ()); INSERT (Begin (), N, T); } Allocator_type get_allocator () const {return (allocator_type) __ end_of_storage;} //// {RETURN __START;} const_iterator begin () const {return const_iterator (__ start.p, __ start.offset);} iterator end () {return__finish;} const_iterator end () const { Return const_iterator (__ finish.p, __ finish.offset); reverse_iterator rbegin () {return reverse_iterator (end ());} const_reverse_iterator rbegin () const {return const_reverse_iterator (end ());} reverse_iterator rend () {return reverse_iterator (begin ());} const_reverse_iterator rend () const {return Const_reverse_iterator (begin ()); // // capacity // size_type size () const {return size_type (end () - begin ());} size_type max_size () const {return __value_alloc_type (__ end_of_storage) .max_size ();} void resize (size_type new_size, bool C = false); size_type capacity () const {return size_type (const_iterator (_) (), 0) - begin ());} BOOL EMPTY () const {return begin () == end ();} void Reserve (size_type n) {_RWSTD_THROW (n> max_size (), length_error, __RWSTD :: except_msg_string (__ RWSTD :: __ rwse_InvalidSizeParam, "vector // // element access // reference operator [] (size_type n) {#ifdef _RWSTD_BOUNDS_CHECKING _RWSTD_THROW (n> = size (), out_of_range, __RWSTD :: except_msg_string (__ RWSTD :: rwse_OutOfRange, "vector Iterator Insert (Iterator Position, Const Bool & X = Bool ()) {size_type n = position - begin (); if (__finish.p! = __END_OF_Storage.Data () && position == end () * __ finish = x; Else __insert_aux (position, x); return begin () n;} void insert (iterator position, size_type n, const bool & x); # ifndef _RWSTD_NO_MEMBER_TEMPLATES template Iterator Erase {IF (! (position 1 == end ())) __copy (position 1, end (), position; --__ finish; return position;} {Iterator First, Iterator Last ) {__finish = __copy (last, end (), first); return first;} void swap (vector #ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC template While (first1! = last1 &&first2! = last2) {if ((int) * first1 <(int) * first2) Return True; if ((int) * first2 <(int) * first1 ) Return False;} Return First1 == Last1 &&first2! = last2;} #if! defined (_RWSTD_NO_NAMESPACE) ||! defined (_RWSTD_NO_PART_SPEC_OVERLOAD) #ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC template #ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC Template #ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC Template #ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC Template #ENDIF #ifdef _RWSTD_NO_CLASS_PARTIAL_SPEC # undef allocator #ENDIF #ENDIF / * _ RWSTD_NO_BOOL * / #ifndef _RWSTD_NO_NAMESPACE} #ENDIF #if Defined (_RWSTD_NO_TEMPLATE_REPOSTORY) && (! defined (__turboc__) || (__turboc__> 0x530)) # include #undef vector #ENDIF / * __SD_Vector__ * / #pragma option pop # endif / * __vector_h * /