Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2007, 2008, 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/value/gl8.hh> 00027 #include <mln/value/gl16.hh> 00028 #include <mln/value/glf.hh> 00029 00030 #include <mln/value/int_u8.hh> 00031 #include <mln/value/int_s8.hh> 00032 #include <mln/value/float01_f.hh> 00033 #include <mln/value/float01_.hh> 00034 00035 00036 #include <mln/literal/black.hh> 00037 #include <mln/literal/white.hh> 00038 00039 00040 00041 // FIXME: Give a more explicit error message. 00042 // template <typename T> 00043 // void foo() 00044 // { 00045 // typedef mln::value::gl8 g; 00046 // // mln_trait_op_times(int, mln::value::Integer<g>) tmp; 00047 // mln_trait_op_times(int, mln::value::Integer<g>) tmp; 00048 // } 00049 00050 00051 #define test_conversion(T1, T2, VAL) \ 00052 { \ 00053 (T1)(T2)(VAL); \ 00054 T1 test = (T2)(VAL); \ 00055 test = (T2)(VAL); \ 00056 } 00057 00058 int main() 00059 { 00060 using namespace mln::value; 00061 using namespace mln::value::internal; 00062 00063 using mln::literal::white; 00064 using mln::literal::black; 00065 00066 00067 // FIXME: Make all the test pass. 00068 00069 gl8 a(white); 00070 gl8 b(white); 00071 00072 a = b; 00073 mln_assertion(a == b); 00074 00075 { 00076 gl8 a(10); 00077 gl8 b(10); 00078 00079 gl8 c = a + b; 00080 } 00081 00082 { 00083 gl8 a(white); 00084 gl8 b(white); 00085 gl8 c; 00086 00087 // gl8 * int 00088 a * 2; 00089 2 * a; 00090 00091 00092 // gl8 * double 00093 a * 2.0; 00094 2.0 * a; 00095 00096 // gl8 * bool 00097 a * false; 00098 false * a; 00099 00100 // gl8 * Integer 00101 a * int_u8(23); 00102 int_u8(23) * a; 00103 00104 // gl8 * Floating 00105 a * float01_f(.23); 00106 float01_f(.23) * a; 00107 00108 float01_<16>(.23) * a; 00109 a * float01_<16>(.23); 00110 00111 00112 // gl8 / int 00113 a / 1.5; 00114 00115 // gl8 / double 00116 mln_assertion(a / 2.0 == glf(0.5)); 00117 00118 // gl8 / bool 00119 mln_assertion(a / true == a); 00120 00121 // gl8 / Integer 00122 /* FIXME: The compiler emits a warning about a comparison between 00123 signed and unsigned for the first line, but not for the second. 00124 This behavior is strange, since 00125 00126 a * int_u(23); 00127 00128 triggers no warning. See whether traits and conversions are 00129 handled symmetrically for `*' and `/'. */ 00130 a / int_u8(23); 00131 a / int_s8(23); 00132 00133 // gl8 / Floating 00134 a / float01_f(.23); 00135 a / float01_<16>(.23); 00136 } 00137 00138 { 00139 // Conversions. 00140 00141 typedef mln::value::internal::gray_<8> i_gray_8; 00142 test_conversion(gl8, i_gray_8, 255); 00143 00144 test_conversion(gl8, gray_f, 0.4); 00145 test_conversion(gl8, glf, 0.4); 00146 00147 test_conversion(glf, i_gray_8, 255); 00148 test_conversion(glf, gray_f, 0.4); 00149 test_conversion(glf, gl8, 142); 00150 00151 test_conversion(gray_f, i_gray_8, 4); 00152 test_conversion(glf, gray_f, 0.4); 00153 } 00154 00155 // { 00156 // // FIXME: comparison with literals doesn't work 00157 // c = a; 00158 // mln_assertion(c == white); 00159 00160 // c = (a * 2) / 2; 00161 // mln_assertion(c == white); 00162 00163 // c = c / 6; 00164 // } 00165 00166 // { 00167 // gl8 c = white; 00168 // mln_assertion(c == white); 00169 // mln_assertion(c.value() == float(255)); 00170 // } 00171 00172 }