- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

# syntactic_decorator.hxx

    00001 // syntactic_decorator.hxx: this file is part of the Vaucanson project.
    00002 //
    00003 // Vaucanson, a generic library for finite state machines.
    00004 //
    00005 // Copyright (C) 2001, 2002, 2003, 2004, 2005 The Vaucanson Group.
    00006 //
    00007 // This program is free software; you can redistribute it and/or
    00008 // modify it under the terms of the GNU General Public License
    00009 // as published by the Free Software Foundation; either version 2
    00010 // of the License, or (at your option) any later version.
    00011 //
    00012 // The complete GNU General Public Licence Notice can be found as the
    00013 // `COPYING' file in the root directory.
    00014 //
    00015 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
    00016 //
    00017 #ifndef VCSN_DESIGN_PATTERN_SYNTACTIC_DECORATOR_HXX
    00018 # define VCSN_DESIGN_PATTERN_SYNTACTIC_DECORATOR_HXX
    00019
    00020 # include <vaucanson/misc/selectors.hh>
    00021 # include <vaucanson/design_pattern/syntactic_decorator.hh>
    00022 # include <vaucanson/misc/contract.hh>
    00023
    00024 namespace vcsn {
    00025   template <typename S, typename T>
    00026   Element<S, T>&
    00027   SyntacticDecorator<S, T>::self()
    00028   {
    00029     return *static_cast<Element<S, T>*>(this);
    00030   }
    00031
    00032   template <typename S, typename T>
    00033   const Element<S, T>&
    00034   SyntacticDecorator<S, T>::self() const
    00035   {
    00036     return *static_cast<const Element<S, T>*>(this);
    00037   }
    00038
    00039
    00040   template <typename S, typename T>
    00041   const S&
    00042   SyntacticDecorator<S, T>::structure() const
    00043   {
    00044     return self().structure();
    00045   }
    00046
    00047   template <typename S, typename T>
    00048   T&
    00049   SyntacticDecorator<S, T>::value()
    00050   {
    00051     return self().value();
    00052   }
    00053
    00054   template <typename S, typename T>
    00055   const T&
    00056   SyntacticDecorator<S, T>::value() const
    00057   {
    00058     return self().value();
    00059   }
    00060
    00061 #define ELEMENT_IN_OPERATOR(Op, HookName)                                       \
    00062       template <typename S, typename T>                                         \
    00063       template<typename OtherS, typename U>                                     \
    00064       Element<S, T>&                                                    \
    00065       SyntacticDecorator<S, T>::Op (const Element<OtherS, U>& other)            \
    00066       {                                                                         \
    00067     op_in_ ## HookName (self().structure(),                                \
    00068                         other.structure(),                                 \
    00069                         value(),                                           \
    00070                         other.value());                                    \
    00071         return self();                                                          \
    00072       }                                                                         \
    00073                                                                            \
    00074       template <typename S, typename T>                                         \
    00075       template<typename U>                                                      \
    00076       Element<S, T>&                                                    \
    00077       SyntacticDecorator<S, T>::Op (const U& other)                             \
    00078       {                                                                         \
    00079     op_in_ ## HookName (self().structure(),                                \
    00080                         value(),                                           \
    00081                         op_convert(self().structure(), SELECT(T), other)); \
    00082         return self();                                                          \
    00083       }
    00084
    00085   ELEMENT_IN_OPERATOR(operator +=, add);
    00086   ELEMENT_IN_OPERATOR(operator -=, sub);
    00087   ELEMENT_IN_OPERATOR(operator /=, div);
    00088   ELEMENT_IN_OPERATOR(operator *=, mul);
    00089   ELEMENT_IN_OPERATOR(operator %=, mod);
    00090
    00091 #undef ELEMENT_IN_OPERATOR
    00092
    00093   template <typename S, typename T>
    00094   Element<S, T>&
    00095   SyntacticDecorator<S, T>::operator++()
    00096   {
    00097     op_in_inc(self().structure(), self().value());
    00098     return self();
    00099   }
    00100
    00101   template <typename S, typename T>
    00102   Element<S, T>
    00103   SyntacticDecorator<S, T>::operator++(int)
    00104   {
    00105     Element<S, T> ret(self());
    00106     op_in_inc(self().structure(), self().value());
    00107     return ret;
    00108   }
    00109
    00110   template <typename S, typename T>
    00111   Element<S, T>&
    00112   SyntacticDecorator<S, T>::operator--()
    00113   {
    00114     op_in_dec(self().structure(), self().value());
    00115     return self();
    00116   }
    00117
    00118   template <typename S, typename T>
    00119   Element<S, T>
    00120   SyntacticDecorator<S, T>::operator--(int)
    00121   {
    00122     Element<S, T> ret(self());
    00123     op_in_dec(self().structure(), self().value());
    00124     return ret;
    00125   }
    00126
    00127   template <typename S, typename T>
    00128   template <typename U>
    00129   Element<S, T>&
    00130   SyntacticDecorator<S, T>::swap(Element<S, U>& other)
    00131   {
    00132     precondition(&structure() == &other.structure());
    00133     op_swap(structure(), value(), other.value());
    00134     return self();
    00135   }
    00136
    00137   template <typename S, typename T>
    00138   SyntacticDecorator<S, T>::SyntacticDecorator()
    00139   {}
    00140
    00141   template <typename S, typename T>
    00142   SyntacticDecorator<S, T>::SyntacticDecorator(const SyntacticDecorator&)
    00143   {}
    00144
    00145 } // vcsn
    00146
    00147 #endif // ! VCSN_DESIGN_PATTERN_SYNTACTIC_DECORATOR_HXX