Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
value_like.hh
1 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 #ifndef MLN_VALUE_INTERNAL_VALUE_LIKE_HH
27 # define MLN_VALUE_INTERNAL_VALUE_LIKE_HH
28 
32 
33 # include <mln/core/concept/value.hh>
34 # include <mln/core/internal/force_exact.hh>
35 
36 
37 namespace mln
38 {
39 
40  namespace value
41  {
42 
43  namespace internal
44  {
45 
50  template < typename V, // Equivalent.
51  typename C, // Encoding.
52  typename N, // Interoperation.
53  typename E >
54  struct value_like_ // FIXME :Remove -> : public Value<E>
55  {
57  typedef V equiv;
58 
60  typedef C enc;
61 
63  typedef N interop;
64 
66  V to_equiv() const;
67 
69  const C& to_enc() const;
70 
72  N to_interop() const;
73 
74 
75  // Handle to encoding value.
76  C& handle_() { return v_; }
77 
78  protected:
79  enc v_;
80  };
81 
82 
86  template <typename V, typename C, typename N, typename E>
87  bool operator==(const value_like_<V,C,N,E>& lhs, const value_like_<V,C,N,E>& rhs);
88 
89 
93  template <typename V, typename C, typename N, typename E>
94  bool operator<(const value_like_<V,C,N,E>& lhs, const value_like_<V,C,N,E>& rhs);
95 
96 
97 # ifndef MLN_INCLUDE_ONLY
98 
99  template <typename V, typename C, typename N, typename E>
100  inline
101  V
102  value_like_<V,C,N,E>::to_equiv() const
103  {
104  return v_;
105  }
106 
107  template <typename V, typename C, typename N, typename E>
108  inline
109  const C&
110  value_like_<V,C,N,E>::to_enc() const
111  {
112  return v_;
113  }
114 
115  template <typename V, typename C, typename N, typename E>
116  inline
117  N
118  value_like_<V,C,N,E>::to_interop() const
119  {
120  return static_cast<N>(mln::internal::force_exact<E>(*this));
121  }
122 
123  template <typename V, typename C, typename N, typename E>
124  inline
125  bool operator==(const value_like_<V,C,N,E>& lhs,
126  const value_like_<V,C,N,E>& rhs)
127  {
128  return lhs.to_enc() == rhs.to_enc();
129  }
130 
131  template <typename V, typename C, typename N, typename E>
132  inline
133  bool operator<(const value_like_<V,C,N,E>& lhs,
134  const value_like_<V,C,N,E>& rhs)
135  {
136  return lhs.to_interop() < rhs.to_interop(); // FIXME HERE: Why interop?
137  }
138 
139 # endif // ! MLN_INCLUDE_ONLY
140 
141  } // end of namespace mln::value::internal
142 
143  } // end of namespace mln::value
144 
145 } // end of namespace mln
146 
147 
148 #endif // ! MLN_VALUE_INTERNAL_VALUE_LIKE_HH