PPL  1.2
Temp_inlines.hh
Go to the documentation of this file.
1 /* Temp_* classes implementation: 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_Temp_inlines_hh
25 #define PPL_Temp_inlines_hh 1
26 
27 #include "meta_programming.hh"
28 
29 namespace Parma_Polyhedra_Library {
30 
31 template <typename T>
32 inline
34  : item_() {
35 }
36 
37 template <typename T>
38 inline T&
40  return item_;
41 }
42 
43 template <typename T>
44 inline
46  : head_ptr(0) {
47 }
48 
49 template <typename T>
50 inline Temp_Item<T>*&
52  static Free_List free_list;
53  return free_list.head_ptr;
54 }
55 
56 template <typename T>
57 inline Temp_Item<T>&
59  Temp_Item* const p = free_list_ref();
60  if (p != 0) {
61  free_list_ref() = p->next;
62  return *p;
63  }
64  else {
65  return *new Temp_Item();
66  }
67 }
68 
69 template <typename T>
70 inline void
72  p.next = free_list_ref();
73  free_list_ref() = &p;
74 }
75 
76 template <typename T>
77 inline
79  : held(Temp_Item<T>::obtain()) {
80 }
81 
82 template <typename T>
83 inline
86 }
87 
88 template <typename T>
89 inline T&
91  return held.item();
92 }
93 
94 template <typename T>
95 inline
97 }
98 
99 template <typename T>
100 inline T&
102  return item_;
103 }
104 
105 } // namespace Parma_Polyhedra_Library
106 
107 #define PPL_DIRTY_TEMP(T, id) \
108  Parma_Polyhedra_Library::Dirty_Temp<PPL_U(T)> holder_ ## id; \
109  PPL_U(T)& PPL_U(id) = holder_ ## id.item()
110 
111 #endif // !defined(PPL_Temp_inlines_hh)
T & item()
Returns the value of the held item.
T & item()
Returns a reference to the held item.
Definition: Temp_inlines.hh:90
A pool of temporary items of type T.
Definition: Temp_defs.hh:36
Temp_Value_Holder()
Constructs a fake holder.
Definition: Temp_inlines.hh:96
Temp_Item()
Default constructor.
Definition: Temp_inlines.hh:33
T & item()
Returns a reference to the encapsulated item.
Definition: Temp_inlines.hh:39
The entire library is confined to this namespace.
Definition: version.hh:61
Temp_Item * next
Pointer to the next item in the free list.
Definition: Temp_defs.hh:52
static void release(Temp_Item &p)
Releases the temporary item p.
Definition: Temp_inlines.hh:71
static Temp_Item *& free_list_ref()
Head of the free list.
Definition: Temp_inlines.hh:51
static Temp_Item & obtain()
Obtains a reference to a temporary item.
Definition: Temp_inlines.hh:58
Temp_Reference_Holder()
Constructs an holder holding a dirty temp.
Definition: Temp_inlines.hh:78