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: Vector.h /main/1 1996/07/29 17:08:00 cde-hp $ */
24 // Copyright (c) 1994, 1996 James Clark
25 // See the file COPYING for copying permission.
27 #ifndef Vector_INCLUDED
28 #define Vector_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 Vector() : ptr_(0), size_(0), alloc_(0) { }
48 Vector(size_t n) : ptr_(0), size_(0), alloc_(0) { append(n); }
50 void resize(size_t n) {
52 erase(ptr_ + n, ptr_ + size_);
56 Vector(size_t, const T &);
57 Vector(const Vector<T> &);
58 Vector<T> &operator=(const Vector<T> &);
59 void assign(size_t, const T &);
60 void push_back(const T &t) {
62 (void)new (ptr_ + size_++) T(t);
64 void insert(const_iterator p, size_t n, const T &t);
65 void insert(const_iterator p, const_iterator q1, const_iterator q2);
66 void swap(Vector<T> &);
67 void clear() { erase(ptr_, ptr_ + size_); }
68 size_t size() const { return size_; }
69 T &operator[](size_t i) { return ptr_[i]; }
70 const T &operator[](size_t i) const { return ptr_[i]; }
71 iterator begin() { return ptr_; }
72 const_iterator begin() const { return ptr_; }
73 T &back() { return ptr_[size_ - 1]; }
74 const T &back() const { return ptr_[size_ - 1]; }
75 void reserve(size_t n) { if (n > alloc_) reserve1(n); }
76 iterator erase(const_iterator, const_iterator);
79 void reserve1(size_t);
83 size_t alloc_; // allocated size
90 #endif /* not Vector_INCLUDED */
92 #ifdef SP_DEFINE_TEMPLATES