00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef PPL_track_allocation_hh
00024 #define PPL_track_allocation_hh
00025
00026 #ifndef PROLOG_TRACK_ALLOCATION
00027 #define PROLOG_TRACK_ALLOCATION 0
00028 #endif
00029
00030 #if PROLOG_TRACK_ALLOCATION
00031
00032 #include <set>
00033 #include <iostream>
00034
00035 namespace Parma_Polyhedra_Library {
00036
00037 class Poly_Tracker {
00038 public:
00039 void insert(const void* pp);
00040 void check(const void* pp) const;
00041 void remove(const void* pp);
00042
00043 Poly_Tracker();
00044 ~Poly_Tracker();
00045
00046 private:
00047 typedef std::set<const void*, std::less<const void*> > Set;
00048 Set s;
00049 };
00050
00051 inline
00052 Poly_Tracker::Poly_Tracker() {
00053 }
00054
00055 inline
00056 Poly_Tracker::~Poly_Tracker() {
00057 Set::size_type n = s.size();
00058 if (n > 0)
00059 std::cerr << "Poly_Tracker: " << n << " polyhedra leaked!" << std::endl;
00060 }
00061
00062 inline void
00063 Poly_Tracker::insert(const void* pp) {
00064 std::pair<Set::iterator, bool> stat = s.insert(pp);
00065 if (!stat.second) {
00066 std::cerr << "Poly_Tracker: two polyhedra at the same address "
00067 << "at the same time?!" << std::endl;
00068 abort();
00069 }
00070 }
00071
00072 inline void
00073 Poly_Tracker::check(const void* pp) const {
00074 if (s.find(pp) == s.end()) {
00075 std::cerr << "Poly_Tracker: attempt to access an inexistent polyhedron."
00076 << std::endl;
00077 abort();
00078 }
00079 }
00080
00081 void
00082 Poly_Tracker::remove(const void* pp) {
00083 if (s.erase(pp) != 1) {
00084 std::cerr << "Poly_Tracker: attempt to deallocate "
00085 << "an inexistent polyhedron."
00086 << std::endl;
00087 abort();
00088 }
00089 }
00090
00091 namespace {
00092
00093 inline Poly_Tracker&
00094 poly_tracker() {
00095 static Poly_Tracker pt;
00096 return pt;
00097 }
00098
00099 }
00100
00101 }
00102
00103
00104 #define REGISTER(x) Parma_Polyhedra_Library::poly_tracker().insert(x)
00105 #define UNREGISTER(x) Parma_Polyhedra_Library::poly_tracker().remove(x)
00106 #define CHECK(x) Parma_Polyhedra_Library::poly_tracker().check(x)
00107
00108 #else
00109
00110 #define REGISTER(x)
00111 #define UNREGISTER(x)
00112 #define CHECK(x)
00113
00114 #endif
00115
00116 #endif // !defined(PPL_track_allocation_hh)