Bcp 1.4.4
Loading...
Searching...
No Matches
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
11template<> inline void BCP_vec<int>::destroy(iterator pos)
12{
13}
14//------------------------------------------------------------------------------
15template<> inline void BCP_vec<int>::destroy_range(iterator first, iterator last)
16{
17}
18//------------------------------------------------------------------------------
19template<> inline void BCP_vec<int>::construct(iterator pos)
20{
21 *pos = 0;
22}
23//------------------------------------------------------------------------------
24template<> 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//------------------------------------------------------------------------------
33template<> inline void BCP_vec<int>::deallocate() {
34 if (start) {
35 ::operator delete(start);
36 }
37}
38//------------------------------------------------------------------------------
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//------------------------------------------------------------------------------
47template<> BCP_vec<int>::BCP_vec(const size_t n, const_reference value);
48//------------------------------------------------------------------------------
50//------------------------------------------------------------------------------
51template<> BCP_vec<int>::BCP_vec(const int* x, const size_t num);
52
53//##############################################################################
54
55template<> 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
64template<> void BCP_vec<int>::assign(const void* x, const size_t num);
65//------------------------------------------------------------------------------
66template<> void BCP_vec<int>::insert(int* position,
67 const void* first, const size_t n);
68//------------------------------------------------------------------------------
69template<> void BCP_vec<int>::insert(iterator position,
70 const_iterator first,
71 const_iterator last);
72//------------------------------------------------------------------------------
73template<> void BCP_vec<int>::insert(iterator position, const size_t n,
75//------------------------------------------------------------------------------
76template<> inline BCP_vec<int>::iterator
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
90{
92 *finish++ = x;
93 else
95}
96//------------------------------------------------------------------------------
98{
99 *finish++ = x;
100}
101//------------------------------------------------------------------------------
102template<> inline void BCP_vec<int>::pop_back()
103{
104 --finish;
105}
106//------------------------------------------------------------------------------
107// template<> inline void BCP_vec<int>::clear();
108//------------------------------------------------------------------------------
109template<> 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//------------------------------------------------------------------------------
122template<> 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
133template<> inline void BCP_vec<int>::keep(iterator pos)
134{
135 *start = *pos;
136 finish = start + 1;
137}
138//------------------------------------------------------------------------------
139template<> 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
162template<> 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//------------------------------------------------------------------------------
169template<> 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
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.
Currently there isn't any error handling in BCP.
Definition BCP_error.hpp:20
const BCP_cut ** const_iterator
void deallocate()
Destroy the entries in the vector and free the memory allocated for the vector.
BCP_vec(const size_t n, const_reference value)
void unchecked_update(const BCP_vec< int > &positions, const BCP_vec< bool > &values)
void pop_back()
Delete the last entry.
const BCP_cut *& const_reference
void push_back(const_reference x)
Append x to the end of the vector.
void unchecked_push_back(const_reference x)
Append x to the end of the vector.
iterator end()
Return an iterator to the end of the object.
size_t size() const
Return the current number of entries.
void keep(iterator pos)
Keep only the entry pointed to by pos.
reference operator[](const size_t i)
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.
void erase(iterator pos)
Erase the entry pointed to by pos.
void insert_aux(iterator position, const_reference x)
iterator begin()
Return an iterator to the beginning of the object.
void update(const BCP_vec< int > &positions, const BCP_vec< T > &values)
Update those entries listed in positions to the given values.
void unchecked_update(const BCP_vec< int > &positions, const BCP_vec< T > &values)
Same as the previous method but without sanity checks.
BCP_vec()
The default constructor initializes the data members as 0 pointers.
void reserve(const size_t n)
Reallocate the object to make space for n entries.
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.
void assign(const void *x, const size_t num)
Copy num entries of type T starting at the memory location x into the object.
void insert_aux(iterator position, const_reference x)
insert x into the given position in the vector.