PPL Prolog Language Interface  1.2
ppl_prolog_common_inlines.hh
Go to the documentation of this file.
1 /* Common part of the Prolog interfaces: inline functions.
2  Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it>
3  Copyright (C) 2010-2016 BUGSENG srl (http://bugseng.com)
4 
5 This file is part of the Parma Polyhedra Library (PPL).
6 
7 The PPL is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 The PPL is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
20 
21 For the most up-to-date information see the Parma Polyhedra Library
22 site: http://bugseng.com/products/ppl/ . */
23 
24 #ifndef PPL_ppl_prolog_common_inlines_hh
25 #define PPL_ppl_prolog_common_inlines_hh 1
26 
27 #if PROLOG_TRACK_ALLOCATION || NOISY_PROLOG_TRACK_ALLOCATION
28 
29 #include <typeinfo>
30 #include <iomanip>
31 
32 template <typename T>
33 void
34 Allocation_Tracker::insert(const T* p) {
35 #if NOISY_PROLOG_TRACK_ALLOCATION
36  std::cerr << "inserting " << typeid(*p).name()
37  << " at " << std::hex << (void*) p << std::endl;
38 #endif
39  std::pair<Set::iterator, bool> stat = s.insert(p);
40  if (!stat.second) {
41  std::cerr << "Interfaces::Prolog::Allocation_Tracker:"
42  " two objects at the same address at the same time?!"
43  << std::endl;
44  abort();
45  }
46 }
47 
48 template <typename T>
49 void
50 Allocation_Tracker::weak_insert(const T* p) {
51 #if NOISY_PROLOG_TRACK_ALLOCATION
52  std::cerr << "inserting weak " << typeid(*p).name()
53  << " at " << std::hex << (void*) p << std::endl;
54 #endif
55  weak_s.insert(p);
56 }
57 
58 template <typename T>
59 void
60 Allocation_Tracker::remove(const T* p) {
61 #if NOISY_PROLOG_TRACK_ALLOCATION
62  std::cerr << "removing " << typeid(*p).name()
63  << " at " << std::hex << (void*) p << std::endl;
64 #endif
65  if (s.erase(p) != 1) {
66  std::cerr << "Interfaces::Prolog::Allocation_Tracker:"
67  " attempt to deallocate a nonexistent polyhedron."
68  << std::endl;
69  abort();
70  }
71 }
72 
73 template <typename T>
74 void
75 Allocation_Tracker::check(const T* p) const {
76  if (s.find(p) == s.end()
77  && weak_s.find(p) == weak_s.end()) {
78  std::cerr << "Interfaces::Prolog::Allocation_Tracker:"
79  " attempt to access a nonexistent "
80  << typeid(*p).name()
81  << " at " << std::hex << (void*) p << std::endl;
82  abort();
83  }
84 }
85 
86 #endif // PROLOG_TRACK_ALLOCATION || NOISY_PROLOG_TRACK_ALLOCATION
87 
88 #endif // !defined(PPL_ppl_prolog_common_inlines_hh)