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_globals_defs_hh
00025 #define PPL_globals_defs_hh 1
00026
00027 #include "globals.types.hh"
00028 #include "C_Integer.hh"
00029 #include "meta_programming.hh"
00030 #include "Slow_Copy.hh"
00031 #include "Temp.defs.hh"
00032 #include <exception>
00033 #include <gmpxx.h>
00034
00035 namespace Parma_Polyhedra_Library {
00036
00038 dimension_type
00039 not_a_dimension();
00040
00041 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00042
00048 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00049 template <typename T>
00050 inline typename Enable_If<Slow_Copy<T>::value, void>::type
00051 swap(T&, T&) {
00052 PPL_COMPILE_TIME_CHECK(!Slow_Copy<T>::value, "missing swap specialization");
00053 }
00054
00062 #define PPL_DIRTY_TEMP_COEFFICIENT(id) PPL_DIRTY_TEMP0(Coefficient, id)
00063
00064 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00065
00066
00083 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00084 dimension_type
00085 compute_capacity(dimension_type requested_size,
00086 dimension_type maximum_size);
00087
00088
00089 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00090
00091
00096 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00097 struct Weightwatch_Traits {
00099 typedef unsigned long long Threshold;
00100
00102 typedef unsigned long long Delta;
00103
00105 static const Threshold& get();
00106
00108 static bool less_than(const Threshold& a, const Threshold& b);
00109
00111 static void from_delta(Threshold& threshold, const Delta& delta);
00112
00114 static Threshold weight;
00115
00122 static void (*check_function)(void);
00123 };
00124
00125
00126 #ifndef NDEBUG
00127 namespace Implementation {
00128
00130 extern unsigned int in_assert;
00131
00132 }
00133 #endif
00134
00135 #ifndef PPL_PROFILE_ADD_WEIGHT
00136 #define PPL_PROFILE_ADD_WEIGHT 0
00137 #endif
00138
00139 #if defined(NDEBUG)
00140 #if PPL_PROFILE_ADD_WEIGHT
00141 #define WEIGHT_BEGIN() Weight_Profiler::begin()
00142 #define WEIGHT_ADD(delta) \
00143 do { \
00144 static Weight_Profiler wp__(__FILE__, __LINE__, delta); \
00145 wp__.end(); \
00146 } while(0)
00147 #define WEIGHT_ADD_MUL(delta, factor) \
00148 do { \
00149 static Weight_Profiler wp__(__FILE__, __LINE__, delta); \
00150 wp__.end(factor); \
00151 } while(0)
00152 #else
00153 #define WEIGHT_BEGIN()
00154 #define WEIGHT_ADD(delta) \
00155 do { \
00156 Weightwatch_Traits::weight += delta; \
00157 } while(0)
00158 #define WEIGHT_ADD_MUL(delta, factor) \
00159 do { \
00160 Weightwatch_Traits::weight += delta * factor; \
00161 } while(0)
00162 #endif
00163 #else
00164 #define WEIGHT_BEGIN()
00165 #define WEIGHT_ADD(delta) \
00166 do { \
00167 if (!Implementation::in_assert) \
00168 Weightwatch_Traits::weight += delta; \
00169 } while(0)
00170 #define WEIGHT_ADD_MUL(delta, factor) \
00171 do { \
00172 if (!Implementation::in_assert) \
00173 Weightwatch_Traits::weight += delta * factor; \
00174 } while(0)
00175 #endif
00176
00178
00183 class Throwable {
00184 public:
00186 virtual void throw_me() const = 0;
00187
00189 virtual ~Throwable();
00190 };
00191
00215 extern const Throwable* volatile abandon_expensive_computations;
00216
00217 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00218
00224 #endif
00225 void
00226 maybe_abandon();
00227
00229
00233 struct Recycle_Input {
00234 };
00235
00236
00237 #define PPL_STR(s) #s
00238
00239 #define PPL_XSTR(s) PPL_STR(s)
00240
00241 #define PPL_OUTPUT_DECLARATIONS \
00242 \
00243 void ascii_dump() const; \
00244 \
00245 void ascii_dump(std::ostream& s) const; \
00246 \
00247 void print() const;
00248
00249 #define PPL_OUTPUT_DEFINITIONS(class_name) \
00250 void \
00251 Parma_Polyhedra_Library::class_name::ascii_dump() const { \
00252 ascii_dump(std::cerr); \
00253 } \
00254 \
00255 void \
00256 Parma_Polyhedra_Library::class_name::print() const { \
00257 using IO_Operators::operator<<; \
00258 std::cerr << *this; \
00259 }
00260
00261 #define PPL_OUTPUT_DEFINITIONS_ASCII_ONLY(class_name) \
00262 void \
00263 Parma_Polyhedra_Library::class_name::ascii_dump() const { \
00264 ascii_dump(std::cerr); \
00265 } \
00266 \
00267 void \
00268 Parma_Polyhedra_Library::class_name::print() const { \
00269 std::cerr << "No user level output operator defined " \
00270 << "for class " PPL_XSTR(class_name) << "." << std::endl; \
00271 }
00272
00273 #define PPL_OUTPUT_TEMPLATE_DEFINITIONS(type_symbol, class_prefix) \
00274 template <typename type_symbol> \
00275 void \
00276 class_prefix::ascii_dump() const { \
00277 ascii_dump(std::cerr); \
00278 } \
00279 \
00280 template <typename type_symbol> \
00281 void \
00282 class_prefix::print() const { \
00283 using IO_Operators::operator<<; \
00284 std::cerr << *this; \
00285 }
00286
00287 #define PPL_OUTPUT_2_PARAM_TEMPLATE_DEFINITIONS(type_symbol1, \
00288 type_symbol2, \
00289 class_prefix) \
00290 template <typename type_symbol1, typename type_symbol2> \
00291 void \
00292 class_prefix<type_symbol1, type_symbol2>::ascii_dump() const { \
00293 ascii_dump(std::cerr); \
00294 } \
00295 \
00296 template <typename type_symbol1, typename type_symbol2> \
00297 void \
00298 class_prefix<type_symbol1, type_symbol2>::print() const { \
00299 using IO_Operators::operator<<; \
00300 std::cerr << *this; \
00301 }
00302
00303 #define PPL_OUTPUT_3_PARAM_TEMPLATE_DEFINITIONS(type_symbol1, \
00304 type_symbol2, \
00305 type_symbol3, \
00306 class_prefix) \
00307 template <typename type_symbol1, typename type_symbol2, \
00308 typename type_symbol3> \
00309 void \
00310 class_prefix<type_symbol1, type_symbol2, type_symbol3>::ascii_dump() \
00311 const { \
00312 ascii_dump(std::cerr); \
00313 } \
00314 \
00315 template <typename type_symbol1, typename type_symbol2, \
00316 typename type_symbol3> \
00317 void \
00318 class_prefix<type_symbol1, type_symbol2, type_symbol3>::print() \
00319 const { \
00320 using IO_Operators::operator<<; \
00321 std::cerr << *this; \
00322 }
00323
00324 #define PPL_OUTPUT_TEMPLATE_DEFINITIONS_ASCII_ONLY(type_symbol, class_prefix) \
00325 template <typename type_symbol> \
00326 void \
00327 class_prefix::ascii_dump() const { \
00328 ascii_dump(std::cerr); \
00329 } \
00330 \
00331 template <typename type_symbol> \
00332 void \
00333 class_prefix::print() const { \
00334 std::cerr << "No user level output operator defined " \
00335 << "for " PPL_XSTR(class_prefix) << "." << std::endl; \
00336 }
00337
00338 template <typename T, long long v, typename Enable = void>
00339 struct Fit : public False {
00340 };
00341
00342 template <typename T, long long v>
00343 struct Fit<T, v, typename Enable_If<C_Integer<T>::value>::type> {
00344 enum {
00345 value = (v >= static_cast<long long>(C_Integer<T>::min)
00346 && v <= static_cast<long long>(C_Integer<T>::max))
00347 };
00348 };
00349
00350 template <typename T, long long v>
00351 struct TConstant {
00352 static const T value = v;
00353 };
00354
00355
00356 template <typename T, long long v>
00357 const T TConstant<T, v>::value;
00358
00359 template <typename T, long long v, bool prefer_signed = true,
00360 typename Enable = void>
00361 struct Constant_ : public TConstant<T, v> {
00362 };
00363
00364 template <typename T, long long v, bool prefer_signed>
00365 struct Constant_<T, v, prefer_signed,
00366 typename Enable_If<(Fit<typename C_Integer<T>::smaller_signed_type, v>::value
00367 && (prefer_signed
00368 || !Fit<typename C_Integer<T>::smaller_unsigned_type, v>::value))>::type>
00369 : public Constant_<typename C_Integer<T>::smaller_signed_type, v, prefer_signed> {
00370 };
00371
00372 template <typename T, long long v, bool prefer_signed>
00373 struct Constant_<T, v, prefer_signed,
00374 typename Enable_If<(Fit<typename C_Integer<T>::smaller_unsigned_type, v>::value
00375 && (!prefer_signed
00376 || !Fit<typename C_Integer<T>::smaller_signed_type, v>::value))>::type>
00377 : public Constant_<typename C_Integer<T>::smaller_unsigned_type, v, prefer_signed> {
00378 };
00379
00380 template <long long v, bool prefer_signed = true>
00381 struct Constant : public Constant_<long long, v, prefer_signed> {
00382 };
00383
00385
00386
00387 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00388
00392 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00393 template <typename T>
00394 typename Enable_If<Is_Native<T>::value, memory_size_type>::type
00395 total_memory_in_bytes(const T&);
00396
00397 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00398
00402 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00403 template <typename T>
00404 typename Enable_If<Is_Native<T>::value, memory_size_type>::type
00405 external_memory_in_bytes(const T&);
00406
00407 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00408
00409 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00410 memory_size_type
00411 total_memory_in_bytes(const mpz_class& x);
00412
00413 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00414
00415 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00416 memory_size_type
00417 external_memory_in_bytes(const mpz_class& x);
00418
00419 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00420
00421 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00422 memory_size_type
00423 total_memory_in_bytes(const mpq_class& x);
00424
00425 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00426
00427 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00428 memory_size_type
00429 external_memory_in_bytes(const mpq_class& x);
00430
00432
00433
00434 template <typename T, typename Enable = void>
00435 struct Has_OK : public False { };
00436
00437 template <typename T>
00438 struct Has_OK<T, typename Enable_If_Is<bool (T::*)() const, &T::OK>::type>
00439 : public True {
00440 };
00441
00442 template <typename T>
00443 inline typename Enable_If<Has_OK<T>::value, bool>::type
00444 f_OK(const T& to) {
00445 return to.OK();
00446 }
00447
00448 #define FOK(T) inline bool f_OK(const T&) { return true; }
00449
00450 FOK(char)
00451 FOK(signed char)
00452 FOK(unsigned char)
00453 FOK(signed short)
00454 FOK(unsigned short)
00455 FOK(signed int)
00456 FOK(unsigned int)
00457 FOK(signed long)
00458 FOK(unsigned long)
00459 FOK(signed long long)
00460 FOK(unsigned long long)
00461 FOK(float)
00462 FOK(double)
00463 FOK(long double)
00464 FOK(mpz_class)
00465 FOK(mpq_class)
00466
00467 }
00468
00469 #if defined(NDEBUG) && PPL_PROFILE_ADD_WEIGHT
00470 #include "Weight_Profiler.defs.hh"
00471 #endif
00472
00473 #include "globals.inlines.hh"
00474
00475 #endif // !defined(PPL_globals_defs_hh)