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