Vcsn  2.3
Be Rational
xalloc.hxx
Go to the documentation of this file.
1 
6 namespace vcsn
7 {
8 
9  /*----------------.
10  | iomanipulator. |
11  `----------------*/
12 
13  inline std::ostream&
14  operator<<(std::ostream& o, const iomanipulator& g)
15  {
16  g(o);
17  return o;
18  }
19 
20 
21  /*---------------------.
22  | xalloc<StoredType>. |
23  `---------------------*/
24 
25  template <typename StoredType>
27  : index_(std::ios::xalloc())
28  {}
29 
30  template <typename StoredType>
31  long int
33  {
34  return index_;
35  }
36 
37  template <typename StoredType>
38  StoredType&
39  xalloc<StoredType>::operator()(std::ostream& ostr) const
40  {
41  // FIXME: Some meta programming to switch on pword or iword
42  // would make it possible to use a regular static_cast instead
43  // of this C-cast.
44  return (StoredType&)(ostr.pword(index()));
45  }
46 
47 
48  /*-----------.
49  | set_type. |
50  `-----------*/
51 
52  template <typename StoredType>
53  xalloc<StoredType>::set_type::set_type(const xalloc& slot, StoredType& data)
54  : slot_(slot), data_(data)
55  {}
56 
57  template <typename StoredType>
58  void
59  xalloc<StoredType>::set_type::operator()(std::ostream& ostr) const
60  {
61  slot_(ostr) = data_;
62  }
63 
64  template <typename StoredType>
66  xalloc<StoredType>::set(StoredType& data) const
67  {
68  return set_type(*this, data);
69  }
70 
71 
72  /*-----------.
73  | get_type. |
74  `-----------*/
75 
76  template <typename StoredType>
77  xalloc<StoredType>::get_type::get_type(const xalloc& slot, StoredType& data)
78  : slot_(slot), data_(data)
79  {
80  }
81 
82  template <typename StoredType>
83  void
84  xalloc<StoredType>::get_type::operator()(std::ostream& ostr) const
85  {
86  data_ = slot_(ostr);
87  }
88 
89  template <typename StoredType>
91  xalloc<StoredType>::get(StoredType& data) const
92  {
93  return get_type(*this, data);
94  }
95 
96 
97  /*------------.
98  | swap_type. |
99  `------------*/
100 
101  template <typename StoredType>
102  xalloc<StoredType>::swap_type::swap_type(const xalloc& slot, StoredType& data)
103  : slot_(slot), data_(data)
104  {}
105 
106  template <typename StoredType>
107  void
109  {
110  std::swap(slot_(ostr), data_);
111  }
112 
113  template <typename StoredType>
115  xalloc<StoredType>::swap(StoredType& data) const
116  {
117  return swap_type(*this, data);
118  }
119 
120 }
Defines the operator() for the classes get_type, set_type and swap_type.
Definition: xalloc.hh:16
void operator()(std::ostream &ostr) const
Get the data from the xalloced place.
Definition: xalloc.hxx:84
get_type get(StoredType &data) const
A getter.
Definition: xalloc.hxx:91
Handle the data to get from the xalloced place.
Definition: xalloc.hh:63
STL namespace.
swap_type swap(StoredType &data) const
A swapper.
Definition: xalloc.hxx:115
std::ostream & operator<<(std::ostream &os, direction d)
Pretty-printing.
Definition: direction.cc:19
swap_type(const xalloc &slot, StoredType &data)
Set data_ to data.
Definition: xalloc.hxx:102
xalloc()
Allocates the slot.
Definition: xalloc.hxx:26
StoredType & operator()(std::ostream &ostr) const
The stored data as an lvalue.
Definition: xalloc.hxx:39
set_type set(StoredType &data) const
A setter.
Definition: xalloc.hxx:66
get_type(const xalloc &slot, StoredType &data)
Set data_ to data.
Definition: xalloc.hxx:77
Swap the data stored in the stream for a given one.
Definition: xalloc.hh:82
Definition: a-star.hh:8
void operator()(std::ostream &ostr) const
Swap the data from the xalloced place for a given one.
Definition: xalloc.hxx:108
long int index() const ATTRIBUTE_PURE
The xalloc index.
Definition: xalloc.hxx:32
set_type(const xalloc &slot, StoredType &data)
Set data_ to data.
Definition: xalloc.hxx:53
Allocate slots in std::ostreams.
Definition: xalloc.hh:38
void operator()(std::ostream &ostr) const
Set the data in the xalloced place.
Definition: xalloc.hxx:59
Handle the data to put in the xalloced place.
Definition: xalloc.hh:45