#include <DB_Row.defs.hh>
Public Types | |
typedef Implementation::Ptr_Iterator < T * > | iterator |
A (non const) random access iterator to access the row's elements. | |
typedef Implementation::Ptr_Iterator < const T * > | const_iterator |
A const random access iterator to access the row's elements. | |
Public Member Functions | |
DB_Row () | |
Pre-constructs a row: construction must be completed by construct(). | |
DB_Row (dimension_type sz) | |
Tight constructor: resizing will require reallocation. | |
DB_Row (dimension_type sz, dimension_type capacity) | |
Sizing constructor with capacity. | |
DB_Row (const DB_Row &y) | |
Ordinary copy constructor. | |
DB_Row (const DB_Row &y, dimension_type capacity) | |
Copy constructor with specified capacity. | |
DB_Row (const DB_Row &y, dimension_type sz, dimension_type capacity) | |
Copy constructor with specified size and capacity. | |
~DB_Row () | |
Destructor. | |
DB_Row & | operator= (const DB_Row &y) |
Assignment operator. | |
void | swap (DB_Row &y) |
Swaps *this with y . | |
void | assign (DB_Row &y) |
Assigns the implementation of y to *this . | |
void | allocate (dimension_type capacity) |
Allocates memory for a default constructed DB_Row object, allowing for capacity coefficients at most. | |
void | expand_within_capacity (dimension_type new_size) |
Expands the row to size new_size . | |
void | shrink (dimension_type new_size) |
Shrinks the row by erasing elements at the end. | |
dimension_type | size () const |
Gives the number of coefficients currently in use. | |
iterator | begin () |
Returns the const iterator pointing to the first element, if *this is not empty; otherwise, returns the past-the-end const iterator. | |
iterator | end () |
Returns the past-the-end iterator. | |
const_iterator | begin () const |
Returns the const iterator pointing to the first element, if *this is not empty; otherwise, returns the past-the-end const iterator. | |
const_iterator | end () const |
Returns the past-the-end const iterator. | |
bool | OK (dimension_type row_size, dimension_type row_capacity) const |
Checks if all the invariants are satisfied. | |
Post-constructors. | |
void | construct (dimension_type sz) |
Constructs properly a default-constructed element. | |
void | construct (dimension_type sz, dimension_type capacity) |
Constructs properly a default-constructed element. | |
template<typename U> | |
void | construct_upward_approximation (const DB_Row< U > &y, dimension_type capacity) |
Constructs properly a conservative approximation of y . | |
Subscript operators. | |
T & | operator[] (dimension_type k) |
Returns a reference to the element of the row indexed by k . | |
const T & | operator[] (dimension_type k) const |
Returns a constant reference to the element of the row indexed by k . | |
Static Public Member Functions | |
static dimension_type | max_size () |
Returns the size() of the largest possible DB_Row. | |
Private Member Functions | |
void | copy_construct_coefficients (const DB_Row &y) |
Exception-safe copy construction mechanism for coefficients. | |
Friends | |
class | Parma_Polyhedra_Library::DB_Row |
Related Functions | |
(Note that these are not member functions.) | |
template<typename T> | |
void | swap (Parma_Polyhedra_Library::DB_Row< T > &x, Parma_Polyhedra_Library::DB_Row< T > &y) |
Specializes std::swap . | |
template<typename T> | |
void | iter_swap (typename std::vector< Parma_Polyhedra_Library::DB_Row< T > >::iterator x, typename std::vector< Parma_Polyhedra_Library::DB_Row< T > >::iterator y) |
Specializes std::iter_swap . | |
Classical comparison operators. | |
template<typename T> | |
bool | operator== (const DB_Row< T > &x, const DB_Row< T > &y) |
template<typename T> | |
bool | operator!= (const DB_Row< T > &x, const DB_Row< T > &y) |
The class template DB_Row<T> allows for the efficient representation of the single rows of a DB_Matrix. It contains elements of type T stored as a vector. The class T is a family of extended numbers that must provide representation for ,
,
(and, consequently for nan, not a number, since this arises as the ``result'' of undefined sums like
).
The class T must provide the following methods:
T()
T().OK()
gives true
(see below). ~T()
bool is_nan() const
true
if and only *this
represents the not a number value. bool OK() const
true
if and only if *this
satisfies all its invariants.
Definition at line 115 of file DB_Row.defs.hh.
typedef Implementation::Ptr_Iterator<T*> Parma_Polyhedra_Library::DB_Row< T >::iterator |
A (non const) random access iterator to access the row's elements.
Definition at line 239 of file DB_Row.defs.hh.
typedef Implementation::Ptr_Iterator<const T*> Parma_Polyhedra_Library::DB_Row< T >::const_iterator |
A const random access iterator to access the row's elements.
Definition at line 242 of file DB_Row.defs.hh.
Parma_Polyhedra_Library::DB_Row< T >::DB_Row | ( | ) | [inline] |
Pre-constructs a row: construction must be completed by construct().
Definition at line 169 of file DB_Row.inlines.hh.
Parma_Polyhedra_Library::DB_Row< T >::DB_Row | ( | dimension_type | sz | ) | [inline] |
Tight constructor: resizing will require reallocation.
Definition at line 253 of file DB_Row.inlines.hh.
References Parma_Polyhedra_Library::DB_Row< T >::construct().
00253 { 00254 construct(sz); 00255 }
Parma_Polyhedra_Library::DB_Row< T >::DB_Row | ( | dimension_type | sz, | |
dimension_type | capacity | |||
) | [inline] |
Sizing constructor with capacity.
Definition at line 245 of file DB_Row.inlines.hh.
References Parma_Polyhedra_Library::DB_Row< T >::construct().
00247 : DB_Row_Impl_Handler<T>() { 00248 construct(sz, capacity); 00249 }
Parma_Polyhedra_Library::DB_Row< T >::DB_Row | ( | const DB_Row< T > & | y | ) | [inline] |
Ordinary copy constructor.
Definition at line 259 of file DB_Row.inlines.hh.
References Parma_Polyhedra_Library::DB_Row< T >::allocate(), Parma_Polyhedra_Library::compute_capacity(), Parma_Polyhedra_Library::DB_Row< T >::copy_construct_coefficients(), Parma_Polyhedra_Library::DB_Row_Impl_Handler< T >::impl, Parma_Polyhedra_Library::DB_Row< T >::max_size(), and Parma_Polyhedra_Library::DB_Row< T >::size().
00260 : DB_Row_Impl_Handler<T>() { 00261 if (y.impl) { 00262 allocate(compute_capacity(y.size(), max_size())); 00263 copy_construct_coefficients(y); 00264 } 00265 }
Parma_Polyhedra_Library::DB_Row< T >::DB_Row | ( | const DB_Row< T > & | y, | |
dimension_type | capacity | |||
) | [inline] |
Copy constructor with specified capacity.
It is assumed that capacity
is greater than or equal to y
size.
Definition at line 269 of file DB_Row.inlines.hh.
References Parma_Polyhedra_Library::DB_Row< T >::allocate(), Parma_Polyhedra_Library::DB_Row< T >::copy_construct_coefficients(), Parma_Polyhedra_Library::DB_Row_Impl_Handler< T >::impl, Parma_Polyhedra_Library::DB_Row< T >::max_size(), and Parma_Polyhedra_Library::DB_Row< T >::size().
00271 : DB_Row_Impl_Handler<T>() { 00272 assert(y.impl); 00273 assert(y.size() <= capacity && capacity <= max_size()); 00274 allocate(capacity); 00275 copy_construct_coefficients(y); 00276 }
Parma_Polyhedra_Library::DB_Row< T >::DB_Row | ( | const DB_Row< T > & | y, | |
dimension_type | sz, | |||
dimension_type | capacity | |||
) | [inline] |
Copy constructor with specified size and capacity.
It is assumed that sz
is greater than or equal to the size of y
and, of course, that sz
is less than or equal to capacity
. Any new position is initialized to .
Definition at line 280 of file DB_Row.inlines.hh.
References Parma_Polyhedra_Library::DB_Row< T >::allocate(), Parma_Polyhedra_Library::DB_Row< T >::copy_construct_coefficients(), Parma_Polyhedra_Library::DB_Row< T >::expand_within_capacity(), Parma_Polyhedra_Library::DB_Row_Impl_Handler< T >::impl, Parma_Polyhedra_Library::DB_Row< T >::max_size(), and Parma_Polyhedra_Library::DB_Row< T >::size().
00283 : DB_Row_Impl_Handler<T>() { 00284 assert(y.impl); 00285 assert(y.size() <= sz && sz <= capacity && capacity <= max_size()); 00286 allocate(capacity); 00287 copy_construct_coefficients(y); 00288 expand_within_capacity(sz); 00289 }
Parma_Polyhedra_Library::DB_Row< T >::~DB_Row | ( | ) | [inline] |
void Parma_Polyhedra_Library::DB_Row< T >::construct | ( | dimension_type | sz | ) | [inline] |
Constructs properly a default-constructed element.
Builds a row with size sz
and minimum capacity.
Definition at line 239 of file DB_Row.inlines.hh.
Referenced by Parma_Polyhedra_Library::DB_Row< T >::DB_Row().
00239 { 00240 construct(sz, sz); 00241 }
void Parma_Polyhedra_Library::DB_Row< T >::construct | ( | dimension_type | sz, | |
dimension_type | capacity | |||
) | [inline] |
Constructs properly a default-constructed element.
sz | The size of the row that will be constructed. | |
capacity | The minimum capacity of the row that will be constructed. |
elements
, sz
of which will be constructed now.
Definition at line 230 of file DB_Row.inlines.hh.
References Parma_Polyhedra_Library::DB_Row< T >::allocate(), Parma_Polyhedra_Library::DB_Row< T >::expand_within_capacity(), and Parma_Polyhedra_Library::DB_Row< T >::max_size().
00231 { 00232 assert(sz <= capacity && capacity <= max_size()); 00233 allocate(capacity); 00234 expand_within_capacity(sz); 00235 }
void Parma_Polyhedra_Library::DB_Row< T >::construct_upward_approximation | ( | const DB_Row< U > & | y, | |
dimension_type | capacity | |||
) | [inline] |
Constructs properly a conservative approximation of y
.
y | A row containing the elements whose upward approximations will be used to properly construct *this . | |
capacity | The capacity of the constructed row. |
capacity
is greater than or equal to the size of y
.
Definition at line 219 of file DB_Row.inlines.hh.
References Parma_Polyhedra_Library::DB_Row< T >::allocate(), Parma_Polyhedra_Library::DB_Row_Impl_Handler< T >::Impl::construct_upward_approximation(), Parma_Polyhedra_Library::DB_Row_Impl_Handler< T >::impl, Parma_Polyhedra_Library::DB_Row< T >::max_size(), and Parma_Polyhedra_Library::DB_Row< T >::size().
00220 { 00221 DB_Row<T>& x = *this; 00222 assert(y.size() <= capacity && capacity <= max_size()); 00223 allocate(capacity); 00224 assert(y.impl); 00225 x.impl->construct_upward_approximation(*(y.impl)); 00226 }
DB_Row< T > & Parma_Polyhedra_Library::DB_Row< T >::operator= | ( | const DB_Row< T > & | y | ) | [inline] |
Assignment operator.
Definition at line 326 of file DB_Row.inlines.hh.
References Parma_Polyhedra_Library::DB_Row< T >::swap().
00326 { 00327 // Copy-construct `tmp' from `y'. 00328 DB_Row tmp(y); 00329 // Swap the implementation of `*this' with the one of `tmp'. 00330 swap(tmp); 00331 // Now `tmp' goes out of scope, so the old `*this' will be destroyed. 00332 return *this; 00333 }
void Parma_Polyhedra_Library::DB_Row< T >::swap | ( | DB_Row< T > & | y | ) | [inline] |
Swaps *this
with y
.
Definition at line 306 of file DB_Row.inlines.hh.
References Parma_Polyhedra_Library::DB_Row_Impl_Handler< T >::impl.
Referenced by Parma_Polyhedra_Library::DB_Row< T >::iter_swap(), Parma_Polyhedra_Library::DB_Row< T >::operator=(), and Parma_Polyhedra_Library::DB_Row< T >::swap().
00306 { 00307 DB_Row<T>& x = *this; 00308 std::swap(x.impl, y.impl); 00309 #if EXTRA_ROW_DEBUG 00310 std::swap(x.capacity_, y.capacity_); 00311 #endif 00312 }
void Parma_Polyhedra_Library::DB_Row< T >::assign | ( | DB_Row< T > & | y | ) | [inline] |
Assigns the implementation of y
to *this
.
Definition at line 316 of file DB_Row.inlines.hh.
References Parma_Polyhedra_Library::DB_Row_Impl_Handler< T >::impl.
00316 { 00317 DB_Row<T>& x = *this; 00318 x.impl = y.impl; 00319 #if EXTRA_ROW_DEBUG 00320 x.capacity_ = y.capacity_; 00321 #endif 00322 }
void Parma_Polyhedra_Library::DB_Row< T >::allocate | ( | dimension_type | capacity | ) | [inline] |
Allocates memory for a default constructed DB_Row object, allowing for capacity
coefficients at most.
It is assumed that no allocation has been performed before (otherwise, a memory leak will occur). After execution, the size of the DB_Row object is zero.
Definition at line 175 of file DB_Row.inlines.hh.
References Parma_Polyhedra_Library::DB_Row_Impl_Handler< T >::impl, and Parma_Polyhedra_Library::DB_Row< T >::max_size().
Referenced by Parma_Polyhedra_Library::DB_Row< T >::construct(), Parma_Polyhedra_Library::DB_Row< T >::construct_upward_approximation(), and Parma_Polyhedra_Library::DB_Row< T >::DB_Row().
00179 { 00180 DB_Row<T>& x = *this; 00181 assert(capacity <= max_size()); 00182 #if !CXX_SUPPORTS_FLEXIBLE_ARRAYS 00183 if (capacity == 0) 00184 ++capacity; 00185 #endif 00186 assert(x.impl == 0); 00187 x.impl = new (capacity) typename DB_Row_Impl_Handler<T>::Impl(); 00188 #if EXTRA_ROW_DEBUG 00189 assert(x.capacity_ == 0); 00190 x.capacity_ = capacity; 00191 #endif 00192 }
void Parma_Polyhedra_Library::DB_Row< T >::expand_within_capacity | ( | dimension_type | new_size | ) | [inline] |
Expands the row to size new_size
.
Adds new positions to the implementation of the row obtaining a new row with size new_size
. It is assumed that new_size
is between the current size and capacity of the row. The new positions are initialized to .
Definition at line 196 of file DB_Row.inlines.hh.
References Parma_Polyhedra_Library::DB_Row_Impl_Handler< T >::Impl::expand_within_capacity(), and Parma_Polyhedra_Library::DB_Row_Impl_Handler< T >::impl.
Referenced by Parma_Polyhedra_Library::DB_Row< T >::construct(), and Parma_Polyhedra_Library::DB_Row< T >::DB_Row().
00196 { 00197 DB_Row<T>& x = *this; 00198 assert(x.impl); 00199 #if EXTRA_ROW_DEBUG 00200 assert(new_size <= x.capacity_); 00201 #endif 00202 x.impl->expand_within_capacity(new_size); 00203 }
void Parma_Polyhedra_Library::DB_Row< T >::shrink | ( | dimension_type | new_size | ) | [inline] |
Shrinks the row by erasing elements at the end.
Destroys elements of the row implementation from position new_size
to the end. It is assumed that new_size
is not greater than the current size.
Definition at line 298 of file DB_Row.inlines.hh.
References Parma_Polyhedra_Library::DB_Row_Impl_Handler< T >::impl, and Parma_Polyhedra_Library::DB_Row_Impl_Handler< T >::Impl::shrink().
dimension_type Parma_Polyhedra_Library::DB_Row< T >::max_size | ( | ) | [inline, static] |
Returns the size() of the largest possible DB_Row.
Definition at line 149 of file DB_Row.inlines.hh.
Referenced by Parma_Polyhedra_Library::DB_Row< T >::allocate(), Parma_Polyhedra_Library::DB_Row< T >::construct(), Parma_Polyhedra_Library::DB_Row< T >::construct_upward_approximation(), and Parma_Polyhedra_Library::DB_Row< T >::DB_Row().
dimension_type Parma_Polyhedra_Library::DB_Row< T >::size | ( | ) | const [inline] |
Gives the number of coefficients currently in use.
Definition at line 155 of file DB_Row.inlines.hh.
References Parma_Polyhedra_Library::DB_Row_Impl_Handler< T >::impl, and Parma_Polyhedra_Library::DB_Row_Impl_Handler< T >::Impl::size().
Referenced by Parma_Polyhedra_Library::DB_Row< T >::construct_upward_approximation(), Parma_Polyhedra_Library::DB_Row< T >::copy_construct_coefficients(), Parma_Polyhedra_Library::DB_Row< T >::DB_Row(), Parma_Polyhedra_Library::DB_Row< T >::OK(), and Parma_Polyhedra_Library::DB_Row< T >::operator==().
T & Parma_Polyhedra_Library::DB_Row< T >::operator[] | ( | dimension_type | k | ) | [inline] |
Returns a reference to the element of the row indexed by k
.
Definition at line 337 of file DB_Row.inlines.hh.
References Parma_Polyhedra_Library::DB_Row_Impl_Handler< T >::impl.
const T & Parma_Polyhedra_Library::DB_Row< T >::operator[] | ( | dimension_type | k | ) | const [inline] |
Returns a constant reference to the element of the row indexed by k
.
Definition at line 344 of file DB_Row.inlines.hh.
References Parma_Polyhedra_Library::DB_Row_Impl_Handler< T >::impl.
DB_Row< T >::iterator Parma_Polyhedra_Library::DB_Row< T >::begin | ( | ) | [inline] |
Returns the const iterator pointing to the first element, if *this
is not empty; otherwise, returns the past-the-end const iterator.
Definition at line 410 of file DB_Row.inlines.hh.
References Parma_Polyhedra_Library::DB_Row_Impl_Handler< T >::impl, and Parma_Polyhedra_Library::DB_Row_Impl_Handler< T >::Impl::vec_.
00410 { 00411 DB_Row<T>& x = *this; 00412 return iterator(x.impl->vec_); 00413 }
DB_Row< T >::iterator Parma_Polyhedra_Library::DB_Row< T >::end | ( | ) | [inline] |
Returns the past-the-end iterator.
Definition at line 417 of file DB_Row.inlines.hh.
References Parma_Polyhedra_Library::DB_Row_Impl_Handler< T >::impl, Parma_Polyhedra_Library::DB_Row_Impl_Handler< T >::Impl::size_, and Parma_Polyhedra_Library::DB_Row_Impl_Handler< T >::Impl::vec_.
00417 { 00418 DB_Row<T>& x = *this; 00419 return iterator(x.impl->vec_ + x.impl->size_); 00420 }
DB_Row< T >::const_iterator Parma_Polyhedra_Library::DB_Row< T >::begin | ( | ) | const [inline] |
Returns the const iterator pointing to the first element, if *this
is not empty; otherwise, returns the past-the-end const iterator.
Definition at line 424 of file DB_Row.inlines.hh.
References Parma_Polyhedra_Library::DB_Row_Impl_Handler< T >::impl, and Parma_Polyhedra_Library::DB_Row_Impl_Handler< T >::Impl::vec_.
00424 { 00425 const DB_Row<T>& x = *this; 00426 return const_iterator(x.impl->vec_); 00427 }
DB_Row< T >::const_iterator Parma_Polyhedra_Library::DB_Row< T >::end | ( | ) | const [inline] |
Returns the past-the-end const iterator.
Definition at line 431 of file DB_Row.inlines.hh.
References Parma_Polyhedra_Library::DB_Row_Impl_Handler< T >::impl, Parma_Polyhedra_Library::DB_Row_Impl_Handler< T >::Impl::size_, and Parma_Polyhedra_Library::DB_Row_Impl_Handler< T >::Impl::vec_.
00431 { 00432 const DB_Row<T>& x = *this; 00433 return const_iterator(x.impl->vec_ + x.impl->size_); 00434 }
bool Parma_Polyhedra_Library::DB_Row< T >::OK | ( | dimension_type | row_size, | |
dimension_type | row_capacity | |||
) | const [inline] |
Checks if all the invariants are satisfied.
Definition at line 438 of file DB_Row.inlines.hh.
References Parma_Polyhedra_Library::is_not_a_number(), and Parma_Polyhedra_Library::DB_Row< T >::size().
00443 { 00444 #ifndef NDEBUG 00445 using std::endl; 00446 using std::cerr; 00447 #endif 00448 00449 const DB_Row<T>& x = *this; 00450 00451 bool is_broken = false; 00452 #if EXTRA_ROW_DEBUG 00453 # if !CXX_SUPPORTS_FLEXIBLE_ARRAYS 00454 if (x.capacity_ == 0) { 00455 cerr << "Illegal row capacity: is 0, should be at least 1" 00456 << endl; 00457 is_broken = true; 00458 } 00459 else if (x.capacity_ == 1 && row_capacity == 0) 00460 // This is fine. 00461 ; 00462 else 00463 # endif 00464 if (x.capacity_ != row_capacity) { 00465 cerr << "DB_Row capacity mismatch: is " << x.capacity_ 00466 << ", should be " << row_capacity << "." 00467 << endl; 00468 is_broken = true; 00469 } 00470 #endif 00471 if (x.size() != row_size) { 00472 #ifndef NDEBUG 00473 cerr << "DB_Row size mismatch: is " << x.size() 00474 << ", should be " << row_size << "." 00475 << endl; 00476 #endif 00477 is_broken = true; 00478 } 00479 #if EXTRA_ROW_DEBUG 00480 if (x.capacity_ < x.size()) { 00481 #ifndef NDEBUG 00482 cerr << "DB_Row is completely broken: capacity is " << x.capacity_ 00483 << ", size is " << x.size() << "." 00484 << endl; 00485 #endif 00486 is_broken = true; 00487 } 00488 #endif 00489 00490 for (dimension_type i = x.size(); i-- > 0; ) { 00491 const T& element = x[i]; 00492 // Not OK is bad. 00493 if (!element.OK()) { 00494 is_broken = true; 00495 break; 00496 } 00497 // In addition, nans should never occur. 00498 if (is_not_a_number(element)) { 00499 #ifndef NDEBUG 00500 cerr << "Not-a-number found in DB_Row." 00501 << endl; 00502 #endif 00503 is_broken = true; 00504 break; 00505 } 00506 } 00507 00508 return !is_broken; 00509 }
void Parma_Polyhedra_Library::DB_Row< T >::copy_construct_coefficients | ( | const DB_Row< T > & | y | ) | [inline, private] |
Exception-safe copy construction mechanism for coefficients.
Definition at line 207 of file DB_Row.inlines.hh.
References Parma_Polyhedra_Library::DB_Row_Impl_Handler< T >::Impl::copy_construct_coefficients(), Parma_Polyhedra_Library::DB_Row_Impl_Handler< T >::impl, and Parma_Polyhedra_Library::DB_Row< T >::size().
Referenced by Parma_Polyhedra_Library::DB_Row< T >::DB_Row().
00207 { 00208 DB_Row<T>& x = *this; 00209 assert(x.impl && y.impl); 00210 #if EXTRA_ROW_DEBUG 00211 assert(y.size() <= x.capacity_); 00212 #endif 00213 x.impl->copy_construct_coefficients(*(y.impl)); 00214 }
friend class Parma_Polyhedra_Library::DB_Row [friend] |
Definition at line 268 of file DB_Row.defs.hh.
Definition at line 515 of file DB_Row.inlines.hh.
References Parma_Polyhedra_Library::DB_Row< T >::size().
00515 { 00516 if (x.size() != y.size()) 00517 return false; 00518 for (dimension_type i = x.size(); i-- > 0; ) 00519 if (x[i] != y[i]) 00520 return false; 00521 return true; 00522 }
void swap | ( | Parma_Polyhedra_Library::DB_Row< T > & | x, | |
Parma_Polyhedra_Library::DB_Row< T > & | y | |||
) | [related] |
Specializes std::swap
.
Definition at line 539 of file DB_Row.inlines.hh.
References Parma_Polyhedra_Library::DB_Row< T >::swap().
00540 { 00541 x.swap(y); 00542 }
void iter_swap | ( | typename std::vector< Parma_Polyhedra_Library::DB_Row< T > >::iterator | x, | |
typename std::vector< Parma_Polyhedra_Library::DB_Row< T > >::iterator | y | |||
) | [related] |
Specializes std::iter_swap
.
Definition at line 547 of file DB_Row.inlines.hh.
References Parma_Polyhedra_Library::DB_Row< T >::swap().
00550 { 00551 swap(*x, *y); 00552 }