00001 // Copyright (C) 2007, 2008, 2009, 2011 EPITA Research and Development 00002 // Laboratory (LRDE) 00003 // 00004 // This file is part of Olena. 00005 // 00006 // Olena is free software: you can redistribute it and/or modify it under 00007 // the terms of the GNU General Public License as published by the Free 00008 // Software Foundation, version 2 of the License. 00009 // 00010 // Olena is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 // General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Olena. If not, see <http://www.gnu.org/licenses/>. 00017 // 00018 // As a special exception, you may use this file as part of a free 00019 // software project without restriction. Specifically, if other files 00020 // instantiate templates or use macros or inline functions from this 00021 // file, or you compile this file and link it with other files to produce 00022 // an executable, this file does not by itself cause the resulting 00023 // executable to be covered by the GNU General Public License. This 00024 // exception does not however invalidate any other reasons why the 00025 // executable file might be covered by the GNU General Public License. 00026 00027 #ifndef MLN_CORE_CONCEPT_FUNCTION_HH 00028 # define MLN_CORE_CONCEPT_FUNCTION_HH 00029 00033 00034 # include <mln/core/concept/object.hh> 00035 00036 00037 namespace mln 00038 { 00039 00040 // Forward declarations. 00041 template <typename E> struct Function; 00042 template <typename E> struct Function_n2v; 00043 template <typename E> struct Function_v2v; 00044 template <typename E> struct Function_v2b; 00045 template <typename E> struct Function_vv2v; 00046 template <typename E> struct Function_vv2b; 00047 00048 00050 template <> 00051 struct Function<void> 00052 { 00053 typedef Object<void> super; 00054 }; 00055 00056 00062 // 00063 template <typename E> 00064 struct Function : public Object<E> 00065 { 00066 typedef Function<void> category; 00067 00070 00071 protected: 00072 Function(); 00073 Function(const Function&); 00074 00075 /* Workaround for Apple's llvm-gcc 4.2.1 (Mac OS X Lion 10.7.1) 00076 00077 Apple's llvm-gcc has a bug causing memmove() errors if the copy 00078 constructor is not declared along with operator=(). */ 00079 Function<E>& operator=(const Function<E>&); 00080 }; 00081 00082 00083 /*---------------. 00084 | Nil -> Value. | 00085 `---------------*/ 00086 00087 template <> 00088 struct Function_n2v<void> { typedef Function<void> super; }; 00089 00090 00097 // 00098 template <typename E> 00099 struct Function_n2v : public Function<E> 00100 { 00101 typedef Function_n2v<void> category; 00102 protected: 00103 Function_n2v(); 00104 Function_n2v(const Function_n2v&); 00105 }; 00106 00107 00108 /*-----------------. 00109 | Value -> Value. | 00110 `-----------------*/ 00111 00112 template <> 00113 struct Function_v2v<void> { typedef Function<void> super; }; 00114 00115 00122 // 00123 template <typename E> 00124 struct Function_v2v : public Function<E> 00125 { 00126 typedef Function_v2v<void> category; 00127 typedef void mutable_result; // Meaning: no mutable result by default. 00128 protected: 00129 Function_v2v(); 00130 Function_v2v(const Function_v2v&); 00131 }; 00132 00133 00134 /*----------------. 00135 | Value -> bool. | 00136 `----------------*/ 00137 00138 template <> 00139 struct Function_v2b<void> { typedef Function_v2v<void> super; }; 00140 00141 00148 // 00149 template <typename E> 00150 struct Function_v2b : public virtual Function_v2v<E> 00151 { 00152 typedef Function_v2b<void> category; 00153 typedef bool result; 00154 protected: 00155 Function_v2b(); 00156 Function_v2b(const Function_v2b&); 00157 }; 00158 00159 00160 00161 /*--------------------------. 00162 | (Value, Value) -> Value. | 00163 `--------------------------*/ 00164 00165 template <> 00166 struct Function_vv2v<void> { typedef Function<void> super; }; 00167 00168 00175 // 00176 template <typename E> 00177 struct Function_vv2v : public Function<E> 00178 { 00179 typedef Function_vv2v<void> category; 00180 protected: 00181 Function_vv2v(); 00182 Function_vv2v(const Function_vv2v&); 00183 }; 00184 00185 00186 /*--------------------------. 00187 | (Value, Value) -> Boolean.| 00188 `--------------------------*/ 00189 00190 template <> 00191 struct Function_vv2b<void> { typedef Function<void> super; }; 00192 00193 00200 // 00201 template <typename E> 00202 struct Function_vv2b : public Function<E> 00203 { 00204 typedef bool result; 00205 typedef Function_vv2b<void> category; 00206 protected: 00207 Function_vv2b(); 00208 Function_vv2b(const Function_vv2b&); 00209 }; 00210 00211 00212 00213 # ifndef MLN_INCLUDE_ONLY 00214 00215 // Function. 00216 00217 template <typename E> 00218 inline 00219 Function<E>::Function() 00220 { 00221 typedef mln_result(E) result; 00222 } 00223 00224 template <typename E> 00225 inline 00226 Function<E>::Function(const Function<E>& rhs) 00227 : Object<E>(rhs) 00228 { 00229 } 00230 00231 template <typename E> 00232 inline 00233 Function<E>& 00234 Function<E>::operator=(const Function<E>&) 00235 { 00236 return *this; 00237 } 00238 00239 // Function_n2v. 00240 00241 template <typename E> 00242 inline 00243 Function_n2v<E>::Function_n2v() 00244 { 00245 } 00246 00247 template <typename E> 00248 inline 00249 Function_n2v<E>::Function_n2v(const Function_n2v<E>& rhs) 00250 : Function<E>(rhs) 00251 { 00252 } 00253 00254 00255 // Function_v2v. 00256 00257 template <typename E> 00258 inline 00259 Function_v2v<E>::Function_v2v() 00260 { 00261 } 00262 00263 template <typename E> 00264 inline 00265 Function_v2v<E>::Function_v2v(const Function_v2v<E>& rhs) 00266 : Function<E>(rhs) 00267 { 00268 } 00269 00270 // Function_v2b. 00271 00272 template <typename E> 00273 inline 00274 Function_v2b<E>::Function_v2b() 00275 { 00276 } 00277 00278 template <typename E> 00279 inline 00280 Function_v2b<E>::Function_v2b(const Function_v2b<E>& rhs) 00281 : Function_v2v<E>(rhs) 00282 { 00283 } 00284 00285 // Function_vv2v. 00286 00287 template <typename E> 00288 inline 00289 Function_vv2v<E>::Function_vv2v() 00290 { 00291 } 00292 00293 template <typename E> 00294 inline 00295 Function_vv2v<E>::Function_vv2v(const Function_vv2v<E>& rhs) 00296 : Function<E>(rhs) 00297 { 00298 } 00299 00300 // Function_vv2b. 00301 00302 template <typename E> 00303 inline 00304 Function_vv2b<E>::Function_vv2b() 00305 { 00306 } 00307 00308 template <typename E> 00309 inline 00310 Function_vv2b<E>::Function_vv2b(const Function_vv2b<E>& rhs) 00311 : Function<E>(rhs) 00312 { 00313 } 00314 00315 # endif // ! MLN_INCLUDE_ONLY 00316 00317 } // end of namespace mln 00318 00319 00320 #endif // ! MLN_CORE_CONCEPT_FUNCTION_HH