PPL  1.2
OR_Matrix_templates.hh
Go to the documentation of this file.
1 /* OR_Matrix class implementation: non-inline template functions.
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_templates_hh
25 #define PPL_OR_Matrix_templates_hh 1
26 
27 #include <iostream>
28 
29 namespace Parma_Polyhedra_Library {
30 
31 template <typename T>
34  return vec.external_memory_in_bytes();
35 }
36 
37 template <typename T>
38 bool
40 #ifndef NDEBUG
41  using std::endl;
42  using std::cerr;
43 #endif
44  // The right number of cells should be in use.
45  const dimension_type dim = space_dimension();
46  if (vec.size() != 2*dim*(dim + 1)) {
47 #ifndef NDEBUG
48  cerr << "OR_Matrix has a wrong number of cells:\n"
49  << "vec.size() is " << vec.size()
50  << ", expected size is " << (2*dim*(dim+1)) << "!\n";
51 #endif
52  return false;
53  }
54 
55  // The underlying DB_Row should be OK.
56  if (!vec.OK(vec.size(), vec_capacity)) {
57  return false;
58  }
59 
60  // All checks passed.
61  return true;
62 }
63 
64 template <typename T>
65 void
66 OR_Matrix<T>::ascii_dump(std::ostream& s) const {
67  const OR_Matrix<T>& x = *this;
68  const char separator = ' ';
69  dimension_type space = x.space_dimension();
70  s << space << separator << "\n";
71  for (const_row_iterator i = x.row_begin(),
72  x_row_end = x.row_end(); i != x_row_end; ++i) {
74  dimension_type rs = i.row_size();
75  for (dimension_type j = 0; j < rs; ++j) {
76  using namespace IO_Operators;
77  s << r[j] << separator;
78  }
79  s << "\n";
80  }
81 }
82 
84 
85 template <typename T>
86 bool
87 OR_Matrix<T>::ascii_load(std::istream& s) {
88  dimension_type space;
89  if (!(s >> space)) {
90  return false;
91  }
92  resize_no_copy(space);
93  for (row_iterator i = row_begin(),
94  this_row_end = row_end(); i != this_row_end; ++i) {
95  row_reference_type r_i = *i;
96  const dimension_type rs = i.row_size();
97  for (dimension_type j = 0; j < rs; ++j) {
98  Result r = input(r_i[j], s, ROUND_CHECK);
99  if (result_relation(r) != VR_EQ || is_minus_infinity(r_i[j])) {
100  return false;
101  }
102  }
103  }
104  PPL_ASSERT(OK());
105  return true;
106 }
107 
108 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
109 
110 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
111 template <typename T>
112 std::ostream&
113 IO_Operators::operator<<(std::ostream& s, const OR_Matrix<T>& m) {
114  for (typename OR_Matrix<T>::const_row_iterator m_iter = m.row_begin(),
115  m_end = m.row_end(); m_iter != m_end; ++m_iter) {
116  typename OR_Matrix<T>::const_row_reference_type r_m = *m_iter;
117  const dimension_type mr_size = m_iter.row_size();
118  for (dimension_type j = 0; j < mr_size; ++j) {
119  s << r_m[j] << " ";
120  }
121  s << "\n";
122  }
123  return s;
124 }
125 
126 } // namespace Parma_Polyhedra_Library
127 
128 #endif // !defined(PPL_OR_Matrix_templates_hh)
memory_size_type external_memory_in_bytes() const
Returns the size in bytes of the memory managed by *this.
Enable_If< Is_Native_Or_Checked< T >::value, bool >::type is_minus_infinity(const T &x)
row_iterator row_end()
Returns the past-the-end const_iterator.
size_t dimension_type
An unsigned integral type for representing space dimensions.
Result
Possible outcomes of a checked arithmetic computation.
Definition: Result_defs.hh:76
A template class to derive both OR_Matrix::iterator and OR_Matrix::const_iterator.
The standard C++ namespace.
#define PPL_OUTPUT_TEMPLATE_DEFINITIONS(type_symbol, class_prefix)
dimension_type space_dimension() const
Returns the space-dimension of the matrix.
Result_Relation result_relation(Result r)
bool OK() const
Checks if all the invariants are satisfied.
An object that behaves like a matrix's row with respect to the subscript operators.
Equal. This need to be accompanied by a value.
Definition: Result_defs.hh:51
Enable_If< Is_Native_Or_Checked< T >::value, bool >::type ascii_load(std::istream &s, T &t)
The entire library is confined to this namespace.
Definition: version.hh:61
void ascii_dump() const
Writes to std::cerr an ASCII representation of *this.
A matrix representing octagonal constraints.
size_t memory_size_type
An unsigned integral type for representing memory size in bytes.
row_iterator row_begin()
Returns an iterator pointing to the first row, if *this is not empty; otherwise, returns the past-the...