Vaucanson  1.4.1
automata/concept/handlers.hxx
1 // handlers.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 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_AUTOMATA_CONCEPT_HANDLERS_HXX
18 # define VCSN_AUTOMATA_CONCEPT_HANDLERS_HXX
19 
20 # include <vaucanson/automata/concept/handlers.hh>
21 
22 namespace vcsn
23 {
24 
25  template<typename Tag, typename Type>
26  handler<Tag, Type>::handler() : v_(Type())
27  {}
28 
29  template<typename Tag, typename Type>
30  handler<Tag, Type>::handler(const Type& h) : v_(h)
31  {}
32 
33  template<typename Tag, typename Type>
34  handler<Tag, Type>::handler(const handler<Tag, Type>& h) : v_(h.v_)
35  {}
36 
37  template<typename Tag, typename Type>
38  handler<Tag, Type>&
39  handler<Tag, Type>::operator=(const handler<Tag, Type>& h)
40  {
41  v_ = h.v_;
42  return *this;
43  }
44 
45  template<typename Tag, typename Type>
46  Type handler<Tag, Type>::value() const
47  {
48  return v_;
49  }
50 
51  template<typename Tag, typename Type>
52  bool
53  handler<Tag, Type>::is_valid() const
54  {
55  return v_ != Type();
56  }
57 
58 } // vcsn
59 
60 #define HOPERATOR(Op) \
61 template<typename Tag, typename Type> \
62 bool operator Op (const handler<Tag, Type>& h1, \
63  const handler<Tag, Type>& h2) \
64 { return h1.value() Op h2.value(); }
65 
66 namespace vcsn {
67 HOPERATOR(==);
68 HOPERATOR(!=);
69 HOPERATOR(<);
70 HOPERATOR(>);
71 HOPERATOR(<=);
72 HOPERATOR(>=);
73 }
74 
75 namespace std {
76 
77  template <typename Tag, typename Type>
78  std::ostream&
79  operator<<(std::ostream& out, const vcsn::handler<Tag, Type>& h)
80  {
81  out << int(h);
82  return out;
83  }
84 
85 } // std
86 
87 #undef HOPERATOR
88 #endif // ! VCSN_AUTOMATA_CONCEPT_HANDLERS_HXX