Vcsn  2.8
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  namespace detail
38  {
39  // Case iword.
40  template <typename StoredType>
41  std::enable_if_t<std::is_integral<StoredType>{},
42  StoredType&>
43  get_slot(std::ostream& ostr, int index)
44  {
45  return static_cast<StoredType&>(ostr.iword(index));
46  }
47 
48  // Case pword.
49  template <typename StoredType>
50  std::enable_if_t<!std::is_integral<StoredType>{},
51  StoredType&>
52  get_slot(std::ostream& ostr, int index)
53  {
54  return reinterpret_cast<StoredType&>
55  (const_cast<const void*&>(ostr.pword(index)));
56  }
57  }
58 
59  template <typename StoredType>
60  StoredType&
61  xalloc<StoredType>::operator()(std::ostream& ostr) const
62  {
63  return detail::get_slot<StoredType>(ostr, index());
64  }
65 
66 
67  /*-----------.
68  | set_type. |
69  `-----------*/
70 
71  template <typename StoredType>
72  xalloc<StoredType>::set_type::set_type(const xalloc& slot, StoredType& data)
73  : slot_(slot), data_(data)
74  {}
75 
76  template <typename StoredType>
77  void
78  xalloc<StoredType>::set_type::operator()(std::ostream& ostr) const
79  {
80  slot_(ostr) = data_;
81  }
82 
83  template <typename StoredType>
85  xalloc<StoredType>::set(StoredType& data) const
86  {
87  return set_type(*this, data);
88  }
89 
90 
91  /*-----------.
92  | get_type. |
93  `-----------*/
94 
95  template <typename StoredType>
96  xalloc<StoredType>::get_type::get_type(const xalloc& slot, StoredType& data)
97  : slot_(slot), data_(data)
98  {
99  }
100 
101  template <typename StoredType>
102  void
104  {
105  data_ = slot_(ostr);
106  }
107 
108  template <typename StoredType>
110  xalloc<StoredType>::get(StoredType& data) const
111  {
112  return get_type(*this, data);
113  }
114 
115 
116  /*------------.
117  | swap_type. |
118  `------------*/
119 
120  template <typename StoredType>
121  xalloc<StoredType>::swap_type::swap_type(const xalloc& slot, StoredType& data)
122  : slot_(slot), data_(data)
123  {}
124 
125  template <typename StoredType>
126  void
128  {
129  std::swap(slot_(ostr), data_);
130  }
131 
132  template <typename StoredType>
134  xalloc<StoredType>::swap(StoredType& data) const
135  {
136  return swap_type(*this, data);
137  }
138 
139 }
set_type(const xalloc &slot, StoredType &data)
Set data_ to data.
Definition: xalloc.hxx:72
Allocate slots in std::ostreams.
Definition: xalloc.hh:38
void operator()(std::ostream &ostr) const
Get the data from the xalloced place.
Definition: xalloc.hxx:103
set_type set(StoredType &data) const
A setter.
Definition: xalloc.hxx:85
Handle the data to get from the xalloced place.
Definition: xalloc.hh:63
std::enable_if_t<!std::is_integral< StoredType >{}, StoredType & > get_slot(std::ostream &ostr, int index)
Definition: xalloc.hxx:52
const xalloc & slot_
The xalloced data.
Definition: xalloc.hh:73
void operator()(std::ostream &ostr) const
Swap the data from the xalloced place for a given one.
Definition: xalloc.hxx:127
std::ostream & operator<<(std::ostream &os, direction d)
Pretty-printing.
Definition: direction.cc:19
StoredType & data_
Variable in which we store the data to be swapped.
Definition: xalloc.hh:94
StoredType & data_
Variable in which we return the xalloc data.
Definition: xalloc.hh:75
swap_type(const xalloc &slot, StoredType &data)
Set data_ to data.
Definition: xalloc.hxx:121
Handle the data to put in the xalloced place.
Definition: xalloc.hh:45
StoredType & operator()(std::ostream &ostr) const
The stored data as an lvalue.
Definition: xalloc.hxx:61
swap_type swap(StoredType &data) const
A swapper.
Definition: xalloc.hxx:134
Swap the data stored in the stream for a given one.
Definition: xalloc.hh:82
Definition: a-star.hh:8
const xalloc & slot_
The xalloced data.
Definition: xalloc.hh:54
xalloc()
Allocates the slot.
Definition: xalloc.hxx:26
StoredType & data_
Data to put in the stream.
Definition: xalloc.hh:56
void swap(config::value &first, config::value &second)
const xalloc & slot_
The xalloced data.
Definition: xalloc.hh:92
get_type(const xalloc &slot, StoredType &data)
Set data_ to data.
Definition: xalloc.hxx:96
Defines the operator() for the classes get_type, set_type and swap_type.
Definition: xalloc.hh:16
long int index() const ATTRIBUTE_PURE
The xalloc index.
Definition: xalloc.hxx:32
void operator()(std::ostream &ostr) const
Set the data in the xalloced place.
Definition: xalloc.hxx:78
const long int index_
The index of the slot.
Definition: xalloc.hh:98
get_type get(StoredType &data) const
A getter.
Definition: xalloc.hxx:110
STL namespace.