Bcp 1.4.4
Loading...
Searching...
No Matches
BCP_vector_bool.hpp
Go to the documentation of this file.
1// Copyright (C) 2000, International Business Machines
2// Corporation and others. All Rights Reserved.
3
4#include <cstring>
5
6//##############################################################################
7
8/* The methods that are commented out are sort of generic methods that do not
9 need specialization. Their implementation is in BCP_vector_general.hpp */
10
11//##############################################################################
12
13// to get memmove
14#include <cstring>
15
16template<> inline void BCP_vec<bool>::destroy(iterator pos)
17{
18}
19//------------------------------------------------------------------------------
20template<> inline void BCP_vec<bool>::destroy_range(iterator first, iterator last)
21{
22}
23//------------------------------------------------------------------------------
24template<> inline void BCP_vec<bool>::construct(iterator pos)
25{
26 *pos = 0;
27}
28//------------------------------------------------------------------------------
29template<> inline void BCP_vec<bool>::construct(iterator pos, const_reference x)
30{
31 *pos = x;
32}
33
34//##############################################################################
35
36// template<> inline void BCP_vec<bool>::allocate(size_t len)
37//------------------------------------------------------------------------------
38template<> inline void BCP_vec<bool>::deallocate() {
39 if (start) {
40 ::operator delete(start);
41 }
42}
43//------------------------------------------------------------------------------
45
46//##############################################################################
47
48// template<> void BCP_vec<bool>::BCP_vec();
49//------------------------------------------------------------------------------
50// template<> void BCP_vec<bool>::BCP_vec(const BCP_vec<bool>& x);
51//------------------------------------------------------------------------------
52template<> BCP_vec<bool>::BCP_vec(const size_t n, const_reference value);
53//------------------------------------------------------------------------------
55//------------------------------------------------------------------------------
56template<> BCP_vec<bool>::BCP_vec(const bool* x, const size_t num);
57
58//##############################################################################
59
60template<> void BCP_vec<bool>::reserve(const size_t n);
61//------------------------------------------------------------------------------
62// template<> inline void BCP_vec<bool>::swap(BCP_vec<bool>& x);
63//------------------------------------------------------------------------------
65
66//##############################################################################
67// these two members serve to copy out entries from a buffer.
68
69template<> void BCP_vec<bool>::assign(const void* x, const size_t num);
70//------------------------------------------------------------------------------
71template<> void BCP_vec<bool>::insert(bool* position,
72 const void* first, const size_t n);
73//------------------------------------------------------------------------------
74template<> void BCP_vec<bool>::insert(iterator position,
75 const_iterator first,
76 const_iterator last);
77//------------------------------------------------------------------------------
78template<> void BCP_vec<bool>::insert(iterator position, const size_t n,
80//------------------------------------------------------------------------------
81template<> inline BCP_vec<bool>::iterator
83{
84 const size_t n = position - start;
85 if (finish != end_of_storage && position == finish) {
86 *finish++ = x;
87 } else
88 insert_aux(position, x);
89 return start + n;
90}
91
92//##############################################################################
93
95{
96 if (finish != end_of_storage)
97 *finish++ = x;
98 else
99 insert_aux(finish, x);
100}
101//------------------------------------------------------------------------------
103{
104 *finish++ = x;
105}
106//------------------------------------------------------------------------------
107template<> inline void BCP_vec<bool>::pop_back()
108{
109 --finish;
110}
111//------------------------------------------------------------------------------
112// template<> inline void BCP_vec<bool>::clear();
113//------------------------------------------------------------------------------
114template<> inline void
116 const BCP_vec<bool>& values)
117{
118 if (positions.size() == 0)
119 return;
120 const_iterator val = values.begin();
121 BCP_vec<int>::const_iterator pos = positions.begin();
122 const BCP_vec<int>::const_iterator lastpos = positions.end();
123 while (pos != lastpos)
124 operator[](*pos++) = *val++;
125}
126
127//------------------------------------------------------------------------------
128template<> inline void BCP_vec<bool>::update(const BCP_vec<int>& positions,
129 const BCP_vec<bool>& values)
130{
131 if (positions.size() != values.size())
132 throw BCP_fatal_error("BCP_vec::update() called with unequal sizes.\n");
133 BCP_vec_sanity_check(positions.begin(), positions.end(), size());
134 unchecked_update(positions, values);
135}
136
137//##############################################################################
138
139template<> inline void BCP_vec<bool>::keep(iterator pos)
140{
141 *start = *pos;
142 finish = start + 1;
143}
144//------------------------------------------------------------------------------
145template<> inline void BCP_vec<bool>::keep(iterator first, iterator last)
146{
147 const size_t len = last - first;
148 std::memmove(start, first, len * sizeof(bool));
149 finish = start + len;
150}
151//------------------------------------------------------------------------------
152// template<> inline void
153// BCP_vec<bool>::unchecked_keep_by_index(BCP_vec<int>::const_iterator firstpos,
154// BCP_vec<int>::const_iterator lastpos);
155//------------------------------------------------------------------------------
156// template<> inline void
157// BCP_vec<bool>::keep_by_index(BCP_vec<int>::const_iterator firstpos,
158// BCP_vec<int>::const_iterator lastpos);
159//------------------------------------------------------------------------------
160// template<> inline void
161// BCP_vec<bool>::keep_by_index(const BCP_vec<int>& positions);
162//------------------------------------------------------------------------------
163// template<> inline void
164// BCP_vec<bool>::unchecked_keep_by_index(const BCP_vec<int>& positions);
165
166//##############################################################################
167
168template<> inline void BCP_vec<bool>::erase(iterator position)
169{
170 if (position + 1 != finish)
171 std::memmove(position, position + 1, ((finish-position) - 1) * sizeof(bool));
172 --finish;
173}
174//------------------------------------------------------------------------------
175template<> inline void BCP_vec<bool>::erase(iterator first, iterator last)
176{
177 if (first != last && last != finish)
178 std::memmove(first, last, (finish - last) * sizeof(bool));
179 finish -= (last - first);
180}
181//------------------------------------------------------------------------------
182// template <class T> inline void
183// BCP_vec<T>::erase_by_index(const BCP_vec<int>& positions);
184//------------------------------------------------------------------------------
185// template <class T> inline void
186// BCP_vec<T>::unchecked_erase_by_index(const BCP_vec<int>& positions);
187//------------------------------------------------------------------------------
188// template <class T> inline void
189// BCP_vec<T>::erase_by_index(BCP_vec<int>::const_iterator firstpos,
190// BCP_vec<int>::const_iterator lastpos);
191//------------------------------------------------------------------------------
192// template <class T> void
193// BCP_vec<T>::unchecked_erase_by_index(BCP_vec<int>::const_iterator firstpos,
194// BCP_vec<int>::const_iterator lastpos);
195
196//#############################################################################
197
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
Abstract base class that defines members common to all types of variables.
Definition BCP_var.hpp:28
The class BCP_vec serves the same purpose as the vector class in the standard template library.
const T * const_iterator
void deallocate()
Destroy the entries in the vector and free the memory allocated for the vector.
void pop_back()
Delete the last entry.
const T & 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.
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.
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.
T * iterator
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.