PPL  0.12.1
globals.defs.hh
Go to the documentation of this file.
00001 /* Declarations of global objects.
00002    Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it>
00003    Copyright (C) 2010-2012 BUGSENG srl (http://bugseng.com)
00004 
00005 This file is part of the Parma Polyhedra Library (PPL).
00006 
00007 The PPL is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 3 of the License, or (at your
00010 option) any later version.
00011 
00012 The PPL is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with this program; if not, write to the Free Software Foundation,
00019 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
00020 
00021 For the most up-to-date information see the Parma Polyhedra Library
00022 site: http://bugseng.com/products/ppl/ . */
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 
00036 namespace Parma_Polyhedra_Library {
00037 
00039 dimension_type
00040 not_a_dimension();
00041 
00042 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00043 
00044 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00045 int32_t
00046 hash_code_from_dimension(dimension_type dim);
00047 
00048 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00049 
00055 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00056 template <typename T>
00057 inline typename Enable_If<Slow_Copy<T>::value, void>::type
00058 swap(T&, T&) {
00059   PPL_COMPILE_TIME_CHECK(!Slow_Copy<T>::value, "missing swap specialization");
00060 }
00061 
00069 #define PPL_DIRTY_TEMP_COEFFICIENT(id) \
00070 PPL_DIRTY_TEMP(Parma_Polyhedra_Library::Coefficient, id)
00071 
00072 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00073 
00074 
00091 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00092 dimension_type
00093 compute_capacity(dimension_type requested_size,
00094                  dimension_type maximum_size);
00095 
00096 
00097 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00098 
00099 
00104 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00105 struct Weightwatch_Traits {
00107   typedef unsigned long long Threshold;
00108 
00110   typedef unsigned long long Delta;
00111 
00113   static const Threshold& get();
00114 
00116   static bool less_than(const Threshold& a, const Threshold& b);
00117 
00119 
00130   static Delta compute_delta(unsigned long unscaled, unsigned scale);
00131 
00133   static void from_delta(Threshold& threshold, const Delta& delta);
00134 
00136   static Threshold weight;
00137 
00144   static void (*check_function)(void);
00145 };
00146 
00147 
00148 #ifndef NDEBUG
00149 namespace Implementation {
00150 
00152 extern unsigned int in_assert;
00153 
00154 } // namespace Implementation
00155 #endif
00156 
00157 
00159 
00164 class Throwable {
00165 public:
00167   virtual void throw_me() const = 0;
00168 
00170   virtual ~Throwable();
00171 };
00172 
00196 extern const Throwable* volatile abandon_expensive_computations;
00197 
00198 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00199 
00205 #endif
00206 void
00207 maybe_abandon();
00208 
00210 
00214 struct Recycle_Input {
00215 };
00216 
00217 // Turn s into a string: PPL_STR(x + y) => "x + y".
00218 #define PPL_STR(s) #s
00219 // Turn the expansion of s into a string: PPL_XSTR(x) => "x expanded".
00220 #define PPL_XSTR(s) PPL_STR(s)
00221 
00222 #define PPL_OUTPUT_DECLARATIONS                                         \
00223  \
00224   void ascii_dump() const;                                              \
00225      \
00226   void ascii_dump(std::ostream& s) const;                               \
00227         \
00228   void print() const;
00229 
00230 #define PPL_OUTPUT_DEFINITIONS(class_name)                      \
00231   void                                                          \
00232   Parma_Polyhedra_Library::class_name::ascii_dump() const {     \
00233     ascii_dump(std::cerr);                                      \
00234   }                                                             \
00235                                                                 \
00236   void                                                          \
00237   Parma_Polyhedra_Library::class_name::print() const {          \
00238     using IO_Operators::operator<<;                             \
00239     std::cerr << *this;                                         \
00240   }
00241 
00242 #define PPL_OUTPUT_DEFINITIONS_ASCII_ONLY(class_name)                   \
00243   void                                                                  \
00244   Parma_Polyhedra_Library::class_name::ascii_dump() const {             \
00245     ascii_dump(std::cerr);                                              \
00246   }                                                                     \
00247                                                                         \
00248   void                                                                  \
00249   Parma_Polyhedra_Library::class_name::print() const {                  \
00250     std::cerr << "No user level output operator defined "               \
00251               << "for class " PPL_XSTR(class_name) << "." << std::endl; \
00252   }
00253 
00254 #define PPL_OUTPUT_TEMPLATE_DEFINITIONS(type_symbol, class_prefix)      \
00255   template <typename type_symbol>                                       \
00256   void                                                                  \
00257   class_prefix::ascii_dump() const {                             \
00258     ascii_dump(std::cerr);                                              \
00259   }                                                                     \
00260                                                                         \
00261   template <typename type_symbol>                                       \
00262   void                                                                  \
00263   class_prefix::print() const {                                  \
00264     using IO_Operators::operator<<;                                     \
00265     std::cerr << *this;                                                 \
00266   }
00267 
00268 #define PPL_OUTPUT_2_PARAM_TEMPLATE_DEFINITIONS(type_symbol1,           \
00269                                                 type_symbol2,           \
00270                                                 class_prefix)           \
00271   template <typename type_symbol1, typename type_symbol2>               \
00272   void                                                                  \
00273   PPL_U(class_prefix)<PPL_U(type_symbol1), PPL_U(type_symbol2)>         \
00274   ::ascii_dump() const {                                                \
00275     ascii_dump(std::cerr);                                              \
00276   }                                                                     \
00277                                                                         \
00278   template <typename type_symbol1, typename type_symbol2>               \
00279   void                                                                  \
00280   PPL_U(class_prefix)<PPL_U(type_symbol1), PPL_U(type_symbol2)>         \
00281   ::print() const {                                                     \
00282     using IO_Operators::operator<<;                                     \
00283     std::cerr << *this;                                                 \
00284   }
00285 
00286 #define PPL_OUTPUT_3_PARAM_TEMPLATE_DEFINITIONS(type_symbol1,           \
00287                                                 type_symbol2,           \
00288                                                 type_symbol3,           \
00289                                                 class_prefix)           \
00290   template <typename type_symbol1, typename type_symbol2,               \
00291             typename type_symbol3>                                      \
00292   void                                                                  \
00293   PPL_U(class_prefix)<PPL_U(type_symbol1), type_symbol2,                \
00294                       PPL_U(type_symbol3)>::ascii_dump()                \
00295     const {                                                             \
00296     ascii_dump(std::cerr);                                              \
00297   }                                                                     \
00298                                                                         \
00299     template <typename type_symbol1, typename type_symbol2,             \
00300               typename type_symbol3>                                    \
00301     void                                                                \
00302     PPL_U(class_prefix)<PPL_U(type_symbol1), type_symbol2,              \
00303                         PPL_U(type_symbol3)>::print()                   \
00304       const {                                                           \
00305       using IO_Operators::operator<<;                                   \
00306       std::cerr << *this;                                               \
00307     }
00308 
00309 #define PPL_OUTPUT_TEMPLATE_DEFINITIONS_ASCII_ONLY(type_symbol, class_prefix) \
00310   template <typename type_symbol>                                       \
00311   void                                                                  \
00312   class_prefix::ascii_dump() const {                                    \
00313     ascii_dump(std::cerr);                                              \
00314   }                                                                     \
00315                                                                         \
00316   template <typename type_symbol>                                       \
00317   void                                                                  \
00318   class_prefix::print() const {                                         \
00319     std::cerr << "No user level output operator defined "               \
00320               << "for " PPL_XSTR(class_prefix) << "." << std::endl;     \
00321   }
00322 
00323 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00324 
00325 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00326 bool is_space(char c);
00327 
00328 template <typename T, long long v, typename Enable = void>
00329 struct Fit : public False {
00330 };
00331 
00332 template <typename T, long long v>
00333 struct Fit<T, v, typename Enable_If<C_Integer<T>::value>::type>  {
00334   enum {
00335     value = (v >= static_cast<long long>(C_Integer<T>::min)
00336              && v <= static_cast<long long>(C_Integer<T>::max))
00337   };
00338 };
00339 
00340 template <typename T, T v>
00341 struct TConstant {
00342   static const T value = v;
00343 };
00344 
00345 
00346 template <typename T, T v>
00347 const T TConstant<T, v>::value;
00348 
00349 template <typename T, long long v, bool prefer_signed = true,
00350           typename Enable = void>
00351 struct Constant_ : public TConstant<T, v> {
00352 };
00353 
00354 template <typename T, long long v, bool prefer_signed>
00355 struct Constant_<T, v, prefer_signed,
00356                  typename Enable_If<(Fit<typename C_Integer<T>::smaller_signed_type, v>::value
00357                                      && (prefer_signed
00358                                          || !Fit<typename C_Integer<T>::smaller_unsigned_type, v>::value))>::type>
00359   : public Constant_<typename C_Integer<T>::smaller_signed_type, v, prefer_signed> {
00360 };
00361 
00362 template <typename T, long long v, bool prefer_signed>
00363 struct Constant_<T, v, prefer_signed,
00364                  typename Enable_If<(Fit<typename C_Integer<T>::smaller_unsigned_type, v>::value
00365                                      && (!prefer_signed
00366                                          || !Fit<typename C_Integer<T>::smaller_signed_type, v>::value))>::type>
00367   : public Constant_<typename C_Integer<T>::smaller_unsigned_type, v, prefer_signed> {
00368 };
00369 
00370 template <long long v, bool prefer_signed = true>
00371 struct Constant : public Constant_<long long, v, prefer_signed> {
00372 };
00373 
00374 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00375 
00376 
00377 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00378 
00379 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00380 
00384 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00385 template <typename T>
00386 typename Enable_If<Is_Native<T>::value, memory_size_type>::type
00387 total_memory_in_bytes(const T&);
00388 
00389 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00390 
00394 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00395 template <typename T>
00396 typename Enable_If<Is_Native<T>::value, memory_size_type>::type
00397 external_memory_in_bytes(const T&);
00398 
00399 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00400 
00401 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00402 memory_size_type
00403 total_memory_in_bytes(const mpz_class& x);
00404 
00405 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00406 
00407 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00408 memory_size_type
00409 external_memory_in_bytes(const mpz_class& x);
00410 
00411 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00412 
00413 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00414 memory_size_type
00415 total_memory_in_bytes(const mpq_class& x);
00416 
00417 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00418 
00419 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00420 memory_size_type
00421 external_memory_in_bytes(const mpq_class& x);
00422 
00423 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00424 
00425 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00426 
00427 
00428 template <typename T, typename Enable = void>
00429 struct Has_OK : public False { };
00430 
00431 template <typename T>
00432 struct Has_OK<T, typename Enable_If_Is<bool (T::*)() const, &T::OK>::type>
00433   : public True {
00434 };
00435 
00436 template <typename T>
00437 inline typename Enable_If<Has_OK<T>::value, bool>::type
00438 f_OK(const T& to) {
00439   return to.OK();
00440 }
00441 
00442 #define FOK(T) inline bool f_OK(const T&) { return true; }
00443 
00444 FOK(char)
00445 FOK(signed char)
00446 FOK(unsigned char)
00447 FOK(signed short)
00448 FOK(unsigned short)
00449 FOK(signed int)
00450 FOK(unsigned int)
00451 FOK(signed long)
00452 FOK(unsigned long)
00453 FOK(signed long long)
00454 FOK(unsigned long long)
00455 FOK(float)
00456 FOK(double)
00457 FOK(long double)
00458 FOK(mpz_class)
00459 FOK(mpq_class)
00460 
00461 dimension_type
00462 check_space_dimension_overflow(dimension_type dim,
00463                                dimension_type max,
00464                                const char* domain,
00465                                const char* method,
00466                                const char* reason);
00467 
00468 template <typename RA_Container>
00469 typename RA_Container::iterator
00470 nth_iter(RA_Container& cont, dimension_type n);
00471 
00472 template <typename RA_Container>
00473 typename RA_Container::const_iterator
00474 nth_iter(const RA_Container& cont, dimension_type n);
00475 
00476 dimension_type
00477 least_significant_one_mask(dimension_type i);
00478 
00479 } // namespace Parma_Polyhedra_Library
00480 
00481 // By default, use sparse matrices both for MIP_Problem and PIP_Problem.
00482 #ifndef PPL_USE_SPARSE_MATRIX
00483 #define PPL_USE_SPARSE_MATRIX 1
00484 #endif
00485 
00486 #ifndef PPL_PROFILE_ADD_WEIGHT
00487 #define PPL_PROFILE_ADD_WEIGHT 0
00488 #endif
00489 
00490 #if defined(NDEBUG) && PPL_PROFILE_ADD_WEIGHT
00491 #include "Weight_Profiler.defs.hh"
00492 #endif
00493 
00494 #if defined(NDEBUG)
00495 #if PPL_PROFILE_ADD_WEIGHT
00496 #define WEIGHT_BEGIN() Weight_Profiler::begin()
00497 #define WEIGHT_ADD(delta)                                     \
00498   do {                                                        \
00499     static Weight_Profiler wp__(__FILE__, __LINE__, delta);   \
00500     wp__.end();                                               \
00501   } while (false)
00502 #define WEIGHT_ADD_MUL(delta, factor)                                   \
00503   do {                                                                  \
00504     static Weight_Profiler wp__(__FILE__, __LINE__, delta);             \
00505     wp__.end(factor);                                                   \
00506   } while (false)
00507 #else
00508 #define WEIGHT_BEGIN()                          \
00509   do {                                          \
00510   } while (false)
00511 #define WEIGHT_ADD(delta)                       \
00512   do {                                          \
00513     Weightwatch_Traits::weight += (delta);      \
00514   } while (false)
00515 #define WEIGHT_ADD_MUL(delta, factor)                   \
00516   do {                                                  \
00517     Weightwatch_Traits::weight += (delta)*(factor);     \
00518   } while (false)
00519 #endif
00520 #else
00521 #define WEIGHT_BEGIN()
00522 #define WEIGHT_ADD(delta)                       \
00523   do {                                          \
00524     if (Implementation::in_assert == 0)         \
00525       Weightwatch_Traits::weight += delta;      \
00526   } while (false)
00527 #define WEIGHT_ADD_MUL(delta, factor)                   \
00528   do {                                                  \
00529     if (Implementation::in_assert == 0)                 \
00530       Weightwatch_Traits::weight += delta * factor;     \
00531   } while (false)
00532 #endif
00533 
00534 #include "globals.inlines.hh"
00535 
00536 #endif // !defined(PPL_globals_defs_hh)