LRDE Tiger Compiler  1.34a $Id: 7fef12e1f5fa43449d667a0eec1d837c40fc1202 $
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
xalloc.hxx
Go to the documentation of this file.
1 
6 #ifndef MISC_XALLOC_HXX
7 # define MISC_XALLOC_HXX
8 
9 # include <misc/xalloc.hh>
10 
11 namespace misc
12 {
13 
14  /*----------------.
15  | iomanipulator. |
16  `----------------*/
17 
18  inline std::ostream&
19  operator<<(std::ostream& o, const iomanipulator& g)
20  {
21  g(o);
22  return o;
23  }
24 
25 
26  /*---------------------.
27  | xalloc<StoredType>. |
28  `---------------------*/
29 
30  template <class StoredType>
32  : index_(std::ios::xalloc())
33  {
34  }
35 
36  template <class StoredType>
37  long int
39  {
40  return index_;
41  }
42 
43  template <class StoredType>
44  StoredType&
45  xalloc<StoredType>::operator()(std::ostream& ostr) const
46  {
47  // FIXME: Some meta programming to switch on pword or iword
48  // would make it possible to use a regular static_cast instead
49  // of this C-cast.
50  return (StoredType&)(ostr.pword(index()));
51  }
52 
53 
54  /*-----------.
55  | set_type. |
56  `-----------*/
57 
58  template <class StoredType>
59  xalloc<StoredType>::set_type::set_type(const xalloc& slot, StoredType& data)
60  : slot_(slot), data_(data)
61  {
62  }
63 
64  template <class StoredType>
65  void
66  xalloc<StoredType>::set_type::operator()(std::ostream& ostr) const
67  {
68  slot_(ostr) = data_;
69  }
70 
71  template <class StoredType>
73  xalloc<StoredType>::set(StoredType& data) const
74  {
75  return set_type(*this, data);
76  }
77 
78 
79  /*-----------.
80  | get_type. |
81  `-----------*/
82 
83  template <class StoredType>
84  xalloc<StoredType>::get_type::get_type(const xalloc& slot, StoredType& data)
85  : slot_(slot), data_(data)
86  {
87  }
88 
89  template <class StoredType>
90  void
91  xalloc<StoredType>::get_type::operator()(std::ostream& ostr) const
92  {
93  data_ = slot_(ostr);
94  }
95 
96  template <class StoredType>
98  xalloc<StoredType>::get(StoredType& data) const
99  {
100  return get_type(*this, data);
101  }
102 
103 
104  /*------------.
105  | swap_type. |
106  `------------*/
107 
108  template <class StoredType>
109  xalloc<StoredType>::swap_type::swap_type(const xalloc& slot, StoredType& data)
110  : slot_(slot), data_(data)
111  {
112  }
113 
114  template <class StoredType>
115  void
117  {
118  std::swap(slot_(ostr), data_);
119  }
120 
121  template <class StoredType>
123  xalloc<StoredType>::swap(StoredType& data) const
124  {
125  return swap_type(*this, data);
126  }
127 
128 }
129 
130 #endif // !MISC_XALLOC_HXX