basix_doc 0.1
|
00001 00002 /****************************************************************************** 00003 * MODULE : primitive.cpp 00004 * DESCRIPTION: Abstract primitives for evaluator 00005 * COPYRIGHT : (C) 2006 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 #include <basix/primitive.hpp> 00014 #include <basix/routine.hpp> 00015 namespace mmx { 00016 00017 class basic_primitive_rep: public primitive_rep { 00018 typedef generic (*function_type) (const generic&); 00019 function_type fun; 00020 public: 00021 basic_primitive_rep (const generic& name, function_type fun2): 00022 primitive_rep (name), fun (fun2) {} 00023 generic apply (const generic& x) const { return fun (x); } 00024 }; 00025 00026 primitive::primitive (const generic& name, generic (*fun) (const generic&)) { 00027 rep= new basic_primitive_rep (name, fun); 00028 } 00029 00030 class routine_primitive_rep: public primitive_rep { 00031 routine fun; 00032 public: 00033 routine_primitive_rep (const routine& fun2): 00034 primitive_rep (fun2->name), fun (fun2) {} 00035 generic apply (const generic& x) const { 00036 return fun->apply (cdr (compound_to_vector (x))); } 00037 }; 00038 00039 primitive::primitive (const routine& fun) { 00040 rep= new routine_primitive_rep (fun); 00041 } 00042 00043 } // namespace mmx