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 librararies 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.C /main/1 1996/07/29 16:58:08 cde-hp $ */
24 // Copyright (c) 1994, 1996 James Clark
25 // See the file COPYING for copying permission.
27 #ifndef NCVector_DEF_INCLUDED
28 #define NCVector_DEF_INCLUDED 1
33 #ifdef SP_QUAL_TEMPLATE_DTOR_BROKEN
40 namespace SP_NAMESPACE {
44 NCVector<T>::~NCVector()
47 erase(ptr_, ptr_ + size_);
48 ::operator delete((void *)ptr_);
55 NCVector<T>::NCVector(const NCVector<T> &v)
56 : ptr_(0), size_(0), alloc_(0)
58 insert(ptr_ + size_, v.ptr_, v.ptr_ + v.size_);
62 NCVector<T>::NCVector(size_t n, const T &t)
63 : ptr_(0), size_(0), alloc_(0)
65 insert(ptr_ + size_, n, t);
69 NCVector<T> &NCVector<T>::operator=(const NCVector<T> &v)
75 insert(ptr_ + size_, v.ptr_ + size_, v.ptr_ + v.size_);
78 erase(ptr_ + n, ptr_ + size_);
86 void NCVector<T>::assign(size_t n, const T &t)
91 insert(ptr_ + size_, n - size_, t);
94 erase(ptr_ + n, ptr_ + size_);
100 void NCVector<T>::insert(const T *p, size_t n, const T &t)
105 memmove(ptr_ + i + n, ptr_ + i, (size_ - i)*sizeof(T));
107 for (T *pp = ptr_ + i; n-- > 0; pp++)
112 void NCVector<T>::insert(const T *p, const T *q1, const T *q2)
118 memmove(ptr_ + i + n, ptr_ + i, (size_ - i)*sizeof(T));
120 for (T *pp = ptr_ + i; q1 != q2; q1++, pp++)
121 (void)new (pp) T(*q1);
127 void NCVector<T>::swap(NCVector<T> &v)
147 void NCVector<T>::append(size_t n)
151 (void)new (ptr_ + size_++) T;
155 T *NCVector<T>::erase(const T *p1, const T *p2)
158 for (const T *p = p1; p != p2; p++)
159 /* ((X *)p)->~X(); */
161 if (p2 != ptr_ + size_)
162 memmove((T *)p1, p2, ((const T *)(ptr_ + size_) - p2)*sizeof(T));
168 void NCVector<T>::reserve1(size_t size)
173 void *p = ::operator new(alloc_*sizeof(T));
175 memcpy(p, ptr_, size_*sizeof(T));
176 ::operator delete((void *)ptr_);
185 #endif /* not NCVector_DEF_INCLUDED */