w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

vectorv.cc
Go to the documentation of this file.
1 /*
2  * vectorv.cc -- template specialization for Vector<void*>
3  * Eddie Kohler
4  *
5  * Copyright (c) 1999-2006 Massachusetts Institute of Technology
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a
8  * copy of this software and associated documentation files (the "Software"),
9  * to deal in the Software without restriction, subject to the conditions
10  * listed in the Click LICENSE file. These conditions include: you must
11  * preserve this copyright notice, and you cannot mention the copyright
12  * holders in advertising related to the Software without their permission.
13  * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This
14  * notice is a summary of the Click LICENSE file; the license in that file is
15  * legally binding.
16  */
17 
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21 #include <lcdf/vector.hh>
22 #include <string.h>
23 
25  : _l(0), _n(0), _capacity(0)
26 {
27  *this = o;
28 }
29 
31 {
32  delete[] _l;
33 }
34 
37 {
38  if (&o != this) {
39  _n = 0;
40  if (reserve(o._n)) {
41  _n = o._n;
42  memcpy(_l, o._l, sizeof(void *) * _n);
43  }
44  }
45  return *this;
46 }
47 
50 {
51  _n = 0;
52  resize(n, e);
53  return *this;
54 }
55 
56 bool
58 {
59  if (want < 0)
60  want = (_capacity > 0 ? _capacity * 2 : 4);
61  if (want <= _capacity)
62  return true;
63 
64  void **new_l = new void*[want];
65  if (!new_l)
66  return false;
67 
68  if (_n) {
69  memcpy(new_l, _l, sizeof(void*) * _n);
70  }
71  delete[] _l;
72 
73  _l = new_l;
74  _capacity = want;
75  return true;
76 }
77 
80 {
81  if (b > a) {
82  assert(a >= begin() && b <= end());
83  memmove(a, b, (end() - b) * sizeof(void*));
84  _n -= b - a;
85  return a;
86  } else
87  return b;
88 }
89 
90 void
92 {
93  if (nn <= _capacity || reserve(nn)) {
94  for (int i = _n; i < nn; i++)
95  _l[i] = e;
96  _n = nn;
97  }
98 }
99 
100 void
102 {
103  void **l = _l;
104  int n = _n;
105  int cap = _capacity;
106  _l = o._l;
107  _n = o._n;
108  _capacity = o._capacity;
109  o._l = l;
110  o._n = n;
111  o._capacity = cap;
112 }
size_type _n
Definition: vector.hh:212
void ** iterator
Definition: vector.hh:157
void ** _l
Definition: vector.hh:211
size_type _capacity
Definition: vector.hh:213
Definition: vector.hh:17
size_type _capacity
Definition: vector.hh:93
Vector()
Definition: vector.hh:32
iterator erase(iterator it)
Definition: vector.hh:126
iterator begin()
Definition: vector.hh:48
Vector< T > & assign(size_type n, const T &e=T())
Definition: vector.cc:65
void swap(Vector< T > &x)
Definition: vector.cc:187
T * _l
Definition: vector.hh:91
Vector< T > & operator=(const Vector< T > &)
Definition: vector.cc:41
void resize(size_type nn, const T &e=T())
Definition: vector.cc:166
iterator end()
Definition: vector.hh:50
bool reserve(size_type n)
Definition: vector.hh:58
~Vector()
Definition: vector.cc:33
size_type _n
Definition: vector.hh:92
#define n
Definition: t4ht.c:1290
#define b
Definition: jpegint.h:372
#define a(n)
Definition: gpos-common.c:148
#define memmove(d, s, n)
Definition: gsftopk.c:65
#define memcpy(d, s, n)
Definition: gsftopk.c:64
assert(pcxLoadImage24((char *)((void *) 0), fp, pinfo, hdr))
small capitals from c petite p scientific i
Definition: afcover.h:80
integer nn[24]
Definition: pmxab.c:90
ShellFileEnvironment e
Definition: sh6.c:388