basix_doc 0.1
|
00001 00002 /****************************************************************************** 00003 * MODULE : function.hpp 00004 * DESCRIPTION: Function classes for any arity 00005 * COPYRIGHT : (C) 2007 Joris van der Hoeven 00006 ******************************************************************************* 00007 * This software falls under the GNU general public license and comes WITHOUT 00008 * ANY WARRANTY WHATSOEVER. See the file $TEXMACS_PATH/LICENSE for more details. 00009 * If you don't have this file, write to the Free Software Foundation, Inc., 00010 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00011 ******************************************************************************/ 00012 00013 #ifndef __MMX_FUNCTION_HPP 00014 #define __MMX_FUNCTION_HPP 00015 #include <basix/operators.hpp> 00016 00017 namespace mmx { 00018 00019 template<typename T> inline syntactic flatten_type () { 00020 return as_syntactic (type_name (type_information<T>::id)); } 00021 00022 /****************************************************************************** 00023 * Add const& to function arguments 00024 ******************************************************************************/ 00025 00026 template<typename T> 00027 struct argument_helper { 00028 typedef const T& arg_type; 00029 }; 00030 00031 template<typename T> 00032 struct argument_helper<T&> { 00033 typedef T& arg_type; 00034 }; 00035 00036 template<typename T> 00037 struct argument_helper<T*> { 00038 typedef T* arg_type; 00039 }; 00040 00041 template<typename T> 00042 struct argument_helper<const T&> { 00043 typedef const T& arg_type; 00044 }; 00045 00046 template<typename T> 00047 struct argument_helper<const T*> { 00048 typedef const T* arg_type; 00049 }; 00050 00051 #ifdef OPTIMIZED_ARGUMENTS 00052 #define Argument(T) typename argument_helper<T>::arg_type 00053 #else 00054 #define Argument(T) T 00055 #endif 00056 00057 /****************************************************************************** 00058 * Nullary functions 00059 ******************************************************************************/ 00060 00061 template<typename D> 00062 struct function_0_rep REP_STRUCT { 00063 inline function_0_rep () {} 00064 virtual ~function_0_rep () {} 00065 virtual D apply () = 0; 00066 }; 00067 00068 template<typename D> 00069 struct def_function_0_rep: public function_0_rep<D> { 00070 D (*fun) (); 00071 inline def_function_0_rep (D (*fun2) ()): fun (fun2) {} 00072 D apply () { return fun (); } 00073 }; 00074 00075 template<typename D> 00076 struct function_0 { 00077 function_0_rep<D>* rep; 00078 inline function_0 (): rep (NULL) {} 00079 inline function_0 (function_0_rep<D>* rep2): rep (rep2) {} 00080 inline function_0 (const function_0& f): 00081 rep (f.rep) { INC_NULL_COUNT(rep); } 00082 inline function_0 (D (*fun) ()): 00083 rep (new def_function_0_rep<D> (fun)) {} 00084 inline ~function_0 () { DEC_NULL_COUNT (rep); } 00085 inline function_0& operator = (const function_0& f) { 00086 INC_NULL_COUNT (f.rep); DEC_NULL_COUNT (rep); 00087 rep= f.rep; return *this; } 00088 inline D operator () () const { return rep->apply (); } 00089 }; 00090 00091 #define TMPL template<typename D> 00092 #define Function function_0<D> 00093 TMPL inline syntactic flatten (const Function& f) { 00094 return apply ("function", flatten_type<D> ()); } 00095 TMPL inline nat hard_hash (const Function& f) { 00096 return as_hash (f.rep); } 00097 TMPL inline bool hard_eq (const Function& f, const Function& g) { 00098 return (f.rep) == (g.rep); } 00099 TMPL inline bool hard_neq (const Function& f, const Function& g) { 00100 return (f.rep) != (g.rep); } 00101 HARD_TO_EXACT_IDENTITY_SUGAR(TMPL,Function) 00102 HARD_TO_TRUE_IDENTITY_SUGAR(TMPL,Function) 00103 #undef Function 00104 #undef TMPL 00105 00106 /****************************************************************************** 00107 * Unary functions 00108 ******************************************************************************/ 00109 00110 template<typename D, typename S1> 00111 struct function_1_rep REP_STRUCT { 00112 inline function_1_rep () {} 00113 virtual ~function_1_rep () {} 00114 virtual D apply (S1 x1) = 0; 00115 }; 00116 00117 template<typename D, typename S1> 00118 struct def_function_1_rep: public function_1_rep<D,S1> { 00119 D (*fun) (S1); 00120 inline def_function_1_rep (D (*fun2) (S1)): fun (fun2) {} 00121 D apply (S1 x1) { return fun (x1); } 00122 }; 00123 00124 template<typename D, typename S1> 00125 struct function_1 { 00126 function_1_rep<D,S1>* rep; 00127 inline function_1 (): rep (NULL) {} 00128 inline function_1 (function_1_rep<D,S1>* rep2): rep (rep2) {} 00129 inline function_1 (const function_1& f): 00130 rep (f.rep) { INC_NULL_COUNT(rep); } 00131 inline function_1 (D (*fun) (S1)): 00132 rep (new def_function_1_rep<D,S1> (fun)) {} 00133 inline ~function_1 () { DEC_NULL_COUNT (rep); } 00134 inline function_1& operator = (const function_1& f) { 00135 INC_NULL_COUNT (f.rep); DEC_NULL_COUNT (rep); 00136 rep= f.rep; return *this; } 00137 inline D operator () (S1 x1) const { return rep->apply (x1); } 00138 }; 00139 00140 #define TMPL template<typename D, typename S1> 00141 #define Function function_1<D,S1> 00142 TMPL inline syntactic flatten (const Function& f) { 00143 return apply ("function", flatten_type<S1> (), flatten_type<D> ()); } 00144 TMPL inline nat hard_hash (const Function& f) { 00145 return as_hash (f.rep); } 00146 TMPL inline bool hard_eq (const Function& f, const Function& g) { 00147 return (f.rep) == (g.rep); } 00148 TMPL inline bool hard_neq (const Function& f, const Function& g) { 00149 return (f.rep) != (g.rep); } 00150 HARD_TO_EXACT_IDENTITY_SUGAR(TMPL,Function) 00151 HARD_TO_TRUE_IDENTITY_SUGAR(TMPL,Function) 00152 #undef Function 00153 #undef TMPL 00154 00155 template<typename FT, typename R, typename C, typename Fun> 00156 struct format_function_helper { 00157 static inline format<R> 00158 op (const Fun& fun, const format<C>& fm) { 00159 return get_format (fun (get_sample (fm))); } 00160 }; 00161 00162 template<typename FT, typename C, typename Fun> 00163 struct format_function_helper<FT,C,C,Fun> { 00164 static inline format<C> 00165 op (const Fun&, const format<C>& fm) { 00166 return fm; } 00167 }; 00168 00169 template<typename R, typename C, typename Fun> 00170 struct format_function_helper<empty_format,R,C,Fun> { 00171 static inline format<R> 00172 op (const Fun& fun, const format<C>&) { 00173 return format<R> (); } 00174 }; 00175 00176 template<typename C, typename Fun> 00177 struct format_function_helper<empty_format,C,C,Fun> { 00178 static inline format<C> 00179 op (const Fun&, const format<C>& fm) { 00180 return fm; } 00181 }; 00182 00183 template<typename C, typename R> format<R> 00184 map (const function_1<R,Argument(C) >& fun, const format<C>& fm) { 00185 typedef function_1<R,Argument(C) > Fun; 00186 typedef typename format<R>::FT FT; 00187 return format_function_helper<FT,R,C,Fun>::op (fun, fm); 00188 } 00189 00190 template<typename C, typename R> format<R> 00191 map (R (*fun) (const C&), const format<C>& fm) { 00192 typedef R (*Fun) (const C&); 00193 typedef typename format<R>::FT FT; 00194 return format_function_helper<FT,R,C,Fun>::op (fun, fm); 00195 } 00196 00197 /****************************************************************************** 00198 * Binary functions 00199 ******************************************************************************/ 00200 00201 template<typename D, typename S1, typename S2> 00202 struct function_2_rep REP_STRUCT { 00203 inline function_2_rep () {} 00204 virtual ~function_2_rep () {} 00205 virtual D apply (S1 x1, S2 x2) = 0; 00206 }; 00207 00208 template<typename D, typename S1, typename S2> 00209 struct def_function_2_rep: public function_2_rep<D,S1,S2> { 00210 D (*fun) (S1, S2); 00211 inline def_function_2_rep (D (*fun2) (S1, S2)): fun (fun2) {} 00212 D apply (S1 x1, S2 x2) { return fun (x1, x2); } 00213 }; 00214 00215 template<typename D, typename S1, typename S2> 00216 struct function_2 { 00217 function_2_rep<D,S1,S2>* rep; 00218 inline function_2 (): rep (NULL) {} 00219 inline function_2 (function_2_rep<D,S1,S2>* rep2): rep (rep2) {} 00220 inline function_2 (const function_2& f): 00221 rep (f.rep) { INC_NULL_COUNT(rep); } 00222 inline function_2 (D (*fun) (S1, S2)): 00223 rep (new def_function_2_rep<D,S1,S2> (fun)) {} 00224 inline ~function_2 () { DEC_NULL_COUNT (rep); } 00225 inline function_2& operator = (const function_2& f) { 00226 INC_NULL_COUNT (f.rep); DEC_NULL_COUNT (rep); 00227 rep= f.rep; return *this; } 00228 inline D operator () (S1 x1, S2 x2) const { 00229 return rep->apply (x1, x2); } 00230 }; 00231 00232 #define TMPL template<typename D, typename S1, typename S2> 00233 #define Function function_2<D,S1,S2> 00234 TMPL inline syntactic flatten (const Function& f) { 00235 return apply ("function", 00236 flatten_type<S1> (), flatten_type<S2> (), flatten_type<D> ()); } 00237 TMPL inline nat hard_hash (const Function& f) { 00238 return as_hash (f.rep); } 00239 TMPL inline bool hard_eq (const Function& f, const Function& g) { 00240 return (f.rep) == (g.rep); } 00241 TMPL inline bool hard_neq (const Function& f, const Function& g) { 00242 return (f.rep) != (g.rep); } 00243 HARD_TO_EXACT_IDENTITY_SUGAR(TMPL,Function) 00244 HARD_TO_TRUE_IDENTITY_SUGAR(TMPL,Function) 00245 #undef Function 00246 #undef TMPL 00247 00248 /****************************************************************************** 00249 * Ternary functions 00250 ******************************************************************************/ 00251 00252 template<typename D, typename S1, typename S2, typename S3> 00253 struct function_3_rep REP_STRUCT { 00254 inline function_3_rep () {} 00255 virtual ~function_3_rep () {} 00256 virtual D apply (S1 x1, S2 x2, S3 x3) = 0; 00257 }; 00258 00259 template<typename D, typename S1, typename S2, typename S3> 00260 struct def_function_3_rep: public function_3_rep<D,S1,S2,S3> { 00261 D (*fun) (S1, S2, S3); 00262 inline def_function_3_rep (D (*fun2) (S1, S2, S3)): 00263 fun (fun2) {} 00264 D apply (S1 x1, S2 x2, S3 x3) { 00265 return fun (x1, x2, x3); } 00266 }; 00267 00268 template<typename D, typename S1, typename S2, typename S3> 00269 struct function_3 { 00270 function_3_rep<D,S1,S2,S3>* rep; 00271 inline function_3 (): rep (NULL) {} 00272 inline function_3 (function_3_rep<D,S1,S2,S3>* rep2): rep (rep2) {} 00273 inline function_3 (const function_3& f): 00274 rep (f.rep) { INC_NULL_COUNT(rep); } 00275 inline function_3 (D (*fun) (S1, S2, S3)): 00276 rep (new def_function_3_rep<D,S1,S2,S3> (fun)) {} 00277 inline ~function_3 () { DEC_NULL_COUNT (rep); } 00278 inline function_3& operator = (const function_3& f) { 00279 INC_NULL_COUNT (f.rep); DEC_NULL_COUNT (rep); 00280 rep= f.rep; return *this; } 00281 inline D operator () (S1 x1, S2 x2, S3 x3) const { 00282 return rep->apply (x1, x2, x3); } 00283 }; 00284 00285 #define TMPL template<typename D, typename S1, typename S2, typename S3> 00286 #define Function function_3<D,S1,S2,S3> 00287 TMPL inline syntactic flatten (const Function& f) { 00288 return "function"; } 00289 TMPL inline nat hard_hash (const Function& f) { 00290 return as_hash (f.rep); } 00291 TMPL inline bool hard_eq (const Function& f, const Function& g) { 00292 return (f.rep) == (g.rep); } 00293 TMPL inline bool hard_neq (const Function& f, const Function& g) { 00294 return (f.rep) != (g.rep); } 00295 HARD_TO_EXACT_IDENTITY_SUGAR(TMPL,Function) 00296 HARD_TO_TRUE_IDENTITY_SUGAR(TMPL,Function) 00297 #undef Function 00298 #undef TMPL 00299 00300 /****************************************************************************** 00301 * Tetragonal functions 00302 ******************************************************************************/ 00303 00304 template<typename D, typename S1, typename S2, typename S3, typename S4> 00305 struct function_4_rep REP_STRUCT { 00306 inline function_4_rep () {} 00307 virtual ~function_4_rep () {} 00308 virtual D apply (S1 x1, S2 x2, S3 x3, S4 x4) = 0; 00309 }; 00310 00311 template<typename D, typename S1, typename S2, typename S3, typename S4> 00312 struct def_function_4_rep: public function_4_rep<D,S1,S2,S3,S4> { 00313 D (*fun) (S1, S2, S3, S4); 00314 inline def_function_4_rep (D (*fun2) (S1, S2, S3, S4)): 00315 fun (fun2) {} 00316 D apply (S1 x1, S2 x2, S3 x3, S4 x4) { 00317 return fun (x1, x2, x3, x4); } 00318 }; 00319 00320 template<typename D, typename S1, typename S2, typename S3, typename S4> 00321 struct function_4 { 00322 function_4_rep<D,S1,S2,S3,S4>* rep; 00323 inline function_4 (): rep (NULL) {} 00324 inline function_4 (function_4_rep<D,S1,S2,S3,S4>* rep2): rep (rep2) {} 00325 inline function_4 (const function_4& f): 00326 rep (f.rep) { INC_NULL_COUNT(rep); } 00327 inline function_4 (D (*fun) (S1, S2, S3, S4)): 00328 rep (new def_function_4_rep<D,S1,S2,S3,S4> (fun)) {} 00329 inline ~function_4 () { DEC_NULL_COUNT (rep); } 00330 inline function_4& operator = (const function_4& f) { 00331 INC_NULL_COUNT (f.rep); DEC_NULL_COUNT (rep); 00332 rep= f.rep; return *this; } 00333 inline D operator () (S1 x1, S2 x2, S3 x3, S4 x4) const { 00334 return rep->apply (x1, x2, x3, x4); } 00335 }; 00336 00337 #define TMPL template<typename D, typename S1, typename S2, typename S3, typename S4> 00338 #define Function function_4<D,S1,S2,S3,S4> 00339 TMPL inline syntactic flatten (const Function& f) { 00340 return "function"; } 00341 TMPL inline nat hard_hash (const Function& f) { 00342 return as_hash (f.rep); } 00343 TMPL inline bool hard_eq (const Function& f, const Function& g) { 00344 return (f.rep) == (g.rep); } 00345 TMPL inline bool hard_neq (const Function& f, const Function& g) { 00346 return (f.rep) != (g.rep); } 00347 HARD_TO_EXACT_IDENTITY_SUGAR(TMPL,Function) 00348 HARD_TO_TRUE_IDENTITY_SUGAR(TMPL,Function) 00349 #undef Function 00350 #undef TMPL 00351 00352 /****************************************************************************** 00353 * Pentagonal functions 00354 ******************************************************************************/ 00355 00356 template<typename D, typename S1, typename S2, typename S3, typename S4, typename S5> 00357 struct function_5_rep REP_STRUCT { 00358 inline function_5_rep () {} 00359 virtual ~function_5_rep () {} 00360 virtual D apply (S1 x1, S2 x2, S3 x3, S4 x4, S5 x5) = 0; 00361 }; 00362 00363 template<typename D, typename S1, typename S2, typename S3, typename S4, typename S5> 00364 struct def_function_5_rep: public function_5_rep<D,S1,S2,S3,S4,S5> { 00365 D (*fun) (S1, S2, S3, S4, S5); 00366 inline def_function_5_rep (D (*fun2) (S1, S2, S3, S4, S5)): 00367 fun (fun2) {} 00368 D apply (S1 x1, S2 x2, S3 x3, S4 x4, S5 x5) { 00369 return fun (x1, x2, x3, x4, x5); } 00370 }; 00371 00372 template<typename D, typename S1, typename S2, typename S3, typename S4, typename S5> 00373 struct function_5 { 00374 function_5_rep<D,S1,S2,S3,S4,S5>* rep; 00375 inline function_5 (): rep (NULL) {} 00376 inline function_5 (function_5_rep<D,S1,S2,S3,S4,S5>* rep2): rep (rep2) {} 00377 inline function_5 (const function_5& f): 00378 rep (f.rep) { INC_NULL_COUNT(rep); } 00379 inline function_5 (D (*fun) (S1, S2, S3, S4, S5)): 00380 rep (new def_function_5_rep<D,S1,S2,S3,S4,S5> (fun)) {} 00381 inline ~function_5 () { DEC_NULL_COUNT (rep); } 00382 inline function_5& operator = (const function_5& f) { 00383 INC_NULL_COUNT (f.rep); DEC_NULL_COUNT (rep); 00384 rep= f.rep; return *this; } 00385 inline D operator () (S1 x1, S2 x2, S3 x3, S4 x4, S5 x5) const { 00386 return rep->apply (x1, x2, x3, x4, x5); } 00387 }; 00388 00389 #define TMPL template<typename D, typename S1, typename S2, typename S3, typename S4, typename S5> 00390 #define Function function_5<D,S1,S2,S3,S4,S5> 00391 TMPL inline syntactic flatten (const Function& f) { 00392 return "function"; } 00393 TMPL inline nat hard_hash (const Function& f) { 00394 return as_hash (f.rep); } 00395 TMPL inline bool hard_eq (const Function& f, const Function& g) { 00396 return (f.rep) == (g.rep); } 00397 TMPL inline bool hard_neq (const Function& f, const Function& g) { 00398 return (f.rep) != (g.rep); } 00399 HARD_TO_EXACT_IDENTITY_SUGAR(TMPL,Function) 00400 HARD_TO_TRUE_IDENTITY_SUGAR(TMPL,Function) 00401 #undef Function 00402 #undef TMPL 00403 00404 /****************************************************************************** 00405 * Hexagonal functions 00406 ******************************************************************************/ 00407 00408 template<typename D, typename S1, typename S2, typename S3, typename S4, typename S5, typename S6> 00409 struct function_6_rep REP_STRUCT { 00410 inline function_6_rep () {} 00411 virtual ~function_6_rep () {} 00412 virtual D apply (S1 x1, S2 x2, S3 x3, S4 x4, S5 x5, S6 x6) = 0; 00413 }; 00414 00415 template<typename D, typename S1, typename S2, typename S3, typename S4, typename S5, typename S6> 00416 struct def_function_6_rep: public function_6_rep<D,S1,S2,S3,S4,S5,S6> { 00417 D (*fun) (S1, S2, S3, S4, S5, S6); 00418 inline def_function_6_rep (D (*fun2) (S1, S2, S3, S4, S5, S6)): 00419 fun (fun2) {} 00420 D apply (S1 x1, S2 x2, S3 x3, S4 x4, S5 x5, S6 x6) { 00421 return fun (x1, x2, x3, x4, x5, x6); } 00422 }; 00423 00424 template<typename D, typename S1, typename S2, typename S3, typename S4, typename S5, typename S6> 00425 struct function_6 { 00426 function_6_rep<D,S1,S2,S3,S4,S5,S6>* rep; 00427 inline function_6 (): rep (NULL) {} 00428 inline function_6 (function_6_rep<D,S1,S2,S3,S4,S5,S6>* rep2): rep (rep2) {} 00429 inline function_6 (const function_6& f): 00430 rep (f.rep) { INC_NULL_COUNT(rep); } 00431 inline function_6 (D (*fun) (S1, S2, S3, S4, S5, S6)): 00432 rep (new def_function_6_rep<D,S1,S2,S3,S4,S5,S6> (fun)) {} 00433 inline ~function_6 () { DEC_NULL_COUNT (rep); } 00434 inline function_6& operator = (const function_6& f) { 00435 INC_NULL_COUNT (f.rep); DEC_NULL_COUNT (rep); 00436 rep= f.rep; return *this; } 00437 inline D operator () (S1 x1, S2 x2, S3 x3, S4 x4, S5 x5, S6 x6) const { 00438 return rep->apply (x1, x2, x3, x4, x5, x6); } 00439 }; 00440 00441 #define TMPL template<typename D, typename S1, typename S2, typename S3, typename S4, typename S5, typename S6> 00442 #define Function function_6<D,S1,S2,S3,S4,S5,S6> 00443 TMPL inline syntactic flatten (const Function& f) { 00444 return "function"; } 00445 TMPL inline nat hard_hash (const Function& f) { 00446 return as_hash (f.rep); } 00447 TMPL inline bool hard_eq (const Function& f, const Function& g) { 00448 return (f.rep) == (g.rep); } 00449 TMPL inline bool hard_neq (const Function& f, const Function& g) { 00450 return (f.rep) != (g.rep); } 00451 HARD_TO_EXACT_IDENTITY_SUGAR(TMPL,Function) 00452 HARD_TO_TRUE_IDENTITY_SUGAR(TMPL,Function) 00453 #undef Function 00454 #undef TMPL 00455 00456 /****************************************************************************** 00457 * Heptagonal functions 00458 ******************************************************************************/ 00459 00460 template<typename D, typename S1, typename S2, typename S3, typename S4, typename S5, typename S6, typename S7> 00461 struct function_7_rep REP_STRUCT { 00462 inline function_7_rep () {} 00463 virtual ~function_7_rep () {} 00464 virtual D apply (S1 x1, S2 x2, S3 x3, S4 x4, S5 x5, S6 x6, S7 x7) = 0; 00465 }; 00466 00467 template<typename D, typename S1, typename S2, typename S3, typename S4, typename S5, typename S6, typename S7> 00468 struct def_function_7_rep: public function_7_rep<D,S1,S2,S3,S4,S5,S6,S7> { 00469 D (*fun) (S1, S2, S3, S4, S5, S6, S7); 00470 inline def_function_7_rep (D (*fun2) (S1, S2, S3, S4, S5, S6, S7)): 00471 fun (fun2) {} 00472 D apply (S1 x1, S2 x2, S3 x3, S4 x4, S5 x5, S6 x6, S7 x7) { 00473 return fun (x1, x2, x3, x4, x5, x6, x7); } 00474 }; 00475 00476 template<typename D, typename S1, typename S2, typename S3, typename S4, typename S5, typename S6, typename S7> 00477 struct function_7 { 00478 function_7_rep<D,S1,S2,S3,S4,S5,S6,S7>* rep; 00479 inline function_7 (): rep (NULL) {} 00480 inline function_7 (function_7_rep<D,S1,S2,S3,S4,S5,S6,S7>* rep2): rep (rep2) {} 00481 inline function_7 (const function_7& f): 00482 rep (f.rep) { INC_NULL_COUNT(rep); } 00483 inline function_7 (D (*fun) (S1, S2, S3, S4, S5, S6, S7)): 00484 rep (new def_function_7_rep<D,S1,S2,S3,S4,S5,S6,S7> (fun)) {} 00485 inline ~function_7 () { DEC_NULL_COUNT (rep); } 00486 inline function_7& operator = (const function_7& f) { 00487 INC_NULL_COUNT (f.rep); DEC_NULL_COUNT (rep); 00488 rep= f.rep; return *this; } 00489 inline D operator () (S1 x1, S2 x2, S3 x3, S4 x4, S5 x5, S6 x6, S7 x7) const { 00490 return rep->apply (x1, x2, x3, x4, x5, x6, x7); } 00491 }; 00492 00493 #define TMPL template<typename D, typename S1, typename S2, typename S3, typename S4, typename S5, typename S6, typename S7> 00494 #define Function function_7<D,S1,S2,S3,S4,S5,S6,S7> 00495 TMPL inline syntactic flatten (const Function& f) { 00496 return "function"; } 00497 TMPL inline nat hard_hash (const Function& f) { 00498 return as_hash (f.rep); } 00499 TMPL inline bool hard_eq (const Function& f, const Function& g) { 00500 return (f.rep) == (g.rep); } 00501 TMPL inline bool hard_neq (const Function& f, const Function& g) { 00502 return (f.rep) != (g.rep); } 00503 HARD_TO_EXACT_IDENTITY_SUGAR(TMPL,Function) 00504 HARD_TO_TRUE_IDENTITY_SUGAR(TMPL,Function) 00505 #undef Function 00506 #undef TMPL 00507 00508 /****************************************************************************** 00509 * Octagonal functions 00510 ******************************************************************************/ 00511 00512 template<typename D, typename S1, typename S2, typename S3, typename S4, typename S5, typename S6, typename S7, typename S8> 00513 struct function_8_rep REP_STRUCT { 00514 inline function_8_rep () {} 00515 virtual ~function_8_rep () {} 00516 virtual D apply (S1 x1, S2 x2, S3 x3, S4 x4, S5 x5, S6 x6, S7 x7, S8 x8) = 0; 00517 }; 00518 00519 template<typename D, typename S1, typename S2, typename S3, typename S4, typename S5, typename S6, typename S7, typename S8> 00520 struct def_function_8_rep: public function_8_rep<D,S1,S2,S3,S4,S5,S6,S7,S8> { 00521 D (*fun) (S1, S2, S3, S4, S5, S6, S7, S8); 00522 inline def_function_8_rep (D (*fun2) (S1, S2, S3, S4, S5, S6, S7, S8)): 00523 fun (fun2) {} 00524 D apply (S1 x1, S2 x2, S3 x3, S4 x4, S5 x5, S6 x6, S7 x7, S8 x8) { 00525 return fun (x1, x2, x3, x4, x5, x6, x7, x8); } 00526 }; 00527 00528 template<typename D, typename S1, typename S2, typename S3, typename S4, typename S5, typename S6, typename S7, typename S8> 00529 struct function_8 { 00530 function_8_rep<D,S1,S2,S3,S4,S5,S6,S7,S8>* rep; 00531 inline function_8 (): rep (NULL) {} 00532 inline function_8 (function_8_rep<D,S1,S2,S3,S4,S5,S6,S7,S8>* rep2): rep (rep2) {} 00533 inline function_8 (const function_8& f): 00534 rep (f.rep) { INC_NULL_COUNT(rep); } 00535 inline function_8 (D (*fun) (S1, S2, S3, S4, S5, S6, S7, S8)): 00536 rep (new def_function_8_rep<D,S1,S2,S3,S4,S5,S6,S7,S8> (fun)) {} 00537 inline ~function_8 () { DEC_NULL_COUNT (rep); } 00538 inline function_8& operator = (const function_8& f) { 00539 INC_NULL_COUNT (f.rep); DEC_NULL_COUNT (rep); 00540 rep= f.rep; return *this; } 00541 inline D operator () (S1 x1, S2 x2, S3 x3, S4 x4, S5 x5, S6 x6, S7 x7, S8 x8) const { 00542 return rep->apply (x1, x2, x3, x4, x5, x6, x7, x8); } 00543 }; 00544 00545 #define TMPL template<typename D, typename S1, typename S2, typename S3, typename S4, typename S5, typename S6, typename S7, typename S8> 00546 #define Function function_8<D,S1,S2,S3,S4,S5,S6,S7,S8> 00547 TMPL inline syntactic flatten (const Function& f) { 00548 return "function"; } 00549 TMPL inline nat hard_hash (const Function& f) { 00550 return as_hash (f.rep); } 00551 TMPL inline bool hard_eq (const Function& f, const Function& g) { 00552 return (f.rep) == (g.rep); } 00553 TMPL inline bool hard_neq (const Function& f, const Function& g) { 00554 return (f.rep) != (g.rep); } 00555 HARD_TO_EXACT_IDENTITY_SUGAR(TMPL,Function) 00556 HARD_TO_TRUE_IDENTITY_SUGAR(TMPL,Function) 00557 #undef Function 00558 #undef TMPL 00559 00560 } // namespace mmx 00561 00562 using namespace mmx; 00563 #endif // __MMX_FUNCTION_HPP