home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 May / PCFMay2001.iso / Xenon / C++ / FreeCommandLineTools.exe / Include / Rw / locvecto.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-31  |  3.7 KB  |  132 lines

  1. #ifndef __LOCVECTO_H
  2. #define __LOCVECTO_H
  3. #pragma option push -b -a8 -pc -Vx- -Ve- -w-inl -w-aus -w-sig
  4. #ifndef __LOCALE_VECTOR
  5. #define __LOCALE_VECTOR
  6. /***************************************************************************
  7.  *
  8.  * locvector - Declarations for locales local vector class
  9.  *
  10.  ***************************************************************************
  11.  *
  12.  * Copyright (c) 1994-1999 Rogue Wave Software, Inc.  All Rights Reserved.
  13.  *
  14.  * This computer software is owned by Rogue Wave Software, Inc. and is
  15.  * protected by U.S. copyright laws and other laws and by international
  16.  * treaties.  This computer software is furnished by Rogue Wave Software,
  17.  * Inc. pursuant to a written license agreement and may be used, copied,
  18.  * transmitted, and stored only in accordance with the terms of such
  19.  * license and with the inclusion of the above copyright notice.  This
  20.  * computer software or any other copies thereof may not be provided or
  21.  * otherwise made available to any other person.
  22.  *
  23.  * U.S. Government Restricted Rights.  This computer software is provided
  24.  * with Restricted Rights.  Use, duplication, or disclosure by the
  25.  * Government is subject to restrictions as set forth in subparagraph (c)
  26.  * (1) (ii) of The Rights in Technical Data and Computer Software clause
  27.  * at DFARS 252.227-7013 or subparagraphs (c) (1) and (2) of the
  28.  * Commercial Computer Software รป Restricted Rights at 48 CFR 52.227-19,
  29.  * as applicable.  Manufacturer is Rogue Wave Software, Inc., 5500
  30.  * Flatiron Parkway, Boulder, Colorado 80301 USA.
  31.  *
  32.  **************************************************************************/
  33.  
  34. #ifndef _RWSTD_NO_NAMESPACE
  35. namespace __rwstd {
  36. #endif
  37.  
  38. #ifdef __TURBOC__
  39. #pragma option -w-inl
  40. #pragma option -w-par
  41. #endif
  42.  
  43. // Minute vector class
  44. template <class T>
  45. class locale_vector
  46. {
  47. public:
  48.     typedef size_t size_type;
  49.     typedef ptrdiff_t difference_type;
  50.     typedef T value_type;
  51.     typedef T& reference;
  52.     typedef T* pointer;
  53.     typedef T* iterator;
  54.  
  55. private:
  56.   iterator first_;
  57.   size_type size_;
  58.  
  59. public:
  60.   locale_vector() : first_(0), size_(0) {;}
  61.   locale_vector(size_type n) : first_(0), size_(n) 
  62.   {
  63.     if (n)
  64.       first_ = new T[n];
  65.   }
  66.   locale_vector(size_type n, const T& v) : first_(0), size_(n) 
  67.   {
  68.     if (n)
  69.       first_ = new T[n];
  70.     while (n)
  71.       first_[--n] = v;
  72.   }
  73.   locale_vector(const locale_vector<T>& lv) : first_(0), size_(0)
  74.   {
  75.     size_type n = size_ = lv.size();
  76.     if (n)
  77.       first_ = new T[n];
  78.     while (n--)
  79.       first_[n] = lv[n];
  80.   }    
  81.   ~locale_vector() { if (first_) delete [] first_;}
  82.   const locale_vector& operator= (const locale_vector& lv) 
  83.   {
  84.     size_type n = size_ = lv.size();
  85.     if (first_)
  86.       delete [] first_;
  87.     if (n)
  88.       first_ = new T[n];
  89.     while (n--)
  90.       first_[n] = lv[n];
  91.     return *this;
  92.   }
  93.   iterator begin() const { return iterator(first_); }
  94.   iterator end() const { return iterator(first_+size_); }    
  95.   size_type size() const { return size_; }
  96.  
  97.   T& operator[] (size_t i) { return first_[i]; }
  98.   const T& operator[] (size_t i) const { return first_[i]; }
  99.  
  100.   // Resize array and copy old contents to new buffer. 
  101.   iterator resize(size_t s)
  102.   { 
  103.      return resize(s,T()); 
  104.   }
  105.   iterator resize(size_t s, T v)
  106.   {
  107.     T *new_buf = new T[s];
  108.     iterator j,k;
  109.     size_type d = size_ < s ? size_ : s;
  110.  
  111.     for (j = first_, k = new_buf; j != first_+d; j++,k++)
  112.       *k =  *j;
  113.  
  114.     while (d < s)
  115.       new_buf[d++] = v;
  116.  
  117.     if (first_)
  118.       delete [] first_;    
  119.     first_ = new_buf;
  120.     size_ = s;
  121.     return first_;
  122.   }
  123. };
  124.  
  125. #ifndef _RWSTD_NO_NAMESPACE
  126. } // namespace __rwstd
  127. #endif
  128. #endif // __LOCALE_VECTOR
  129.  
  130. #pragma option pop
  131. #endif /* __LOCVECTO_H */
  132.