Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 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 #ifndef MLN_ACCU_CONVOLVE_HH 00027 # define MLN_ACCU_CONVOLVE_HH 00028 00032 00033 # include <mln/accu/internal/base.hh> 00034 # include <mln/value/ops.hh> 00035 # include <mln/literal/zero.hh> 00036 00037 00038 namespace mln 00039 { 00040 00041 namespace accu 00042 { 00043 00044 00051 // 00052 template <typename T1, typename T2, 00053 typename R = mln_sum_product(T1, T2)> 00054 struct convolve : public mln::accu::internal::base< R, convolve<T1,T2,R> >, 00055 private metal::converts_to< mln_sum_product(T1, T2), 00056 R >::check_t 00057 { 00058 typedef std::pair<T1,T2> argument; 00059 00060 convolve(); 00061 00064 void init(); 00065 void take(const argument& t); 00066 void take(const T1& t1, const T2& t2); 00067 void take(const convolve<T1,T2,R>& other); 00069 00071 R to_result() const; 00072 00075 bool is_valid() const; 00076 00077 protected: 00078 00079 typedef mln_sum_product(T1, T2) S; 00080 S s_; 00081 }; 00082 00083 00084 # ifndef MLN_INCLUDE_ONLY 00085 00086 template <typename T1, typename T2, typename R> 00087 inline 00088 convolve<T1,T2,R>::convolve() 00089 { 00090 init(); 00091 } 00092 00093 template <typename T1, typename T2, typename R> 00094 inline 00095 void 00096 convolve<T1,T2,R>::init() 00097 { 00098 static S zero = literal::zero; 00099 s_ = zero; 00100 } 00101 00102 template <typename T1, typename T2, typename R> 00103 inline 00104 void 00105 convolve<T1,T2,R>::take(const argument& t) 00106 { 00107 s_ = static_cast<S>(s_ + static_cast<S>(t.first) * static_cast<S>(t.second)); 00108 } 00109 00110 template <typename T1, typename T2, typename R> 00111 inline 00112 void 00113 convolve<T1,T2,R>::take(const T1& t1, const T2& t2) 00114 { 00115 s_ = static_cast<S>(s_ + static_cast<S>(t1) * static_cast<S>(t2)); 00116 } 00117 00118 template <typename T1, typename T2, typename R> 00119 inline 00120 void 00121 convolve<T1,T2,R>::take(const convolve<T1,T2,R>& other) 00122 { 00123 s_ = static_cast<S>(s_ + other.s_); 00124 } 00125 00126 template <typename T1, typename T2, typename R> 00127 inline 00128 R 00129 convolve<T1,T2,R>::to_result() const 00130 { 00131 return s_; 00132 } 00133 00134 template <typename T1, typename T2, typename R> 00135 inline 00136 bool 00137 convolve<T1,T2,R>::is_valid() const 00138 { 00139 return true; 00140 } 00141 00142 # endif // ! MLN_INCLUDE_ONLY 00143 00144 } // end of namespace mln::accu 00145 00146 } // end of namespace mln 00147 00148 00149 #endif // ! MLN_ACCU_CONVOLVE_HH