PPL  1.2
OR_Matrix_defs.hh
Go to the documentation of this file.
1 /* OR_Matrix class declaration.
2  Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it>
3  Copyright (C) 2010-2016 BUGSENG srl (http://bugseng.com)
4 
5 This file is part of the Parma Polyhedra Library (PPL).
6 
7 The PPL is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 The PPL is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
20 
21 For the most up-to-date information see the Parma Polyhedra Library
22 site: http://bugseng.com/products/ppl/ . */
23 
24 #ifndef PPL_OR_Matrix_defs_hh
25 #define PPL_OR_Matrix_defs_hh 1
26 
27 #include "OR_Matrix_types.hh"
28 #include "globals_defs.hh"
29 #include "DB_Row_defs.hh"
30 #include "Checked_Number_defs.hh"
31 #include <cstddef>
32 #include <iosfwd>
33 
34 #ifndef PPL_OR_MATRIX_EXTRA_DEBUG
35 #ifdef PPL_ABI_BREAKING_EXTRA_DEBUG
36 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
37 
43 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
44 #define PPL_OR_MATRIX_EXTRA_DEBUG 1
45 #else // !defined(PPL_ABI_BREAKING_EXTRA_DEBUG)
46 #define PPL_OR_MATRIX_EXTRA_DEBUG 0
47 #endif // !defined(PPL_ABI_BREAKING_EXTRA_DEBUG)
48 #endif // !defined(PPL_OR_MATRIX_EXTRA_DEBUG)
49 
50 namespace Parma_Polyhedra_Library {
51 
52 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
53 
55 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
56 template <typename T>
57 bool operator==(const OR_Matrix<T>& x, const OR_Matrix<T>& y);
58 
59 namespace IO_Operators {
60 
61 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
62 
64 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
65 template <typename T>
66 std::ostream&
67 operator<<(std::ostream& s, const OR_Matrix<T>& m);
68 
69 } // namespace IO_Operators
70 
71 } // namespace Parma_Polyhedra_Library
72 
73 
74 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
75 
102 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
103 
104 template <typename T>
106 private:
111  template <typename U>
112  class Pseudo_Row {
113  public:
119  template <typename V>
120  Pseudo_Row(const Pseudo_Row<V>& y);
121 
123  ~Pseudo_Row();
124 
126  U& operator[](dimension_type k) const;
127 
129  Pseudo_Row();
130 
132  Pseudo_Row& operator=(const Pseudo_Row& y);
133 
134 #if !defined(__GNUC__) || __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 0)
135  private:
136 #else
137  // Work around a bug of GCC 4.0.x (and, likely, previous versions).
138  public:
139 #endif
140 
141 #if PPL_OR_MATRIX_EXTRA_DEBUG
142 
144  Pseudo_Row(U& y, dimension_type s);
145 
146 #else // !PPL_OR_MATRIX_EXTRA_DEBUG
147 
149  explicit Pseudo_Row(U& y);
150 
151 #endif // !PPL_OR_MATRIX_EXTRA_DEBUG
152 
154  U* first;
155 
156 #if !defined(__GNUC__) || __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 0)
157 #else
158  // Work around a bug of GCC 4.0.x (and, likely, previous versions).
159  private:
160 #endif
161 
162 #if PPL_OR_MATRIX_EXTRA_DEBUG
163 
165  dimension_type size_;
166 
168  dimension_type size() const;
169 
170 #endif // PPL_OR_MATRIX_EXTRA_DEBUG
171 
172  // FIXME: the EDG-based compilers (such as Comeau and Intel)
173  // are here in wild disagreement with GCC: what is a legal friend
174  // declaration for one, is illegal for the others.
175 #ifdef __EDG__
176  template <typename V> template<typename W>
177  friend class OR_Matrix<V>::Pseudo_Row;
178  template <typename V> template<typename W>
179  friend class OR_Matrix<V>::any_row_iterator;
180 #else
181  template <typename V> friend class Pseudo_Row;
182  template <typename V> friend class any_row_iterator;
183 #endif
184 
185  friend class OR_Matrix;
186  }; // class Pseudo_Row
187 
188 public:
191 
194 
195 private:
200  template <typename U>
202  public:
203  typedef std::random_access_iterator_tag iterator_category;
205  typedef long difference_type;
206  typedef const Pseudo_Row<U>* pointer;
207  typedef const Pseudo_Row<U>& reference;
208 
211 
216  explicit any_row_iterator(U& base);
217 
222  template <typename V>
224 
229  template <typename V>
231 
233  reference operator*() const;
234 
236  pointer operator->() const;
237 
239  any_row_iterator& operator++();
240 
242  any_row_iterator operator++(int);
243 
245  any_row_iterator& operator--();
246 
248  any_row_iterator operator--(int);
249 
251  reference operator[](difference_type m) const;
252 
254  any_row_iterator& operator+=(difference_type m);
255 
257  template <typename Unsigned>
259  operator+=(Unsigned m);
260 
262  any_row_iterator& operator-=(difference_type m);
263 
266 
269 
271  template <typename Unsigned>
272  typename Enable_If<(static_cast<Unsigned>(-1) > 0), any_row_iterator>::type
273  operator+(Unsigned m) const;
274 
277 
279  bool operator==(const any_row_iterator& y) const;
280 
285  bool operator!=(const any_row_iterator& y) const;
286 
288  bool operator<(const any_row_iterator& y) const;
289 
294  bool operator<=(const any_row_iterator& y) const;
295 
297  bool operator>(const any_row_iterator& y) const;
298 
303  bool operator>=(const any_row_iterator& y) const;
304 
305  dimension_type row_size() const;
306 
307  dimension_type index() const;
308 
309  private:
312 
315 
318 
319  // FIXME: the EDG-based compilers (such as Comeau and Intel)
320  // are here in wild disagreement with GCC: what is a legal friend
321  // declaration for one, is illegal for the others.
322 #ifdef __EDG__
323  template <typename V> template<typename W>
324  friend class OR_Matrix<V>::any_row_iterator;
325 #else
326  template <typename V> friend class any_row_iterator;
327 #endif
328  }; // class any_row_iterator
329 
330 public:
333 
336 
338  typedef typename DB_Row<T>::iterator element_iterator;
339 
341  typedef typename DB_Row<T>::const_iterator const_element_iterator;
342 
343 public:
345  static dimension_type max_num_rows();
346 
348 
355  OR_Matrix(dimension_type num_dimensions);
356 
358  OR_Matrix(const OR_Matrix& y);
359 
361  template <typename U>
362  explicit OR_Matrix(const OR_Matrix<U>& y);
363 
365  ~OR_Matrix();
366 
368  OR_Matrix& operator=(const OR_Matrix& y);
369 
370 private:
371  template <typename U> friend class OR_Matrix;
372 
374 
382 
385 
388 
390  OR_Matrix();
391 
396  static dimension_type row_first_element_index(dimension_type k);
397 
398 public:
400  static dimension_type row_size(dimension_type k);
401 
403  void m_swap(OR_Matrix& y);
404 
406 
417  void grow(dimension_type new_dim);
418 
420 
427  void shrink(dimension_type new_dim);
428 
430 
441  void resize_no_copy(dimension_type new_dim);
442 
445 
448 
450 
451  row_reference_type operator[](dimension_type k);
453 
455  const_row_reference_type operator[](dimension_type k) const;
457 
458 
465 
468 
475 
478 
485 
488 
495 
498 
500  void clear();
501 
503 
509  bool ascii_load(std::istream& s);
510 
513 
516 
517  friend bool operator==<T>(const OR_Matrix<T>& x, const OR_Matrix<T>& y);
518 
520  bool OK() const;
521 };
522 
523 namespace Parma_Polyhedra_Library {
524 
525 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
526 
528 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
529 template <typename T>
530 void swap(OR_Matrix<T>& x, OR_Matrix<T>& y);
531 
532 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
533 
535 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
536 template <typename T>
537 bool operator!=(const OR_Matrix<T>& x, const OR_Matrix<T>& y);
538 
539 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
540 
551 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
552 template <typename Temp, typename To, typename T>
554  const OR_Matrix<T>& x,
555  const OR_Matrix<T>& y,
556  Rounding_Dir dir,
557  Temp& tmp0,
558  Temp& tmp1,
559  Temp& tmp2);
560 
561 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
562 
573 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
574 template <typename Temp, typename To, typename T>
576  const OR_Matrix<T>& x,
577  const OR_Matrix<T>& y,
578  Rounding_Dir dir,
579  Temp& tmp0,
580  Temp& tmp1,
581  Temp& tmp2);
582 
583 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
584 
595 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
596 template <typename Temp, typename To, typename T>
598  const OR_Matrix<T>& x,
599  const OR_Matrix<T>& y,
600  Rounding_Dir dir,
601  Temp& tmp0,
602  Temp& tmp1,
603  Temp& tmp2);
604 
605 } // namespace Parma_Polyhedra_Library
606 
607 #include "OR_Matrix_inlines.hh"
608 #include "OR_Matrix_templates.hh"
609 
610 #endif // !defined(PPL_OR_Matrix_defs_hh)
void swap(OR_Matrix< T > &x, OR_Matrix< T > &y)
Swaps x with y.
friend bool operator==(const OR_Matrix< T > &x, const OR_Matrix< T > &y)
memory_size_type external_memory_in_bytes() const
Returns the size in bytes of the memory managed by *this.
Enable_If< Is_Singleton< T >::value, Interval< B, Info > >::type operator*(const Interval< B, Info > &x, const T &y)
bool operator!=(const OR_Matrix< T > &x, const OR_Matrix< T > &y)
Returns true if and only if x and y are different.
dimension_type num_rows() const
Returns the number of rows in the matrix.
bool operator>(const Ptr_Iterator< P > &x, const Ptr_Iterator< Q > &y)
row_iterator row_end()
Returns the past-the-end const_iterator.
void shrink(dimension_type new_dim)
Makes the matrix shrink by removing the last space dimensions.
size_t dimension_type
An unsigned integral type for representing space dimensions.
Pseudo_Row< const Parma_Polyhedra_Library::Checked_Number > const_row_reference_type
A const reference to a matrix's row.
Pseudo_Row()
Default constructor: creates an invalid object that has to be assigned.
any_row_iterator< Parma_Polyhedra_Library::Checked_Number > row_iterator
A (non const) row iterator.
Rounding_Dir
Rounding directions for arithmetic computations.
DB_Row< Parma_Polyhedra_Library::Checked_Number >::const_iterator const_element_iterator
A const element iterator.
bool operator>=(const Ptr_Iterator< P > &x, const Ptr_Iterator< Q > &y)
A template class to derive both OR_Matrix::iterator and OR_Matrix::const_iterator.
memory_size_type total_memory_in_bytes() const
Returns the total size in bytes of the memory occupied by *this.
U & operator[](dimension_type k) const
Subscript operator.
dimension_type space_dimension() const
Returns the space-dimension of the matrix.
bool euclidean_distance_assign(Checked_Number< To, Extended_Number_Policy > &r, const OR_Matrix< T > &x, const OR_Matrix< T > &y, Rounding_Dir dir, Temp &tmp0, Temp &tmp1, Temp &tmp2)
Computes the euclidean distance between x and y.
void resize_no_copy(dimension_type new_dim)
Resizes the matrix without worrying about the old contents.
bool OK() const
Checks if all the invariants are satisfied.
void m_swap(OR_Matrix &y)
Swaps *this with y.
An object that behaves like a matrix's row with respect to the subscript operators.
dimension_type i
Internal index: i = (e+1)*(e+1)/2.
U * first
Holds a reference to the beginning of this row.
The base class for the single rows of matrices.
Definition: DB_Row_defs.hh:120
A wrapper for numeric types implementing a given policy.
#define PPL_OUTPUT_DECLARATIONS
bool ascii_load(std::istream &s)
Loads from s an ASCII representation (as produced by ascii_dump(std::ostream&) const) and sets *this ...
element_iterator element_begin()
Returns an iterator pointing to the first element, if *this is not empty; otherwise, returns the past-the-end const_iterator.
bool l_infinity_distance_assign(Checked_Number< To, Extended_Number_Policy > &r, const OR_Matrix< T > &x, const OR_Matrix< T > &y, Rounding_Dir dir, Temp &tmp0, Temp &tmp1, Temp &tmp2)
Computes the distance between x and y.
static dimension_type row_first_element_index(dimension_type k)
Returns the index into vec of the first element of the row of index k.
Pseudo_Row & operator=(const Pseudo_Row &y)
Assignment operator.
any_row_iterator< const Parma_Polyhedra_Library::Checked_Number > const_row_iterator
A const row iterator.
bool operator<(const Ptr_Iterator< P > &x, const Ptr_Iterator< Q > &y)
static dimension_type row_size(dimension_type k)
Returns the size of the row of index k.
void grow(dimension_type new_dim)
Makes the matrix grow by adding more space dimensions.
Pseudo_Row< U > value
Represents the beginning of a row.
DB_Row< T > vec
Contains the rows of the matrix.
dimension_type space_dim
Contains the dimension of the space of the matrix.
The entire library is confined to this namespace.
Definition: version.hh:61
Enable_If< Is_Singleton< T >::value, Interval< B, Info > >::type operator+(const Interval< B, Info > &x, const T &y)
static dimension_type max_num_rows()
Returns the maximum number of rows of a OR_Matrix.
dimension_type vec_capacity
Contains the capacity of vec.
bool rectilinear_distance_assign(Checked_Number< To, Extended_Number_Policy > &r, const OR_Matrix< T > &x, const OR_Matrix< T > &y, Rounding_Dir dir, Temp &tmp0, Temp &tmp1, Temp &tmp2)
Computes the rectilinear (or Manhattan) distance between x and y.
bool operator<=(const Ptr_Iterator< P > &x, const Ptr_Iterator< Q > &y)
DB_Row< Parma_Polyhedra_Library::Checked_Number >::iterator element_iterator
A (non const) element iterator.
Pseudo_Row< Parma_Polyhedra_Library::Checked_Number > row_reference_type
A (non const) reference to a matrix's row.
A matrix representing octagonal constraints.
bool operator==(const Box< ITV > &x, const Box< ITV > &y)
Enable_If< Is_Singleton< T >::value, Interval< B, Info > >::type operator-(const Interval< B, Info > &x, const T &y)
size_t memory_size_type
An unsigned integral type for representing memory size in bytes.
void clear()
Clears the matrix deallocating all its rows.
A class that provides a type member called type equivalent to T if and only if b is true...
row_iterator row_begin()
Returns an iterator pointing to the first row, if *this is not empty; otherwise, returns the past-the...
element_iterator element_end()
Returns the past-the-end const_iterator.