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