2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: NCVector.h /main/1 1996/07/29 16:58:13 cde-hp $ */
24 // Copyright (c) 1994, 1996 James Clark
25 // See the file COPYING for copying permission.
27 #ifndef NCVector_INCLUDED
28 #define NCVector_INCLUDED 1
33 // This offers a subset of the interface offered by the standard C++
34 // vector class as defined in the Jan 96 WP.
35 // Code in SP currently assumes that size_type is size_t.
38 namespace SP_NAMESPACE {
44 typedef size_t size_type;
46 typedef const T *const_iterator;
47 NCVector() : ptr_(0), size_(0), alloc_(0) { }
48 NCVector(size_t n) : ptr_(0), size_(0), alloc_(0) { append(n); }
50 void resize(size_t n) {
52 erase(ptr_ + n, ptr_ + size_);
56 void swap(NCVector<T> &);
57 void clear() { erase(ptr_, ptr_ + size_); }
58 size_t size() const { return size_; }
59 T &operator[](size_t i) { return ptr_[i]; }
60 const T &operator[](size_t i) const { return ptr_[i]; }
61 iterator begin() { return ptr_; }
62 const_iterator begin() const { return ptr_; }
63 T &back() { return ptr_[size_ - 1]; }
64 const T &back() const { return ptr_[size_ - 1]; }
65 void reserve(size_t n) { if (n > alloc_) reserve1(n); }
66 iterator erase(const_iterator, const_iterator);
69 void reserve1(size_t);
73 size_t alloc_; // allocated size
80 #endif /* not NCVector_INCLUDED */
82 #ifdef SP_DEFINE_TEMPLATES