00001 /* Implementation of global objects: inline functions. 00002 Copyright (C) 2001-2008 Roberto Bagnara <bagnara@cs.unipr.it> 00003 00004 This file is part of the Parma Polyhedra Library (PPL). 00005 00006 The PPL is free software; you can redistribute it and/or modify it 00007 under the terms of the GNU General Public License as published by the 00008 Free Software Foundation; either version 3 of the License, or (at your 00009 option) any later version. 00010 00011 The PPL is distributed in the hope that it will be useful, but WITHOUT 00012 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00013 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00014 for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software Foundation, 00018 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. 00019 00020 For the most up-to-date information see the Parma Polyhedra Library 00021 site: http://www.cs.unipr.it/ppl/ . */ 00022 00023 #ifndef PPL_globals_inlines_hh 00024 #define PPL_globals_inlines_hh 1 00025 00026 #include <limits> 00027 #include <cassert> 00028 00029 namespace Parma_Polyhedra_Library { 00030 00031 inline dimension_type 00032 not_a_dimension() { 00033 return std::numeric_limits<dimension_type>::max(); 00034 } 00035 00036 inline 00037 Throwable::~Throwable() { 00038 } 00039 00040 inline void 00041 maybe_abandon() { 00042 if (const Throwable* p = abandon_expensive_computations) 00043 p->throw_me(); 00044 } 00045 00046 inline dimension_type 00047 compute_capacity(const dimension_type requested_size, 00048 const dimension_type maximum_size) { 00049 assert(requested_size <= maximum_size); 00050 // Speculation factor 2. 00051 return (requested_size < maximum_size / 2) 00052 ? 2*(requested_size + 1) 00053 : maximum_size; 00054 // Speculation factor 1.5. 00055 // return (maximum_size - requested_size > requested_size/2) 00056 // ? requested_size + requested_size/2 + 1 00057 // : maximum_size; 00058 } 00059 00060 // FIXME!!! 00061 inline dimension_type 00062 compute_capacity(const dimension_type requested_size) { 00063 // Speculation factor 2. 00064 return 2*(requested_size + 1); 00065 // Speculation factor 1.5. 00066 // return requested_size + requested_size/2 + 1; 00067 } 00068 00069 template <typename T> 00070 inline typename 00071 Enable_If<Is_Native<T>::value, memory_size_type>::type 00072 external_memory_in_bytes(const T&) { 00073 return 0; 00074 } 00075 00076 template <typename T> 00077 inline typename 00078 Enable_If<Is_Native<T>::value, memory_size_type>::type 00079 total_memory_in_bytes(const T&) { 00080 return sizeof(T); 00081 } 00082 00083 inline memory_size_type 00084 external_memory_in_bytes(const mpz_class& x) { 00085 return x.get_mpz_t()[0]._mp_alloc * PPL_SIZEOF_MP_LIMB_T; 00086 } 00087 00088 inline memory_size_type 00089 total_memory_in_bytes(const mpz_class& x) { 00090 return sizeof(x) + external_memory_in_bytes(x); 00091 } 00092 00093 inline memory_size_type 00094 external_memory_in_bytes(const mpq_class& x) { 00095 return external_memory_in_bytes(x.get_num()) 00096 + external_memory_in_bytes(x.get_den()); 00097 } 00098 00099 inline memory_size_type 00100 total_memory_in_bytes(const mpq_class& x) { 00101 return sizeof(x) + external_memory_in_bytes(x); 00102 } 00103 00104 } // namespace Parma_Polyhedra_Library 00105 00106 #endif // !defined(PPL_globals_inlines_hh)