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.C /main/3 1996/08/17 08:15:28 mgreess $ */
24 // Copyright (c) 1994, 1996 James Clark
25 // See the file COPYING for copying permission.
27 #ifndef Vector_DEF_INCLUDED
28 #define Vector_DEF_INCLUDED 1
33 #ifdef SP_QUAL_TEMPLATE_DTOR_BROKEN
40 namespace SP_NAMESPACE {
47 erase(ptr_, ptr_ + size_);
48 ::operator delete((void *)ptr_);
53 Vector<T>::Vector(const Vector<T> &v)
54 : ptr_(0), size_(0), alloc_(0)
56 insert(ptr_ + size_, v.ptr_, v.ptr_ + v.size_);
60 Vector<T>::Vector(size_t n, const T &t)
61 : ptr_(0), size_(0), alloc_(0)
63 insert(ptr_ + size_, n, t);
67 Vector<T> &Vector<T>::operator=(const Vector<T> &v)
73 insert(ptr_ + size_, v.ptr_ + size_, v.ptr_ + v.size_);
76 erase(ptr_ + n, ptr_ + size_);
84 void Vector<T>::assign(size_t n, const T &t)
89 insert(ptr_ + size_, n - size_, t);
92 erase(ptr_ + n, ptr_ + size_);
98 void Vector<T>::insert(const T *p, size_t n, const T &t)
103 memmove(ptr_ + i + n, ptr_ + i, (size_ - i)*sizeof(T));
105 for (T *pp = ptr_ + i; n-- > 0; pp++)
110 void Vector<T>::insert(const T *p, const T *q1, const T *q2)
116 memmove(ptr_ + i + n, ptr_ + i, (size_ - i)*sizeof(T));
118 for (T *pp = ptr_ + i; q1 != q2; q1++, pp++)
119 (void)new (pp) T(*q1);
123 void Vector<T>::swap(Vector<T> &v)
143 void Vector<T>::append(size_t n)
147 (void)new (ptr_ + size_++) T;
151 T *Vector<T>::erase(const T *p1, const T *p2)
153 #if !defined(SP_TEMPLATE_DESTRUCTOR_COMPILER_BUG)
154 for (const T *p = p1; p != p2; p++)
157 if (p2 != ptr_ + size_)
158 memmove((T *)p1, p2, ((const T *)(ptr_ + size_) - p2)*sizeof(T));
164 void Vector<T>::reserve1(size_t size)
169 void *p = ::operator new(alloc_*sizeof(T));
171 memcpy(p, ptr_, size_*sizeof(T));
172 ::operator delete((void *)ptr_);
181 #endif /* not Vector_DEF_INCLUDED */