Vaucanson  1.4.1
syntactic_decorator.hxx
1 // syntactic_decorator.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 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_SYNTACTIC_DECORATOR_HXX
18 # define VCSN_DESIGN_PATTERN_SYNTACTIC_DECORATOR_HXX
19 
23 
24 namespace vcsn {
25  template <typename S, typename T>
26  Element<S, T>&
28  {
29  return *static_cast<Element<S, T>*>(this);
30  }
31 
32  template <typename S, typename T>
33  const Element<S, T>&
35  {
36  return *static_cast<const Element<S, T>*>(this);
37  }
38 
39 
40  template <typename S, typename T>
41  const S&
43  {
44  return self().structure();
45  }
46 
47  template <typename S, typename T>
48  T&
50  {
51  return self().value();
52  }
53 
54  template <typename S, typename T>
55  const T&
57  {
58  return self().value();
59  }
60 
61 #define ELEMENT_IN_OPERATOR(Op, HookName) \
62  template <typename S, typename T> \
63  template<typename OtherS, typename U> \
64  Element<S, T>& \
65  SyntacticDecorator<S, T>::Op (const Element<OtherS, U>& other) \
66  { \
67  op_in_ ## HookName (self().structure(), \
68  other.structure(), \
69  value(), \
70  other.value()); \
71  return self(); \
72  } \
73  \
74  template <typename S, typename T> \
75  template<typename U> \
76  Element<S, T>& \
77  SyntacticDecorator<S, T>::Op (const U& other) \
78  { \
79  op_in_ ## HookName (self().structure(), \
80  value(), \
81  op_convert(self().structure(), SELECT(T), other)); \
82  return self(); \
83  }
84 
85  ELEMENT_IN_OPERATOR(operator +=, add);
86  ELEMENT_IN_OPERATOR(operator -=, sub);
87  ELEMENT_IN_OPERATOR(operator /=, div);
88  ELEMENT_IN_OPERATOR(operator *=, mul);
89  ELEMENT_IN_OPERATOR(operator %=, mod);
90 
91 #undef ELEMENT_IN_OPERATOR
92 
93  template <typename S, typename T>
96  {
97  op_in_inc(self().structure(), self().value());
98  return self();
99  }
100 
101  template <typename S, typename T>
104  {
105  Element<S, T> ret(self());
106  op_in_inc(self().structure(), self().value());
107  return ret;
108  }
109 
110  template <typename S, typename T>
113  {
114  op_in_dec(self().structure(), self().value());
115  return self();
116  }
117 
118  template <typename S, typename T>
121  {
122  Element<S, T> ret(self());
123  op_in_dec(self().structure(), self().value());
124  return ret;
125  }
126 
127  template <typename S, typename T>
128  template <typename U>
131  {
132  precondition(&structure() == &other.structure());
133  op_swap(structure(), value(), other.value());
134  return self();
135  }
136 
137  template <typename S, typename T>
139  {}
140 
141  template <typename S, typename T>
142  SyntacticDecorator<S, T>::SyntacticDecorator(const SyntacticDecorator&)
143  {}
144 
145 } // vcsn
146 
147 #endif // ! VCSN_DESIGN_PATTERN_SYNTACTIC_DECORATOR_HXX