00001 /* Implementation of global objects: inline functions. 00002 Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it> 00003 Copyright (C) 2010-2011 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://www.cs.unipr.it/ppl/ . */ 00023 00024 #ifndef PPL_globals_inlines_hh 00025 #define PPL_globals_inlines_hh 1 00026 00027 #include <limits> 00028 #include "assert.hh" 00029 00030 namespace Parma_Polyhedra_Library { 00031 00032 inline dimension_type 00033 not_a_dimension() { 00034 return std::numeric_limits<dimension_type>::max(); 00035 } 00036 00037 inline const Weightwatch_Traits::Threshold& 00038 Weightwatch_Traits::get() { 00039 return weight; 00040 } 00041 00042 inline bool 00043 Weightwatch_Traits::less_than(const Threshold& a, const Threshold& b) { 00044 return b - a < 1ULL << (sizeof(Threshold)*8-1); 00045 } 00046 00047 inline void 00048 Weightwatch_Traits::from_delta(Threshold& threshold, const Delta& delta) { 00049 threshold = weight + delta; 00050 } 00051 00052 inline 00053 Throwable::~Throwable() { 00054 } 00055 00056 inline void 00057 maybe_abandon() { 00058 #ifndef NDEBUG 00059 if (Implementation::in_assert) 00060 return; 00061 #endif 00062 if (Weightwatch_Traits::check_function) 00063 Weightwatch_Traits::check_function(); 00064 if (const Throwable* p = abandon_expensive_computations) 00065 p->throw_me(); 00066 } 00067 00068 inline dimension_type 00069 compute_capacity(const dimension_type requested_size, 00070 const dimension_type maximum_size) { 00071 assert(requested_size <= maximum_size); 00072 // Speculation factor 2. 00073 return (requested_size < maximum_size / 2) 00074 ? 2*(requested_size + 1) 00075 : maximum_size; 00076 // Speculation factor 1.5. 00077 // return (maximum_size - requested_size > requested_size/2) 00078 // ? requested_size + requested_size/2 + 1 00079 // : maximum_size; 00080 } 00081 00082 template <typename T> 00083 inline typename 00084 Enable_If<Is_Native<T>::value, memory_size_type>::type 00085 external_memory_in_bytes(const T&) { 00086 return 0; 00087 } 00088 00089 template <typename T> 00090 inline typename 00091 Enable_If<Is_Native<T>::value, memory_size_type>::type 00092 total_memory_in_bytes(const T&) { 00093 return sizeof(T); 00094 } 00095 00096 inline memory_size_type 00097 external_memory_in_bytes(const mpz_class& x) { 00098 return x.get_mpz_t()[0]._mp_alloc * PPL_SIZEOF_MP_LIMB_T; 00099 } 00100 00101 inline memory_size_type 00102 total_memory_in_bytes(const mpz_class& x) { 00103 return sizeof(x) + external_memory_in_bytes(x); 00104 } 00105 00106 inline memory_size_type 00107 external_memory_in_bytes(const mpq_class& x) { 00108 return external_memory_in_bytes(x.get_num()) 00109 + external_memory_in_bytes(x.get_den()); 00110 } 00111 00112 inline memory_size_type 00113 total_memory_in_bytes(const mpq_class& x) { 00114 return sizeof(x) + external_memory_in_bytes(x); 00115 } 00116 00117 } // namespace Parma_Polyhedra_Library 00118 00119 #endif // !defined(PPL_globals_inlines_hh)
1.6.3