PPL  1.2
Parma_Polyhedra_Library::Swapping_Vector< T > Class Template Reference

#include <Swapping_Vector_defs.hh>

Inheritance diagram for Parma_Polyhedra_Library::Swapping_Vector< T >:

Public Types

typedef std::vector< T >::const_iterator const_iterator
 
typedef std::vector< T >::iterator iterator
 
typedef std::vector< T >::size_type size_type
 

Public Member Functions

 Swapping_Vector ()
 
 Swapping_Vector (dimension_type new_size)
 
 Swapping_Vector (dimension_type new_size, const T &x)
 
void clear ()
 
void reserve (dimension_type new_capacity)
 
void resize (dimension_type new_size)
 
void resize (dimension_type new_size, const T &x)
 
dimension_type size () const
 
dimension_type capacity () const
 
bool empty () const
 
void m_swap (Swapping_Vector &v)
 
T & operator[] (dimension_type i)
 
const T & operator[] (dimension_type i) const
 
T & back ()
 
const T & back () const
 
void push_back (const T &x)
 
void pop_back ()
 
iterator begin ()
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 
iterator erase (iterator itr)
 
iterator erase (iterator first, iterator last)
 
memory_size_type external_memory_in_bytes () const
 
dimension_type max_num_rows ()
 

Private Attributes

std::vector< T > impl
 

Related Functions

(Note that these are not member functions.)

template<typename T >
void swap (Swapping_Vector< T > &x, Swapping_Vector< T > &y)
 

Detailed Description

template<typename T>
class Parma_Polyhedra_Library::Swapping_Vector< T >

A wrapper for std::vector that calls a swap() method instead of copying elements, when possible.

Definition at line 38 of file Swapping_Vector_defs.hh.

Member Typedef Documentation

template<typename T>
typedef std::vector<T>::const_iterator Parma_Polyhedra_Library::Swapping_Vector< T >::const_iterator

Definition at line 41 of file Swapping_Vector_defs.hh.

template<typename T>
typedef std::vector<T>::iterator Parma_Polyhedra_Library::Swapping_Vector< T >::iterator

Definition at line 42 of file Swapping_Vector_defs.hh.

template<typename T>
typedef std::vector<T>::size_type Parma_Polyhedra_Library::Swapping_Vector< T >::size_type

Definition at line 43 of file Swapping_Vector_defs.hh.

Constructor & Destructor Documentation

template<typename T >
Parma_Polyhedra_Library::Swapping_Vector< T >::Swapping_Vector ( )
inline

Definition at line 33 of file Swapping_Vector_inlines.hh.

34  : impl() {
35 }
template<typename T >
Parma_Polyhedra_Library::Swapping_Vector< T >::Swapping_Vector ( dimension_type  new_size)
inlineexplicit

Definition at line 39 of file Swapping_Vector_inlines.hh.

References Parma_Polyhedra_Library::Swapping_Vector< T >::resize().

40  : impl() {
41  // NOTE: This is not the same as constructing impl as `impl(i)', because
42  // this implementation calls compute_capacity().
43  resize(i);
44 }
template<typename T>
Parma_Polyhedra_Library::Swapping_Vector< T >::Swapping_Vector ( dimension_type  new_size,
const T &  x 
)
inline

Definition at line 48 of file Swapping_Vector_inlines.hh.

References Parma_Polyhedra_Library::Swapping_Vector< T >::resize().

49  : impl() {
50  resize(new_size, x);
51 }

Member Function Documentation

template<typename T >
T & Parma_Polyhedra_Library::Swapping_Vector< T >::back ( )
inline

Definition at line 134 of file Swapping_Vector_inlines.hh.

Referenced by Parma_Polyhedra_Library::Linear_System< Row >::merge_rows_assign().

134  {
135  return impl.back();
136 }
template<typename T >
const T & Parma_Polyhedra_Library::Swapping_Vector< T >::back ( ) const
inline

Definition at line 140 of file Swapping_Vector_inlines.hh.

140  {
141  return impl.back();
142 }
template<typename T >
Swapping_Vector< T >::iterator Parma_Polyhedra_Library::Swapping_Vector< T >::begin ( )
inline

