coin-Bcp
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
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 //------------------------------------------------------------------------------
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 
void deallocate()
Destroy the entries in the vector and free the memory allocated for the vector.
void insert_aux(iterator position, const_reference x)
insert x into the given position in the vector.
iterator finish
Iterator pointing to right after the last entry in the vector.
Definition: BCP_vector.hpp:68
reference operator[](const size_t i)
Return a reference to the i-th entry.
Definition: BCP_vector.hpp:124
const int & const_reference
Definition: BCP_vector.hpp:39
iterator begin()
Return an iterator to the beginning of the object.
Definition: BCP_vector.hpp:99
void unchecked_update(const BCP_vec< int > &positions, const BCP_vec< T > &values)
Same as the previous method but without sanity checks.
void reserve(const size_t n)
Reallocate the object to make space for n entries.
void push_back(const_reference x)
Append x to the end of the vector.
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 construct(iterator pos)
void erase(iterator pos)
Erase the entry pointed to by pos.
iterator end_of_storage
Iterator pointing to right after the last memory location usable by the vector without reallocation...
Definition: BCP_vector.hpp:71
void pop_back()
Delete the last entry.
iterator start
Iterator pointing to the beginning of the memory array where the vector is stored.
Definition: BCP_vector.hpp:66
void update(const BCP_vec< int > &positions, const BCP_vec< T > &values)
Update those entries listed in positions to the given values.
void destroy_range(iterator first, iterator last)
BCP_vec()
The default constructor initializes the data members as 0 pointers.
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 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&#39;t any error handling in BCP.
Definition: BCP_error.hpp:20
size_t size() const
Return the current number of entries.
Definition: BCP_vector.hpp:116
iterator end()
Return an iterator to the end of the object.
Definition: BCP_vector.hpp:104
void unchecked_push_back(const_reference x)
Append x to the end of the vector.
void keep(iterator pos)
Keep only the entry pointed to by 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.
const int * const_iterator
Definition: BCP_vector.hpp:35
void destroy(iterator pos)