Bcp 1.4.4
Loading...
Searching...
No Matches
BCP_vector_short.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
13template<> inline void BCP_vec<short>::destroy(iterator pos)
14{
15}
16//------------------------------------------------------------------------------
17template<> inline void BCP_vec<short>::destroy_range(iterator first, iterator last)
18{
19}
20//------------------------------------------------------------------------------
21template<> inline void BCP_vec<short>::construct(iterator pos)
22{
23 *pos = 0;
24}
25//------------------------------------------------------------------------------
26template<> inline void BCP_vec<short>::construct(iterator pos, const_reference x)
27{
28 *pos = x;
29}
30
31//##############################################################################
32
33// template<> inline void BCP_vec<short>::allocate(size_t len)
34//------------------------------------------------------------------------------
35template<> inline void BCP_vec<short>::deallocate() {
36 if (start) {
37 ::operator delete(start);
38 }
39}
40//------------------------------------------------------------------------------
42
43//##############################################################################
44
45// template<> void BCP_vec<short>::BCP_vec();
46//------------------------------------------------------------------------------
47// template<> void BCP_vec<short>::BCP_vec(const BCP_vec<short>& x);
48//------------------------------------------------------------------------------
49template<> BCP_vec<short>::BCP_vec(const size_t n, const_reference value);
50//------------------------------------------------------------------------------
52//------------------------------------------------------------------------------
53template<> BCP_vec<short>::BCP_vec(const short* x, const size_t num);
54
55//##############################################################################
56
57template<> void BCP_vec<short>::reserve(const size_t n);
58//------------------------------------------------------------------------------
59// template<> inline void BCP_vec<short>::swap(BCP_vec<short>& x);
60//------------------------------------------------------------------------------
62
63//##############################################################################
64// these two members serve to copy out entries from a buffer.
65
66template<> void BCP_vec<short>::assign(const void* x, const size_t num);
67//------------------------------------------------------------------------------
68template<> void BCP_vec<short>::insert(short* position,
69 const void* first, const size_t n);
70//------------------------------------------------------------------------------
71template<> void BCP_vec<short>::insert(iterator position,
72 const_iterator first,
73 const_iterator last);
74//------------------------------------------------------------------------------
75template<> void BCP_vec<short>::insert(iterator position, const size_t n,
77//------------------------------------------------------------------------------
78template<> inline BCP_vec<short>::iterator
80{
81 const size_t n = position - start;
82 if (finish != end_of_storage && position == finish) {
83 *finish++ = x;
84 } else
85 insert_aux(position, x);
86 return start + n;
87}
88
89//##############################################################################
90
92{
93 if (finish != end_of_storage)
94 *finish++ = x;
95 else
96 insert_aux(finish, x);
97}
98//------------------------------------------------------------------------------
100{
101 *finish++ = x;
102}
103//------------------------------------------------------------------------------
104template<> inline void BCP_vec<short>::pop_back()
105{
106 --finish;
107}
108//------------------------------------------------------------------------------
109// template<> inline void BCP_vec<short>::clear();
110//------------------------------------------------------------------------------
111template<> inline void
113 const BCP_vec<short>& values)
114{
115 if (positions.size() == 0)
116 return;
117 const_iterator val = values.begin();
118 BCP_vec<int>::const_iterator pos = positions.begin();
119 const BCP_vec<int>::const_iterator lastpos = positions.end();
120 while (pos != lastpos)
121 operator[](*pos++) = *val++;
122}
123//------------------------------------------------------------------------------
124template<> inline void BCP_vec<short>::update(const BCP_vec<int>& positions,
125 const BCP_vec<short>& values)
126{
127 if (positions.size() != values.size())
128 throw BCP_fatal_error("BCP_vec::update() called with unequal sizes.\n");
129 BCP_vec_sanity_check(positions.begin(), positions.end(), size());
130 unchecked_update(positions, values);
131}
132
133//##############################################################################
134
135template<> inline void BCP_vec<short>::keep(iterator pos)
136{
137 *start = *pos;
138 finish = start + 1;
139}
140//------------------------------------------------------------------------------
141template<> inline void BCP_vec<short>::keep(iterator first, iterator last)
142{
143 const size_t len = last - first;
144 std::memmove(start, first, len * sizeof(short));
145 finish = start + len;
146}
147//------------------------------------------------------------------------------
148// template<> inline void
149// BCP_vec<short>::unchecked_keep_by_index(BCP_vec<int>::const_iterator firstpos,
150// BCP_vec<int>::const_iterator lastpos);
151//------------------------------------------------------------------------------
152// template<> inline void
153// BCP_vec<short>::keep_by_index(BCP_vec<int>::const_iterator firstpos,
154// BCP_vec<int>::const_iterator lastpos);
155//------------------------------------------------------------------------------
156// template<> inline void
157// BCP_vec<short>::keep_by_index(const BCP_vec<int>& positions);
158//------------------------------------------------------------------------------
159// template<> inline void
160// BCP_vec<short>::unchecked_keep_by_index(const BCP_vec<int>& positions);
161
162//##############################################################################
163
164template<> inline void BCP_vec<short>::erase(iterator position)
165{
166 if (position + 1 != finish)
167 std::memmove(position, position + 1, ((finish-position) - 1) * sizeof(short));
168 --finish;
169}
170//------------------------------------------------------------------------------
171template<> inline void BCP_vec<short>::erase(iterator first, iterator last)
172{
173 if (first != last && last != finish)
174 std::memmove(first, last, (finish - last) * sizeof(short));
175 finish -= (last - first);
176}
177//------------------------------------------------------------------------------
178// template <class T> inline void
179// BCP_vec<T>::erase_by_index(const BCP_vec<int>& positions);
180//------------------------------------------------------------------------------
181// template <class T> inline void
182// BCP_vec<T>::unchecked_erase_by_index(const BCP_vec<int>& positions);
183//------------------------------------------------------------------------------
184// template <class T> inline void
185// BCP_vec<T>::erase_by_index(BCP_vec<int>::const_iterator firstpos,
186// BCP_vec<int>::const_iterator lastpos);
187//------------------------------------------------------------------------------
188// template <class T> void
189// BCP_vec<T>::unchecked_erase_by_index(BCP_vec<int>::const_iterator firstpos,
190// BCP_vec<int>::const_iterator lastpos);
191
192//#############################################################################
193
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.