LRDE Tiger Compiler  1.34a $Id: 7fef12e1f5fa43449d667a0eec1d837c40fc1202 $
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
xalloc.hh
Go to the documentation of this file.
1 
6 #ifndef MISC_XALLOC_HH
7 # define MISC_XALLOC_HH
8 
9 # include <iostream>
10 # include <functional>
11 
12 namespace misc
13 {
15  struct iomanipulator : public std::unary_function<void, std::ostream>
16  {
17  virtual ~iomanipulator();
18  virtual void operator()(std::ostream& o) const = 0;
19  };
20 
26  std::ostream& operator<<(std::ostream& o, const iomanipulator& g);
27 
28 
39  template <class StoredType>
40  class xalloc
41  {
42  private:
47  class set_type : public iomanipulator
48  {
49  public:
51  set_type(const xalloc& slot, StoredType& data);
53  void operator()(std::ostream& ostr) const override;
54  private:
56  const xalloc& slot_;
58  StoredType& data_;
59  };
60 
65  class get_type : public iomanipulator
66  {
67  public:
69  get_type(const xalloc& slot, StoredType& data);
70 
72  void operator()(std::ostream& ostr) const override;
73  private:
75  const xalloc& slot_;
77  StoredType& data_;
78  };
79 
84  class swap_type : public iomanipulator
85  {
86  public:
88  swap_type(const xalloc& slot, StoredType& data);
89 
91  void operator()(std::ostream& ostr) const override;
92  private:
94  const xalloc& slot_;
96  StoredType& data_;
97  };
98 
100  const long int index_;
101 
102  public:
104  xalloc();
106  long int index() const;
108  StoredType& operator()(std::ostream& ostr) const;
109 
112  set_type set(StoredType& data) const;
113 
116  get_type get(StoredType& data) const;
117 
120  swap_type swap(StoredType& data) const;
121  };
122 
123 }
124 
125 # include <misc/xalloc.hxx>
126 
127 #endif // !MISC_XALLOC_HH