https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Update Alex's mixin.
* abraham/mln/value/mixin.hh (F): Turn into plain type.
(mixin): New methods.
(operator<): New routine.
* abraham/tests/value/mixin.cc: Update.
mln/value/mixin.hh | 55 +++++++++++++++++++++++++++++++++++++++++++--------
tests/value/mixin.cc | 54 +++++++++++++++++++++++++++++++++++++++-----------
2 files changed, 90 insertions(+), 19 deletions(-)
Index: abraham/tests/value/mixin.cc
--- abraham/tests/value/mixin.cc (revision 2958)
+++ abraham/tests/value/mixin.cc (working copy)
@@ -39,26 +39,58 @@
namespace mln
{
- namespace value
- {
- template <unsigned int n>
- struct op_less< mln::value::rgb<n> >
+// namespace value
+// {
+// template <unsigned int n>
+// struct op_less< mln::value::rgb<n> >
+// {
+// bool operator()(const mln::value::rgb<n> &a, const
mln::value::rgb<n> &b)
+// {
+// return a.red() < b.red();
+// }
+// };
+// }
+
+ struct red_only
{
- bool operator()(const mln::value::rgb<n> &a, const
mln::value::rgb<n> &b)
+ template <unsigned n>
+ bool less(const value::rgb<n>& a, const value::rgb<n>& b)
{
return a.red() < b.red();
}
};
+
}
+
+
+template <typename T, typename A>
+const T& my_violent_cast(const A& a)
+{
+ return *(const T*)(const void*)(&a);
}
+
+template <typename T, typename A>
+T& my_violent_cast(A& a)
+{
+ return *(T*)(void*)(&a);
+}
+
+
int main ()
{
- mln::value::rgb8 r(12, 13, 14);
- mln::value::rgb8 s(13, 14, 15);
+ using namespace mln;
+
+ value::rgb8 r(12, 13, 14);
+ value::rgb8 s(13, 14, 15);
+
+ typedef value::mixin<value::rgb8,red_only> Rgb;
+
+ std::cout << ( my_violent_cast<Rgb>(r) < my_violent_cast<Rgb>(s) )
<< std::endl;
+
- std::cout
- << ( *(mln::value::mixin<mln::value::rgb8, mln::value::op_less>*)(void*)
&r <
- *(mln::value::mixin<mln::value::rgb8, mln::value::op_less>*)(void*) &s )
- << std::endl;
+// std::cout
+// << ( *(value::mixin<value::rgb8, value::op_less>*)(void*) &r <
+// *(value::mixin<value::rgb8, value::op_less>*)(void*) &s )
+// << std::endl;
}
Index: abraham/mln/value/mixin.hh
--- abraham/mln/value/mixin.hh (revision 2958)
+++ abraham/mln/value/mixin.hh (working copy)
@@ -35,16 +35,17 @@
namespace mln
{
+
namespace value
{
- template <typename T, template <typename> class F>
+ template <typename T, typename F>
struct mixin;
}
namespace trait
{
- template <typename T, template <typename> class F>
+ template <typename T, typename F>
struct value_< mln::value::mixin<T, F> >
: value_< T > // FIXME
{
@@ -52,23 +53,59 @@
} // end of namespace trait
+
namespace value
{
- template <typename T, template <typename> class F>
- struct mixin : T, Value < mixin<T, F> >, internal::value_like_ <T,
mln_enc(T), mixin<T, F>, mixin<T, F> >
+ template <typename T, typename F>
+ struct mixin : T // , Value < mixin<T, F> >, internal::value_like_ <T,
mln_enc(T), mixin<T, F>, mixin<T, F> >
+ {
+ // typedef T value;
+
+ mixin()
+ {
+ }
+
+ mixin(const T& t)
+ : T(t)
{
- typedef T value;
+ }
- // Ctor ?
+ mixin(const mixin& rhs)
+ : T(rhs)
+ {
+ }
- // operator (T) ();
+ mixin& operator=(const mixin& rhs)
+ {
+ // FIXME: (?) Test if (this == &rhs)...
+ this->T::operator=(rhs);
+ return *this;
+ }
+ mixin& operator=(const T& t)
+ {
+ // FIXME: (?) Test if (this == &t)...
+ this->T::operator=(t);
+ return *this;
+ }
};
+
+ } // end of namespace mln::value
+
+
+ template <typename T, typename F>
+ bool operator < (const value::mixin<T,F>& lhs, const
value::mixin<T,F>& rhs)
+ {
+ static F f;
+ return f.less(lhs, rhs);
}
+
+
# ifndef MLN_INCLUDE_ONLY
+ /*
namespace value
{
@@ -86,7 +123,7 @@
// Ctor
- // template <typename T, template <typename> class F>
+ // template <typename T, typename F>
// mixin<T, F>::operator(T)()
// {
// return (T)*this;
@@ -94,6 +131,8 @@
}
+*/
+
/*
template <typename F, typename I>
std::ostream& operator<<(std::ostream& ostr, value::shell<F, I>
&s)