00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef PPL_DB_Row_templates_hh
00025 #define PPL_DB_Row_templates_hh 1
00026
00027 #include "globals.defs.hh"
00028
00029 namespace Parma_Polyhedra_Library {
00030
00031 template <typename T>
00032 template <typename U>
00033 void
00034 DB_Row_Impl_Handler<T>::Impl::construct_upward_approximation(const U& y) {
00035 const dimension_type y_size = y.size();
00036 #if PPL_CXX_SUPPORTS_FLEXIBLE_ARRAYS
00037
00038 for (dimension_type i = 0; i < y_size; ++i) {
00039 construct(vec_[i], y[i], ROUND_UP);
00040 bump_size();
00041 }
00042 #else // PPL_CXX_SUPPORTS_FLEXIBLE_ARRAYS
00043 if (y_size > 0) {
00044 assign_r(vec_[0], y[0], ROUND_UP);
00045 bump_size();
00046
00047 for (dimension_type i = 1; i < y_size; ++i) {
00048 construct(vec_[i], y[i], ROUND_UP);
00049 bump_size();
00050 }
00051 }
00052 #endif // PPL_CXX_SUPPORTS_FLEXIBLE_ARRAYS
00053 }
00054
00055 template <typename T>
00056 void
00057 DB_Row_Impl_Handler<T>::
00058 Impl::expand_within_capacity(const dimension_type new_size) {
00059 PPL_ASSERT(size() <= new_size && new_size <= max_size());
00060 #if !PPL_CXX_SUPPORTS_FLEXIBLE_ARRAYS
00061 if (size() == 0 && new_size > 0) {
00062
00063 assign_r(vec_[0], PLUS_INFINITY, ROUND_NOT_NEEDED);
00064 bump_size();
00065 }
00066 #endif
00067
00068 for (dimension_type i = size(); i < new_size; ++i) {
00069 new (&vec_[i]) T(PLUS_INFINITY, ROUND_NOT_NEEDED);
00070 bump_size();
00071 }
00072 }
00073
00074 template <typename T>
00075 void
00076 DB_Row_Impl_Handler<T>::Impl::shrink(dimension_type new_size) {
00077 const dimension_type old_size = size();
00078 PPL_ASSERT(new_size <= old_size);
00079
00080 set_size(new_size);
00081 #if !PPL_CXX_SUPPORTS_FLEXIBLE_ARRAYS
00082
00083 if (new_size == 0)
00084 ++new_size;
00085 #endif
00086
00087
00088 for (dimension_type i = old_size; i-- > new_size; )
00089 vec_[i].~T();
00090 }
00091
00092 template <typename T>
00093 void
00094 DB_Row_Impl_Handler<T>::Impl::copy_construct_coefficients(const Impl& y) {
00095 const dimension_type y_size = y.size();
00096 #if PPL_CXX_SUPPORTS_FLEXIBLE_ARRAYS
00097
00098 for (dimension_type i = 0; i < y_size; ++i) {
00099 new (&vec_[i]) T(y.vec_[i]);
00100 bump_size();
00101 }
00102 #else // PPL_CXX_SUPPORTS_FLEXIBLE_ARRAYS
00103 if (y_size > 0) {
00104 vec_[0] = y.vec_[0];
00105 bump_size();
00106
00107 for (dimension_type i = 1; i < y_size; ++i) {
00108 new (&vec_[i]) T(y.vec_[i]);
00109 bump_size();
00110 }
00111 }
00112 #endif // PPL_CXX_SUPPORTS_FLEXIBLE_ARRAYS
00113 }
00114
00115 template <typename T>
00116 memory_size_type
00117 DB_Row_Impl_Handler<T>::Impl::external_memory_in_bytes() const {
00118 memory_size_type n = 0;
00119 for (dimension_type i = size(); i-- > 0; )
00120 n += Parma_Polyhedra_Library::external_memory_in_bytes(vec_[i]);
00121 return n;
00122 }
00123
00124 template <typename T>
00125 bool
00126 DB_Row<T>::OK(const dimension_type row_size,
00127 const dimension_type
00128 #if PPL_DB_ROW_EXTRA_DEBUG
00129 row_capacity
00130 #endif
00131 ) const {
00132 #ifndef NDEBUG
00133 using std::endl;
00134 using std::cerr;
00135 #endif
00136
00137 const DB_Row<T>& x = *this;
00138 bool is_broken = false;
00139
00140 #if PPL_DB_ROW_EXTRA_DEBUG
00141 # if !PPL_CXX_SUPPORTS_FLEXIBLE_ARRAYS
00142 if (x.capacity_ == 0) {
00143 cerr << "Illegal row capacity: is 0, should be at least 1"
00144 << endl;
00145 is_broken = true;
00146 }
00147 else if (x.capacity_ == 1 && row_capacity == 0)
00148
00149 ;
00150 else
00151 # endif // !PPL_CXX_SUPPORTS_FLEXIBLE_ARRAYS
00152 if (x.capacity_ != row_capacity) {
00153 cerr << "DB_Row capacity mismatch: is " << x.capacity_
00154 << ", should be " << row_capacity << "."
00155 << endl;
00156 is_broken = true;
00157 }
00158 #endif // PPL_DB_ROW_EXTRA_DEBUG
00159
00160 if (x.size() != row_size) {
00161 #ifndef NDEBUG
00162 cerr << "DB_Row size mismatch: is " << x.size()
00163 << ", should be " << row_size << "."
00164 << endl;
00165 #endif
00166 is_broken = true;
00167 }
00168
00169 #if PPL_DB_ROW_EXTRA_DEBUG
00170 if (x.capacity_ < x.size()) {
00171 #ifndef NDEBUG
00172 cerr << "DB_Row is completely broken: capacity is " << x.capacity_
00173 << ", size is " << x.size() << "."
00174 << endl;
00175 #endif
00176 is_broken = true;
00177 }
00178 #endif // PPL_DB_ROW_EXTRA_DEBUG
00179
00180 for (dimension_type i = x.size(); i-- > 0; ) {
00181 const T& element = x[i];
00182
00183 if (!element.OK()) {
00184 is_broken = true;
00185 break;
00186 }
00187
00188 if (is_not_a_number(element)) {
00189 #ifndef NDEBUG
00190 cerr << "Not-a-number found in DB_Row."
00191 << endl;
00192 #endif
00193 is_broken = true;
00194 break;
00195 }
00196 }
00197
00198 return !is_broken;
00199 }
00200
00202 template <typename T>
00203 bool
00204 operator==(const DB_Row<T>& x, const DB_Row<T>& y) {
00205 if (x.size() != y.size())
00206 return false;
00207 for (dimension_type i = x.size(); i-- > 0; )
00208 if (x[i] != y[i])
00209 return false;
00210 return true;
00211 }
00212
00213 }
00214
00215 #endif // !defined(PPL_DB_Row_templates_hh)