• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

comp.cc

00001 // Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
00002 //
00003 // This file is part of Olena.
00004 //
00005 // Olena is free software: you can redistribute it and/or modify it under
00006 // the terms of the GNU General Public License as published by the Free
00007 // Software Foundation, version 2 of the License.
00008 //
00009 // Olena is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 // As a special exception, you may use this file as part of a free
00018 // software project without restriction.  Specifically, if other files
00019 // instantiate templates or use macros or inline functions from this
00020 // file, or you compile this file and link it with other files to produce
00021 // an executable, this file does not by itself cause the resulting
00022 // executable to be covered by the GNU General Public License.  This
00023 // exception does not however invalidate any other reasons why the
00024 // executable file might be covered by the GNU General Public License.
00025 
00026 #include <mln/trait/value/comp.hh>
00027 
00028 #include <mln/value/int_u8.hh>
00029 #include <mln/algebra/vec.hh>
00030 
00031 
00032 
00033 
00034 template <typename T, unsigned i, typename C>
00035 void check_equal()
00036 {
00037   mlc_equal(mln_trait_value_comp(T, i), C)::check();
00038 }
00039 
00040 
00041 template <typename T>
00042 void check_scalar()
00043 {
00044   mlc_equal(mln_trait_value_comp(T, 0), T)::check();
00045 }
00046 
00047 
00048 template <typename T, typename C>
00049 void check_homogeneous()
00050 {
00051   mlc_equal(mln_trait_value_comp(T, 0), C)::check();
00052 }
00053 
00054 
00055 namespace mln
00056 {
00057 
00058   template <typename R, typename G, typename B>
00059   struct my_rgb;
00060 
00061   namespace trait
00062   {
00063 
00064     template <typename R, typename G, typename B>
00065     struct value_< my_rgb<R,G,B> >
00066     {
00067       enum { dim = 3 };
00068       typedef void comp;
00069       typedef R comp_0;
00070       typedef G comp_1;
00071       typedef B comp_2;
00072     };
00073 
00074   } // mln::trait
00075 
00076 } // mln
00077 
00078 
00079 
00080 template <typename T,
00081           typename C0, typename C1, typename C2>
00082 void check_heterogeneous()
00083 {
00084   mlc_equal(mln_trait_value_comp(T, 0), C0)::check();
00085   mlc_equal(mln_trait_value_comp(T, 1), C1)::check();
00086   mlc_equal(mln_trait_value_comp(T, 2), C2)::check();
00087 }
00088 
00089 
00090 
00091 int main()
00092 {
00093   using namespace mln;
00094 
00095 
00096   // Scalars.
00097 
00098   {
00099     typedef mln::value::int_u8 T;
00100     check_scalar<T>();
00101     check_equal<T, 0, T>();
00102   }
00103   {
00104     typedef int T;
00105     check_scalar<T>();
00106     check_equal<T, 0, T>();
00107   }
00108 
00109 
00110   // Homogeneous vectors.
00111 
00112   {
00113     typedef float C;
00114     typedef algebra::vec<2, C> T;
00115     check_homogeneous< T, C >();
00116     check_equal< T, 0, C >();
00117     check_equal< T, 1, C >();
00118   }
00119   {
00120     typedef double C;
00121     typedef C T[2];
00122     check_homogeneous< T, C >();
00123     check_equal< T, 0, C >();
00124     check_equal< T, 1, C >();
00125   }
00126 
00127 
00128   // Heterogeneous types.
00129 
00130   {
00131     check_heterogeneous< my_rgb< bool, unsigned, float* >,
00132                                  bool, unsigned, float* >();
00133   }
00134 }

Generated on Tue Oct 4 2011 15:23:35 for Milena (Olena) by  doxygen 1.7.1