Bcp  1.4.4
BCP_vector_int.hpp
Go to the documentation of this file.
1 // Copyright (C) 2000, International Business Machines
2 // Corporation and others. All Rights Reserved.
3 
4 //##############################################################################
5 
6 /* The methods that are commented out are sort of generic methods that do not
7  need specialization. Their implementation is in BCP_vector_general.hpp */
8 
9 //##############################################################################
10 
11 template<> inline void BCP_vec<int>::destroy(iterator pos)
12 {
13 }
14 //------------------------------------------------------------------------------
15 template<> inline void BCP_vec<int>::destroy_range(iterator first, iterator last)
16 {
17 }
18 //------------------------------------------------------------------------------
19 template<> inline void BCP_vec<int>::construct(iterator pos)
20 {
21  *pos = 0;
22 }
23 //------------------------------------------------------------------------------
24 template<> inline void BCP_vec<int>::construct(iterator pos, const_reference x)
25 {
26  *pos = x;
27 }
28 
29 //##############################################################################
30 
31 // template<> inline void BCP_vec<int>::allocate(size_t len)
32 //------------------------------------------------------------------------------
33 template<> inline void BCP_vec<int>::deallocate() {
34  if (start) {
35  ::operator delete(start);
36  }
37 }
38 //------------------------------------------------------------------------------
39 template<> void BCP_vec<int>::insert_aux(iterator position, const_reference x);
40 
41 //##############################################################################
42 
43 // template<> void BCP_vec<int>::BCP_vec();
44 //------------------------------------------------------------------------------
45 // template<> void BCP_vec<int>::BCP_vec(const BCP_vec<int>& x);
46 //------------------------------------------------------------------------------
47 template<> BCP_vec<int>::BCP_vec(const size_t n, const_reference value);
48 //------------------------------------------------------------------------------
49 template<> BCP_vec<int>::BCP_vec(const_iterator first, const_iterator last);
50 //------------------------------------------------------------------------------
51 template<> BCP_vec<int>::BCP_vec(const int* x, const size_t num);
52 
53 //##############################################################################
54 
55 template<> void BCP_vec<int>::reserve(const size_t n);
56 //------------------------------------------------------------------------------
57 // template<> inline void BCP_vec<int>::swap(BCP_vec<int>& x);
58 //------------------------------------------------------------------------------
60 
61 //##############################################################################
62 // these two members serve to copy out entries from a buffer.
63 
64 template<> void BCP_vec<int>::assign(const void* x, const size_t num);
65 //------------------------------------------------------------------------------
66 template<> void BCP_vec<int>::insert(int* position,
67  const void* first, const size_t n);
68 //------------------------------------------------------------------------------
69 template<> void BCP_vec<int>::insert(iterator position,
70  const_iterator first,
71  const_iterator last);
72 //------------------------------------------------------------------------------
73 template<> void BCP_vec<int>::insert(iterator position, const size_t n,
74  const_reference x);
75 //------------------------------------------------------------------------------
76 template<> inline BCP_vec<int>::iterator
77 BCP_vec<int>::insert(iterator position, const_reference x)
78 {
79  const size_t n = position - start;
80  if (finish != end_of_storage && position == finish) {
81  *finish++ = x;
82  } else
83  insert_aux(position, x);
84  return start + n;
85 }
86 
87 //##############################################################################
88 
89 template<> inline void BCP_vec<int>::push_back(const_reference x)
90 {
91  if (finish != end_of_storage)
92  *finish++ = x;
93  else
94  insert_aux(finish, x);
95 }
96 //------------------------------------------------------------------------------
97 template<> inline void BCP_vec<int>::unchecked_push_back(const_reference x)
98 {
99  *finish++ = x;
100 }
101 //------------------------------------------------------------------------------
102 template<> inline void BCP_vec<int>::pop_back()
103 {
104  --finish;
105 }
106 //------------------------------------------------------------------------------
107 // template<> inline void BCP_vec<int>::clear();
108 //------------------------------------------------------------------------------
109 template<> inline void
111  const BCP_vec<int>& values)
112 {
113  if (positions.size() == 0)
114  return;
115  const_iterator val = values.begin();
116  BCP_vec<int>::const_iterator pos = positions.begin();
117  const BCP_vec<int>::const_iterator lastpos = positions.end();
118  while (pos != lastpos)
119  operator[](*pos++) = *val++;
120 }
121 //------------------------------------------------------------------------------
122 template<> inline void BCP_vec<int>::update(const BCP_vec<int>& positions,
123  const BCP_vec<int>& values)
124 {
125  if (positions.size() != values.size())
126  throw BCP_fatal_error("BCP_vec::update() called with unequal sizes.\n");
127  BCP_vec_sanity_check(positions.begin(), positions.end(), size());
128  unchecked_update(positions, values);
129 }
130 
131 //##############################################################################
132 
133 template<> inline void BCP_vec<int>::keep(iterator pos)
134 {
135  *start = *pos;
136  finish = start + 1;
137 }
138 //------------------------------------------------------------------------------
139 template<> inline void BCP_vec<int>::keep(iterator first, iterator last)
140 {
141  const size_t len = last - first;
142  memmove(start, first, len * sizeof(int));
143  finish = start + len;
144 }
145 //------------------------------------------------------------------------------
146 // template<> inline void
147 // BCP_vec<int>::unchecked_keep_by_index(BCP_vec<int>::const_iterator firstpos,
148 // BCP_vec<int>::const_iterator lastpos);
149 //------------------------------------------------------------------------------
150 // template<> inline void
151 // BCP_vec<int>::keep_by_index(BCP_vec<int>::const_iterator firstpos,
152 // BCP_vec<int>::const_iterator lastpos);
153 //------------------------------------------------------------------------------
154 // template<> inline void
155 // BCP_vec<int>::keep_by_index(const BCP_vec<int>& positions);
156 //------------------------------------------------------------------------------
157 // template<> inline void
158 // BCP_vec<int>::unchecked_keep_by_index(const BCP_vec<int>& positions);
159 
160 //##############################################################################
161 
162 template<> inline void BCP_vec<int>::erase(iterator position)
163 {
164  if (position + 1 != finish)
165  memmove(position, position + 1, ((finish-position) - 1) * sizeof(int));
166  --finish;
167 }
168 //------------------------------------------------------------------------------
169 template<> inline void BCP_vec<int>::erase(iterator first, iterator last)
170 {
171  if (first != last && last != finish)
172  memmove(first, last, (finish - last) * sizeof(int));
173  finish -= (last - first);
174 }
175 //------------------------------------------------------------------------------
176 // template <class T> inline void
177 // BCP_vec<T>::erase_by_index(const BCP_vec<int>& positions);
178 //------------------------------------------------------------------------------
179 // template <class T> inline void
180 // BCP_vec<T>::unchecked_erase_by_index(const BCP_vec<int>& positions);
181 //------------------------------------------------------------------------------
182 // template <class T> inline void
183 // BCP_vec<T>::erase_by_index(BCP_vec<int>::const_iterator firstpos,
184 // BCP_vec<int>::const_iterator lastpos);
185 //------------------------------------------------------------------------------
186 // template <class T> void
187 // BCP_vec<T>::unchecked_erase_by_index(BCP_vec<int>::const_iterator firstpos,
188 // BCP_vec<int>::const_iterator lastpos);
189 
190 //#############################################################################
191 
BCP_vec::operator=
BCP_vec< T > & operator=(const BCP_vec< T > &x)
Copy the contents of x into the object and return a reference the the object itself.
Definition: BCP_vector_general.hpp:131
BCP_vec::unchecked_update
void unchecked_update(const BCP_vec< int > &positions, const BCP_vec< T > &values)
Same as the previous method but without sanity checks.
Definition: BCP_vector_general.hpp:324
BCP_vec
The class BCP_vec serves the same purpose as the vector class in the standard template library.
Definition: BCP_vector.hpp:24
BCP_vec::assign
void assign(const void *x, const size_t num)
Copy num entries of type T starting at the memory location x into the object.
Definition: BCP_vector_general.hpp:157
BCP_vec::unchecked_push_back
void unchecked_push_back(const_reference x)
Append x to the end of the vector.
Definition: BCP_vector_general.hpp:308
BCP_vec::size
size_t size() const
Return the current number of entries.
Definition: BCP_vector.hpp:116
BCP_vec::erase
void erase(iterator pos)
Erase the entry pointed to by pos.
Definition: BCP_vector_general.hpp:399
BCP_vec::begin
iterator begin()
Return an iterator to the beginning of the object.
Definition: BCP_vector.hpp:99
BCP_vec::start
iterator start
Iterator pointing to the beginning of the memory array where the vector is stored.
Definition: BCP_vector.hpp:66
BCP_vec::push_back
void push_back(const_reference x)
Append x to the end of the vector.
Definition: BCP_vector_general.hpp:300
BCP_vec::update
void update(const BCP_vec< int > &positions, const BCP_vec< T > &values)
Update those entries listed in positions to the given values.
Definition: BCP_vector_general.hpp:336
BCP_vec::deallocate
void deallocate()
Destroy the entries in the vector and free the memory allocated for the vector.
Definition: BCP_vector_general.hpp:35
BCP_vec::reserve
void reserve(const size_t n)
Reallocate the object to make space for n entries.
Definition: BCP_vector_general.hpp:112
BCP_vec_sanity_check
void BCP_vec_sanity_check(BCP_vec< int >::const_iterator firstpos, BCP_vec< int >::const_iterator lastpos, const int maxsize)
A helper function to test whether a set positions is sane for a vector.
BCP_vec::insert_aux
void insert_aux(iterator position, const_reference x)
insert x into the given position in the vector.
Definition: BCP_vector_general.hpp:43
BCP_vec::finish
iterator finish
Iterator pointing to right after the last entry in the vector.
Definition: BCP_vector.hpp:68
BCP_vec::keep
void keep(iterator pos)
Keep only the entry pointed to by pos.
Definition: BCP_vector_general.hpp:347
BCP_vec::const_iterator
const T * const_iterator
Definition: BCP_vector.hpp:35
BCP_vec::insert
void insert(iterator position, const void *first, const size_t num)
Insert num entries starting from memory location first into the vector from position pos.
Definition: BCP_vector_general.hpp:176
BCP_vec::end_of_storage
iterator end_of_storage
Iterator pointing to right after the last memory location usable by the vector without reallocation.
Definition: BCP_vector.hpp:71
BCP_vec::operator[]
reference operator[](const size_t i)
Return a reference to the i-th entry.
Definition: BCP_vector.hpp:124
BCP_vec::BCP_vec
BCP_vec()
The default constructor initializes the data members as 0 pointers.
Definition: BCP_vector_general.hpp:65
BCP_vec::pop_back
void pop_back()
Delete the last entry.
Definition: BCP_vector_general.hpp:313
BCP_vec::end
iterator end()
Return an iterator to the end of the object.
Definition: BCP_vector.hpp:104
BCP_fatal_error
Currently there isn't any error handling in BCP.
Definition: BCP_error.hpp:20