Definition at line 170 of file Swapping_Vector_inlines.hh.

170  {
171  return impl.begin();
172 }
template<typename T >
Swapping_Vector< T >::const_iterator Parma_Polyhedra_Library::Swapping_Vector< T >::begin ( ) const
inline

Definition at line 182 of file Swapping_Vector_inlines.hh.

182  {
183  return impl.begin();
184 }
template<typename T >
dimension_type Parma_Polyhedra_Library::Swapping_Vector< T >::capacity ( ) const
inline

Definition at line 103 of file Swapping_Vector_inlines.hh.

103  {
104  return impl.capacity();
105 }
template<typename T >
void Parma_Polyhedra_Library::Swapping_Vector< T >::clear ( )
inline

Definition at line 55 of file Swapping_Vector_inlines.hh.

55  {
56  impl.clear();
57 }
template<typename T >
bool Parma_Polyhedra_Library::Swapping_Vector< T >::empty ( ) const
inline

Definition at line 109 of file Swapping_Vector_inlines.hh.

109  {
110  return impl.empty();
111 }
template<typename T >
Swapping_Vector< T >::iterator Parma_Polyhedra_Library::Swapping_Vector< T >::end ( )
inline

Definition at line 176 of file Swapping_Vector_inlines.hh.

176  {
177  return impl.end();
178 }
template<typename T >
Swapping_Vector< T >::const_iterator Parma_Polyhedra_Library::Swapping_Vector< T >::end ( ) const
inline

Definition at line 188 of file Swapping_Vector_inlines.hh.

188  {
189  return impl.end();
190 }
template<typename T >
Swapping_Vector< T >::iterator Parma_Polyhedra_Library::Swapping_Vector< T >::erase ( iterator  itr)
inline

Definition at line 194 of file Swapping_Vector_inlines.hh.

References Parma_Polyhedra_Library::swap().

