Vaucanson  1.4.1
element.hxx
1 // element.hxx: this file is part of the Vaucanson project.
2 //
3 // Vaucanson, a generic library for finite state machines.
4 //
5 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2011 The Vaucanson Group.
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
11 //
12 // The complete GNU General Public Licence Notice can be found as the
13 // `COPYING' file in the root directory.
14 //
15 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
16 //
17 #ifndef VCSN_DESIGN_PATTERN_ELEMENT_HXX
18 # define VCSN_DESIGN_PATTERN_ELEMENT_HXX
19 
22 
23 namespace vcsn {
24 
25  /*-------------.
26  | Constructors |
27  `-------------*/
28 
29  template <class S, class T>
31  MetaElement<S, T>(),
32  SetSlot<S>(),
33  value_(op_default(SELECT(S), SELECT(T)))
34  {
35  static_assertion_(not dynamic_traits<S>::ret,
36  need_dynamic_structural_element);
37  }
38 
39  /*--------------------------.
40  | Constructors from Element |
41  `--------------------------*/
42 
43  template <class S, class T>
45  MetaElement<S, T>(other),
46  SetSlot<S>(other),
47  value_(other.value_)
48  {}
49 
50  template <class S, class T>
51  template<typename U>
53  SetSlot<S>(other.structure()),
54  value_(op_convert(other.structure(), SELECT(T), other.value()))
55  {}
56 
57  template <class S, class T>
58  template<typename OtherS, typename U>
60  : SetSlot<S>(op_convert(SELECT(S), other.structure())),
61  value_ (op_convert(this->_structure_get(), value_,
62  other.structure(), other.value()))
63  {
64  }
65 
66  /*-------------------------.
67  | Constructors from values |
68  `-------------------------*/
69 
70  template <class S, class T>
71  Element<S,T>::Element(const T& other)
72  : SetSlot<S> (),
73  value_(op_convert(SELECT(S), SELECT(T), other))
74  {
75  static_assertion_(not dynamic_traits<S>::ret,
76  need_dynamic_structural_element);
77  }
78 
79  template <class S, class T>
80  template<typename U>
81  Element<S,T>::Element(const U& other)
82  : SetSlot<S> (),
83  value_(op_convert(SELECT(S), SELECT(T), other))
84  {
85  static_assertion_(not dynamic_traits<S>::ret,
86  need_dynamic_structural_element);
87  }
88 
89  /*--------------------------------------.
90  | Constructors from structural elements |
91  `--------------------------------------*/
92 
93  template <class S, class T>
94  Element<S,T>::Element(const S& structure)
95  : SetSlot<S>(structure),
96  value_(op_default(this->_structure_get(), SELECT(T)))
97  {}
98 
99  template <class S, class T>
100  Element<S,T>::Element(const S& structure, const T& other)
101  : SetSlot<S>(structure),
102  value_(op_convert(this->_structure_get(), SELECT(T), other))
103  {}
104  template <class S, class T>
105  template<typename U>
106  Element<S,T>::Element(const S& structure, const U& other)
107  : SetSlot<S>(structure),
108  value_(op_convert(this->_structure_get(), SELECT(T), other))
109  {}
110 
111  template <class S, class T>
112  template<typename OtherS, typename U>
113  Element<S,T>::Element(const S& structure, const Element<OtherS, U>& other)
114  : SetSlot<S> (structure),
115  value_(op_convert(this->_structure_get(), SELECT(T),
116  other.structure(), other.value()))
117  {}
118 
119  /*-----------.
120  | Assignment |
121  `-----------*/
122 
123  template <class S, class T>
124  Element<S,T>&
126  {
127  this->_structure_assign(other.structure());
128  op_assign(structure(), other.structure(), value_, other.value());
129  return *this;
130  }
131 
132  template <class S, class T>
133  template<typename U>
134  Element<S,T>&
136  {
137  this->_structure_assign(other.structure());
138  op_assign(structure(), other.structure(), value_, other.value());
139  return *this;
140  }
141 
142  template <class S, class T>
143  template<typename OtherS, typename U>
145  {
146  this->_structure_assign(op_convert(SELECT(S), other.structure()));
147  op_assign(structure(), other.structure(), value_, other.value());
148  return *this;
149  }
150 
151  template <class S, class T>
152  template<typename U>
154  {
155  op_assign(structure(), value(), other);
156  return *this;
157  }
158 
159  /*------.
160  | Sugar |
161  `------*/
162 
163  template <class S, class T>
164  void
165  Element<S,T>::attach(const S& structure)
166  {
167  this->_structure_attach(structure);
168  }
169 
170  template <class S, class T>
171  const S&
173  {
174  return this->_structure_get();
175  }
176 
177  template <class S, class T>
179  {
180  return value_;
181  }
182 
183  template <class S, class T>
184  const T& Element<S,T>::value() const
185  {
186  return value_;
187  }
188 
189 } // vcsn
190 
191 
192 #endif // ! VCSN_DESIGN_PATTERN_ELEMENT_HXX