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_Interval_Info_defs_hh
00025 #define PPL_Interval_Info_defs_hh 1
00026
00027 #include "Boundary.defs.hh"
00028 #include "Interval_Restriction.defs.hh"
00029
00030 #include <iostream>
00031
00032 namespace Parma_Polyhedra_Library {
00033
00034 namespace Interval_NS {
00035
00036 struct Property {
00037 enum Type {
00038 CARDINALITY_0_,
00039 CARDINALITY_1_,
00040 CARDINALITY_IS_
00041 };
00042 typedef bool Value;
00043 static const Value default_value = true;
00044 static const Value unsupported_value = false;
00045 Property(Type t)
00046 : type(t) {
00047 }
00048 Type type;
00049 };
00050
00051 const Property CARDINALITY_0(Property::CARDINALITY_0_);
00052 const Property CARDINALITY_1(Property::CARDINALITY_1_);
00053 const Property CARDINALITY_IS(Property::CARDINALITY_IS_);
00054
00055 template <typename T>
00056 inline void
00057 reset_bits(T& bits) {
00058 bits = 0;
00059 }
00060
00061 template <typename T>
00062 inline void
00063 reset_bit(T& bits, unsigned int bit) {
00064 bits &= ~(static_cast<T>(1) << bit);
00065 }
00066
00067 template <typename T>
00068 inline void
00069 set_bit(T& bits, unsigned int bit, bool value) {
00070 if (value)
00071 bits |= static_cast<T>(1) << bit;
00072 else
00073 reset_bit(bits, bit);
00074 }
00075
00076 template <typename T>
00077 inline bool
00078 get_bit(const T& bits, unsigned int bit) {
00079 return bits & (static_cast<T>(1) << bit);
00080 }
00081
00082 template <typename T>
00083 inline void
00084 set_bits(T& bits, unsigned int start, unsigned int len, T value) {
00085 bits &= ~(((static_cast<T>(1) << len) - 1) << start);
00086 bits |= value << start;
00087 }
00088
00089 template <typename T>
00090 inline T
00091 get_bits(T& bits, unsigned int start, unsigned int len) {
00092 return (bits >> start) & ((static_cast<T>(1) << len) - 1);
00093 }
00094
00095 }
00096
00097 using namespace Interval_NS;
00098 using namespace Boundary_NS;
00099
00100
00101 template <typename Policy>
00102 class Interval_Info_Null {
00103 public:
00104 const_bool_nodef(may_be_empty, Policy::may_be_empty);
00105 const_bool_nodef(may_contain_infinity, Policy::may_contain_infinity);
00106 const_bool_nodef(check_inexact, Policy::check_inexact);
00107 const_bool_nodef(store_special, false);
00108 const_bool_nodef(store_open, false);
00109 const_bool_nodef(cache_normalized, false);
00110 const_bool_nodef(cache_empty, false);
00111 const_bool_nodef(cache_singleton, false);
00112 void clear() {
00113 }
00114 void clear_boundary_properties(Boundary_Type) {
00115 }
00116
00117 template <typename Property>
00118 void set_boundary_property(Boundary_Type, const Property&, typename Property::Value = Property::default_value) {
00119 }
00120 template <typename Property>
00121 typename Property::Value get_boundary_property(Boundary_Type, const Property&) const {
00122 return Property::unsupported_value;
00123 }
00124 template <typename Property>
00125 void set_interval_property(const Property&, typename Property::Value = Property::default_value) {
00126 }
00127 template <typename Property>
00128 typename Property::Value get_interval_property(const Property&) const {
00129 return Property::unsupported_value;
00130 }
00131
00133 void swap(Interval_Info_Null& y);
00134
00135 void ascii_dump(std::ostream& s) const;
00136 bool ascii_load(std::istream& s);
00137 };
00138
00139 template <typename Policy>
00140 class Interval_Info_Null_Open : public Interval_Info_Null<Policy> {
00141 public:
00142 const_bool_nodef(store_open, true);
00143 Interval_Info_Null_Open(bool o)
00144 : open(o) {
00145 }
00146 bool get_boundary_property(Boundary_Type, const Boundary_NS::Property& p) const {
00147 switch (p.type) {
00148 case Boundary_NS::Property::OPEN_:
00149 return open;
00150 default:
00151 return Boundary_NS::Property::unsupported_value;
00152 }
00153 }
00154
00155 void ascii_dump(std::ostream& s) const;
00156 bool ascii_load(std::istream& s);
00157
00158 private:
00159 bool open;
00160 };
00161
00162
00163 template <typename T, typename Policy>
00164 class Interval_Info_Bitset {
00165 public:
00166 const_bool_nodef(may_be_empty, Policy::may_be_empty);
00167 const_bool_nodef(may_contain_infinity, Policy::may_contain_infinity);
00168 const_bool_nodef(check_inexact, Policy::check_inexact);
00169 const_bool_nodef(store_special, Policy::store_special);
00170 const_bool_nodef(store_open, Policy::store_open);
00171 const_bool_nodef(cache_normalized, Policy::cache_normalized);
00172 const_bool_nodef(cache_empty, Policy::cache_empty);
00173 const_bool_nodef(cache_singleton, Policy::cache_singleton);
00174 const_int_nodef(lower_special_bit, Policy::next_bit);
00175 const_int_nodef(lower_open_bit, lower_special_bit + store_special);
00176 const_int_nodef(lower_normalized_bit, lower_open_bit + store_open);
00177 const_int_nodef(upper_special_bit, lower_normalized_bit + cache_normalized);
00178 const_int_nodef(upper_open_bit, upper_special_bit + store_special);
00179 const_int_nodef(upper_normalized_bit, upper_open_bit + store_open);
00180 const_int_nodef(cardinality_is_bit, upper_normalized_bit + cache_normalized);
00181 const_int_nodef(cardinality_0_bit, cardinality_is_bit + (cache_empty || cache_singleton));
00182 const_int_nodef(cardinality_1_bit, cardinality_0_bit + cache_empty);
00183 const_int_nodef(next_bit, cardinality_1_bit + cache_singleton);
00184 Interval_Info_Bitset() {
00185
00186
00187 clear();
00188 }
00189
00190 void clear() {
00191 reset_bits(bitset);
00192 }
00193 void clear_boundary_properties(Boundary_Type t) {
00194 set_boundary_property(t, SPECIAL, false);
00195 set_boundary_property(t, OPEN, false);
00196 }
00197 void set_boundary_property(Boundary_Type t, const Boundary_NS::Property& p, bool value = true) {
00198 switch (p.type) {
00199 case Boundary_NS::Property::SPECIAL_:
00200 if (store_special) {
00201 if (t == LOWER)
00202 set_bit(bitset, lower_special_bit, value);
00203 else
00204 set_bit(bitset, upper_special_bit, value);
00205 }
00206 break;
00207 case Boundary_NS::Property::OPEN_:
00208 if (store_open) {
00209 if (t == LOWER)
00210 set_bit(bitset, lower_open_bit, value);
00211 else
00212 set_bit(bitset, upper_open_bit, value);
00213 }
00214 break;
00215 case Boundary_NS::Property::NORMALIZED_:
00216 if (cache_normalized) {
00217 if (t == LOWER)
00218 set_bit(bitset, lower_normalized_bit, value);
00219 else
00220 set_bit(bitset, upper_normalized_bit, value);
00221 }
00222 break;
00223 default:
00224 break;
00225 }
00226 }
00227 bool get_boundary_property(Boundary_Type t, const Boundary_NS::Property& p) const {
00228 switch (p.type) {
00229 case Boundary_NS::Property::SPECIAL_:
00230 if (!store_special)
00231 return false;
00232 if (t == LOWER)
00233 return get_bit(bitset, lower_special_bit);
00234 else
00235 return get_bit(bitset, upper_special_bit);
00236 case Boundary_NS::Property::OPEN_:
00237 if (!store_open)
00238 return false;
00239 else if (t == LOWER)
00240 return get_bit(bitset, lower_open_bit);
00241 else
00242 return get_bit(bitset, upper_open_bit);
00243 case Boundary_NS::Property::NORMALIZED_:
00244 if (!cache_normalized)
00245 return false;
00246 else if (t == LOWER)
00247 return get_bit(bitset, lower_normalized_bit);
00248 else
00249 return get_bit(bitset, upper_normalized_bit);
00250 default:
00251 return false;
00252 }
00253 }
00254 void set_interval_property(const Interval_NS::Property& p, bool value = true) {
00255 switch (p.type) {
00256 case Interval_NS::Property::CARDINALITY_0_:
00257 if (cache_empty)
00258 set_bit(bitset, cardinality_0_bit, value);
00259 break;
00260 case Interval_NS::Property::CARDINALITY_1_:
00261 if (cache_singleton)
00262 set_bit(bitset, cardinality_1_bit, value);
00263 break;
00264 case Interval_NS::Property::CARDINALITY_IS_:
00265 if (cache_empty || cache_singleton)
00266 set_bit(bitset, cardinality_is_bit, value);
00267 break;
00268 default:
00269 break;
00270 }
00271 }
00272 bool get_interval_property(Interval_NS::Property p) const {
00273 switch (p.type) {
00274 case Interval_NS::Property::CARDINALITY_0_:
00275 return cache_empty && get_bit(bitset, cardinality_0_bit);
00276 case Interval_NS::Property::CARDINALITY_1_:
00277 return cache_singleton && get_bit(bitset, cardinality_1_bit);
00278 case Interval_NS::Property::CARDINALITY_IS_:
00279 return (cache_empty || cache_singleton)
00280 && get_bit(bitset, cardinality_is_bit);
00281 default:
00282 return false;
00283 }
00284 }
00285
00287 void swap(Interval_Info_Bitset& y);
00288
00289 void ascii_dump(std::ostream& s) const;
00290 bool ascii_load(std::istream& s);
00291
00292 protected:
00293 T bitset;
00294 };
00295
00296 }
00297
00298 #include "Interval_Info.inlines.hh"
00299
00300 #endif // !defined(PPL_Interval_Info_defs_hh)