194  {
195  PPL_ASSERT(itr >= begin());
196  PPL_ASSERT(itr < end());
197  const dimension_type old_i = itr - begin();
198  dimension_type i = old_i;
199  ++i;
200  while (i != size()) {
201  swap(impl[i-1], impl[i]);
202  }
203  impl.pop_back();
204  return begin() + old_i;
205 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
void swap(Swapping_Vector< T > &x, Swapping_Vector< T > &y)
template<typename T >
Swapping_Vector< T >::iterator Parma_Polyhedra_Library::Swapping_Vector< T >::erase ( iterator  first,
iterator  last 
)
inline

Definition at line 209 of file Swapping_Vector_inlines.hh.

References Parma_Polyhedra_Library::swap().

209  {
210  PPL_ASSERT(begin() <= first);
211  PPL_ASSERT(first <= last);
212  PPL_ASSERT(last <= end());
213  const iterator old_first = first;
214  typedef typename std::iterator_traits<iterator>::difference_type diff_t;
215  const diff_t k = last - first;
216  const dimension_type n = static_cast<dimension_type>(end() - last);
217  using std::swap;
218  for (dimension_type i = 0; i < n; ++i, ++first) {
219  swap(*first, *(first + k));
220  }
221  impl.erase(end() - k, end());
222  return old_first;
223 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
void swap(Swapping_Vector< T > &x, Swapping_Vector< T > &y)
void swap(Swapping_Vector< T > &vec1, Swapping_Vector< T > &vec2)
template<typename T >
memory_size_type Parma_Polyhedra_Library::Swapping_Vector< T >::external_memory_in_bytes ( ) const
inline

Definition at line 159 of file Swapping_Vector_inlines.hh.

159  {
160  // Estimate the size of vector.
161  memory_size_type n = impl.capacity() * sizeof(T);
162  for (const_iterator i = begin(), i_end = end(); i != i_end; ++i) {
163  n += i->external_memory_in_bytes();
164  }
165  return n;
166 }
std::vector< T >::const_iterator const_iterator
size_t memory_size_type
An unsigned integral type for representing memory size in bytes.
template<typename T >
void Parma_Polyhedra_Library::Swapping_Vector< T >::m_swap ( Swapping_Vector< T > &  v)
inline

Definition at line 115 of file Swapping_Vector_inlines.hh.

References Parma_Polyhedra_Library::Swapping_Vector< T >::impl, and Parma_Polyhedra_Library::swap().

Referenced by Parma_Polyhedra_Library::swap().

115  {
116  using std::swap;
117  swap(impl, v.impl);
118 }
void swap(Swapping_Vector< T > &x, Swapping_Vector< T > &y)
void swap(Swapping_Vector< T > &vec1, Swapping_Vector< T > &vec2)
template<typename T >
dimension_type Parma_Polyhedra_Library::Swapping_Vector< T >::max_num_rows ( )
inline

Definition at line 227 of file Swapping_Vector_inlines.hh.

Referenced by Parma_Polyhedra_Library::Linear_System< Row >::merge_rows_assign().

227  {
228  return impl.max_size();
229 }
template<typename T >
T & Parma_Polyhedra_Library::Swapping_Vector< T >::operator[] ( dimension_type  i)
inline

Definition at line 122 of file Swapping_Vector_inlines.hh.

122  {
123  return impl[i];
124 }
template<typename T >
const T & Parma_Polyhedra_Library::Swapping_Vector< T >::operator[] ( dimension_type  i) const
inline

Definition at line 128 of file Swapping_Vector_inlines.hh.

128  {
129  return impl[i];
130 }
template<typename T >
void Parma_Polyhedra_Library::Swapping_Vector< T >::pop_back ( )
inline

Definition at line 153 of file Swapping_Vector_inlines.hh.

153  {
154  impl.pop_back();
155 }
template<typename T>
void Parma_Polyhedra_Library::Swapping_Vector< T >::push_back ( const T &  x)
inline

Definition at line 146 of file Swapping_Vector_inlines.hh.

146  {
147  reserve(size() + 1);
148  impl.push_back(x);
149 }
void reserve(dimension_type new_capacity)
template<typename T >
void Parma_Polyhedra_Library::Swapping_Vector< T >::reserve ( dimension_type  new_capacity)
inline

Definition at line 61 of file Swapping_Vector_inlines.hh.

References Parma_Polyhedra_Library::compute_capacity(), and Parma_Polyhedra_Library::swap().

Referenced by Parma_Polyhedra_Library::Linear_System< Row >::merge_rows_assign().

61  {
62  if (impl.capacity() < new_capacity) {
63  // Reallocation will take place.
64  std::vector<T> new_impl;
65 
66  new_impl.reserve(compute_capacity(new_capacity, max_num_rows()));
67  new_impl.resize(impl.size());
68 
69  using std::swap;
70 
71  // Steal the old elements.
72  for (dimension_type i = impl.size(); i-- > 0; ) {
73  swap(new_impl[i], impl[i]);
74  }
75 
76  // Put the new vector into place.
77  swap(impl, new_impl);
78  }
79 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
void swap(Swapping_Vector< T > &x, Swapping_Vector< T > &y)
dimension_type compute_capacity(dimension_type requested_size, dimension_type maximum_size)
Speculative allocation function.
void swap(Swapping_Vector< T > &vec1, Swapping_Vector< T > &vec2)
template<typename T>
void Parma_Polyhedra_Library::Swapping_Vector< T >::resize ( dimension_type  new_size,
const T &  x 
)
inline

Definition at line 90 of file Swapping_Vector_inlines.hh.

90  {
91  reserve(new_size);
92  impl.resize(new_size, x);
93 }
void reserve(dimension_type new_capacity)

Friends And Related Function Documentation

template<typename T >
void swap ( Swapping_Vector< T > &  x,
Swapping_Vector< T > &  y 
)
related

Definition at line 233 of file Swapping_Vector_inlines.hh.

233  {
234  vec1.m_swap(vec2);
235 }

Member Data Documentation

template<typename T>
std::vector<T> Parma_Polyhedra_Library::Swapping_Vector< T >::impl
private

The documentation for this class was generated from the following files: