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>
32 memory_size_type
external_memory_in_bytes() const33 OR_Matrix<T>::external_memory_in_bytes() const{
34   return vec.external_memory_in_bytes();
35 }
36 
37 template <typename T>
38 bool
OK() const39 OR_Matrix<T>::OK() const {
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
ascii_dump(std::ostream & s) const66 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) {
73     const_row_reference_type r = *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 
PPL_OUTPUT_TEMPLATE_DEFINITIONS(T,OR_Matrix<T>)83 PPL_OUTPUT_TEMPLATE_DEFINITIONS(T, OR_Matrix<T>)
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 /*! \relates Parma_Polyhedra_Library::OR_Matrix */
110 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
111 template <typename T>
112 std::ostream&
operator <<(std::ostream & s,const OR_Matrix<T> & m)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)
129