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_Row_inlines_hh
00024 #define PPL_Row_inlines_hh 1
00025
00026 #include "math_utilities.defs.hh"
00027 #include "assert.hh"
00028 #include <cstddef>
00029 #include <limits>
00030 #include <algorithm>
00031
00032 namespace Parma_Polyhedra_Library {
00033
00034 inline
00035 Row::Flags::Flags()
00036 : bits(0) {
00037 }
00038
00039 inline
00040 Row::Flags::Flags(base_type n)
00041 : bits(n) {
00042 }
00043
00044 inline Row::Flags::base_type
00045 Row::Flags::get_bits() const {
00046 return bits;
00047 }
00048
00049 inline void
00050 Row::Flags::set_bits(const base_type mask) {
00051 bits |= mask;
00052 }
00053
00054 inline void
00055 Row::Flags::reset_bits(const base_type mask) {
00056 bits &= ~mask;
00057 }
00058
00059 inline bool
00060 Row::Flags::test_bits(const base_type mask) const {
00061 return (bits & mask) == mask;
00062 }
00063
00064 inline bool
00065 Row::Flags::operator==(const Flags& y) const {
00066 base_type mask = low_bits_mask<base_type>(first_free_bit);
00067 return (get_bits() & mask) == (y.get_bits() & mask);
00068 }
00069
00070 inline bool
00071 Row::Flags::operator!=(const Flags& y) const {
00072 return !operator==(y);
00073 }
00074
00075 inline void*
00076 Row_Impl_Handler::Impl::operator new(const size_t fixed_size,
00077 const dimension_type capacity) {
00078 #if PPL_CXX_SUPPORTS_FLEXIBLE_ARRAYS
00079 return ::operator new(fixed_size + capacity*sizeof(Coefficient));
00080 #else
00081 PPL_ASSERT(capacity >= 1);
00082 return ::operator new(fixed_size + (capacity-1)*sizeof(Coefficient));
00083 #endif
00084 }
00085
00086 inline void
00087 Row_Impl_Handler::Impl::operator delete(void* p) {
00088 ::operator delete(p);
00089 }
00090
00091 inline void
00092 Row_Impl_Handler::Impl::operator delete(void* p, dimension_type) {
00093 ::operator delete(p);
00094 }
00095
00096 inline dimension_type
00097 Row_Impl_Handler::Impl::max_size() {
00098 return std::numeric_limits<size_t>::max() / sizeof(Coefficient);
00099 }
00100
00101 inline dimension_type
00102 Row_Impl_Handler::Impl::size() const {
00103 return size_;
00104 }
00105
00106 inline void
00107 Row_Impl_Handler::Impl::set_size(const dimension_type new_size) {
00108 size_ = new_size;
00109 }
00110
00111 inline void
00112 Row_Impl_Handler::Impl::bump_size() {
00113 ++size_;
00114 }
00115
00116 inline
00117 Row_Impl_Handler::Impl::Impl(const Row::Flags f)
00118 : size_(0), flags_(f) {
00119 }
00120
00121 inline
00122 Row_Impl_Handler::Impl::~Impl() {
00123 shrink(0);
00124 }
00125
00126 inline const Row::Flags&
00127 Row_Impl_Handler::Impl::flags() const {
00128 return flags_;
00129 }
00130
00131 inline Row::Flags&
00132 Row_Impl_Handler::Impl::flags() {
00133 return flags_;
00134 }
00135
00136 inline Coefficient&
00137 Row_Impl_Handler::Impl::operator[](const dimension_type k) {
00138 PPL_ASSERT(k < size());
00139 return vec_[k];
00140 }
00141
00142 inline Coefficient_traits::const_reference
00143 Row_Impl_Handler::Impl::operator[](const dimension_type k) const {
00144 PPL_ASSERT(k < size());
00145 return vec_[k];
00146 }
00147
00148 inline memory_size_type
00149 Row_Impl_Handler::Impl::total_memory_in_bytes(dimension_type capacity) const {
00150 return
00151 sizeof(*this)
00152 + capacity*sizeof(Coefficient)
00153 #if !PPL_CXX_SUPPORTS_FLEXIBLE_ARRAYS
00154 - 1*sizeof(Coefficient)
00155 #endif
00156 + external_memory_in_bytes();
00157 }
00158
00159 inline memory_size_type
00160 Row_Impl_Handler::Impl::total_memory_in_bytes() const {
00161
00162
00163 return total_memory_in_bytes(size_);
00164 }
00165
00166 inline dimension_type
00167 Row::max_size() {
00168 return Impl::max_size();
00169 }
00170
00171 inline dimension_type
00172 Row::size() const {
00173 return impl->size();
00174 }
00175
00176 inline const Row::Flags&
00177 Row::flags() const {
00178 return impl->flags();
00179 }
00180
00181 inline Row::Flags&
00182 Row::flags() {
00183 return impl->flags();
00184 }
00185
00186 #if PPL_ROW_EXTRA_DEBUG
00187 inline dimension_type
00188 Row::capacity() const {
00189 return capacity_;
00190 }
00191 #endif
00192
00193 inline
00194 Row_Impl_Handler::Row_Impl_Handler()
00195 : impl(0) {
00196 #if PPL_ROW_EXTRA_DEBUG
00197 capacity_ = 0;
00198 #endif
00199 }
00200
00201 inline
00202 Row_Impl_Handler::~Row_Impl_Handler() {
00203 delete impl;
00204 }
00205
00206 inline
00207 Row::Row()
00208 : Row_Impl_Handler() {
00209 }
00210
00211 inline void
00212 Row::allocate(
00213 #if PPL_CXX_SUPPORTS_FLEXIBLE_ARRAYS
00214 const
00215 #endif
00216 dimension_type capacity,
00217 const Flags f) {
00218 PPL_ASSERT(capacity <= max_size());
00219 #if !PPL_CXX_SUPPORTS_FLEXIBLE_ARRAYS
00220 if (capacity == 0)
00221 ++capacity;
00222 #endif
00223 PPL_ASSERT(impl == 0);
00224 impl = new (capacity) Impl(f);
00225 #if PPL_ROW_EXTRA_DEBUG
00226 PPL_ASSERT(capacity_ == 0);
00227 capacity_ = capacity;
00228 #endif
00229 }
00230
00231 inline void
00232 Row::expand_within_capacity(const dimension_type new_size) {
00233 PPL_ASSERT(impl);
00234 #if PPL_ROW_EXTRA_DEBUG
00235 PPL_ASSERT(new_size <= capacity_);
00236 #endif
00237 impl->expand_within_capacity(new_size);
00238 }
00239
00240 inline void
00241 Row::copy_construct_coefficients(const Row& y) {
00242 PPL_ASSERT(impl && y.impl);
00243 #if PPL_ROW_EXTRA_DEBUG
00244 PPL_ASSERT(y.size() <= capacity_);
00245 #endif
00246 impl->copy_construct_coefficients(*(y.impl));
00247 }
00248
00249 inline void
00250 Row::construct(const dimension_type sz,
00251 const dimension_type capacity,
00252 const Flags f) {
00253 PPL_ASSERT(sz <= capacity && capacity <= max_size());
00254 allocate(capacity, f);
00255 expand_within_capacity(sz);
00256 }
00257
00258 inline void
00259 Row::construct(const dimension_type sz, const Flags f) {
00260 construct(sz, sz, f);
00261 }
00262
00263 inline
00264 Row::Row(const dimension_type sz,
00265 const dimension_type capacity,
00266 const Flags f)
00267 : Row_Impl_Handler() {
00268 construct(sz, capacity, f);
00269 }
00270
00271 inline
00272 Row::Row(const dimension_type sz, const Flags f)
00273 : Row_Impl_Handler() {
00274 construct(sz, f);
00275 }
00276
00277 inline
00278 Row::Row(const Row& y)
00279 : Row_Impl_Handler() {
00280 if (y.impl) {
00281 allocate(compute_capacity(y.size(), max_size()), y.flags());
00282 copy_construct_coefficients(y);
00283 }
00284 }
00285
00286 inline
00287 Row::Row(const Row& y,
00288 const dimension_type capacity)
00289 : Row_Impl_Handler() {
00290 PPL_ASSERT(y.impl);
00291 PPL_ASSERT(y.size() <= capacity && capacity <= max_size());
00292 allocate(capacity, y.flags());
00293 copy_construct_coefficients(y);
00294 }
00295
00296 inline
00297 Row::Row(const Row& y,
00298 const dimension_type sz,
00299 const dimension_type capacity)
00300 : Row_Impl_Handler() {
00301 PPL_ASSERT(y.impl);
00302 PPL_ASSERT(y.size() <= sz && sz <= capacity && capacity <= max_size());
00303 allocate(capacity, y.flags());
00304 copy_construct_coefficients(y);
00305 expand_within_capacity(sz);
00306 }
00307
00308 inline
00309 Row::~Row() {
00310 }
00311
00312 inline void
00313 Row::shrink(const dimension_type new_size) {
00314 PPL_ASSERT(impl);
00315 impl->shrink(new_size);
00316 }
00317
00318 inline void
00319 Row::swap(Row& y) {
00320 std::swap(impl, y.impl);
00321 #if PPL_ROW_EXTRA_DEBUG
00322 std::swap(capacity_, y.capacity_);
00323 #endif
00324 }
00325
00326 inline void
00327 Row::assign(Row& y) {
00328 impl = y.impl;
00329 #if PPL_ROW_EXTRA_DEBUG
00330 capacity_ = y.capacity_;
00331 #endif
00332 }
00333
00334 inline Row&
00335 Row::operator=(const Row& y) {
00336
00337 Row tmp(y);
00338
00339 swap(tmp);
00340
00341 return *this;
00342 }
00343
00344 inline Coefficient&
00345 Row::operator[](const dimension_type k) {
00346 PPL_ASSERT(impl);
00347 return (*impl)[k];
00348 }
00349
00350 inline Coefficient_traits::const_reference
00351 Row::operator[](const dimension_type k) const {
00352 PPL_ASSERT(impl);
00353 return (*impl)[k];
00354 }
00355
00356 inline memory_size_type
00357 Row::external_memory_in_bytes(dimension_type capacity) const {
00358 return impl->total_memory_in_bytes(capacity);
00359 }
00360
00361 inline memory_size_type
00362 Row::total_memory_in_bytes(dimension_type capacity) const {
00363 return sizeof(*this) + external_memory_in_bytes(capacity);
00364 }
00365
00366 inline memory_size_type
00367 Row::external_memory_in_bytes() const {
00368 #if PPL_ROW_EXTRA_DEBUG
00369 return impl->total_memory_in_bytes(capacity_);
00370 #else
00371 return impl->total_memory_in_bytes();
00372 #endif
00373 }
00374
00375 inline memory_size_type
00376 Row::total_memory_in_bytes() const {
00377 return sizeof(*this) + external_memory_in_bytes();
00378 }
00379
00381 inline bool
00382 operator!=(const Row& x, const Row& y) {
00383 return !(x == y);
00384 }
00385
00386 }
00387
00388
00389 namespace std {
00390
00392 inline void
00393 swap(Parma_Polyhedra_Library::Row& x, Parma_Polyhedra_Library::Row& y) {
00394 x.swap(y);
00395 }
00396
00398 inline void
00399 iter_swap(std::vector<Parma_Polyhedra_Library::Row>::iterator x,
00400 std::vector<Parma_Polyhedra_Library::Row>::iterator y) {
00401 swap(*x, *y);
00402 }
00403
00404 }
00405
00406 #endif // !defined(PPL_Row_inlines_hh)