00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #pragma once
00021
00022
00023 #include <drizzled/item/func.h>
00024 #include <drizzled/plugin.h>
00025 #include <drizzled/plugin/plugin.h>
00026
00027 #include <string>
00028 #include <vector>
00029 #include <functional>
00030
00031 #include <boost/unordered_map.hpp>
00032
00033 #include <drizzled/visibility.h>
00034
00035 namespace drizzled
00036 {
00037
00038 class Item_func;
00039
00040 namespace memory
00041 {
00042 class Root;
00043 }
00044
00045 namespace util
00046 {
00047 struct insensitive_hash;
00048 struct insensitive_equal_to;
00049 }
00050
00051 namespace plugin
00052 {
00053
00057 class DRIZZLED_API Function
00058 : public Plugin,
00059 public std::unary_function<memory::Root*, Item_func *>
00060 {
00061 Function();
00062 Function(const Function &);
00063 Function& operator=(const Function &);
00064 public:
00065 Function(std::string in_name)
00066 : Plugin(in_name, "Function"),
00067 std::unary_function<memory::Root*, Item_func *>()
00068 { }
00069 virtual result_type operator()(argument_type root) const= 0;
00070 virtual ~Function() {}
00071
00075 static bool addPlugin(const plugin::Function *function_obj);
00076
00080 static void removePlugin(const plugin::Function *function_obj);
00081
00082 static const plugin::Function *get(const std::string &name);
00083
00084 typedef boost::unordered_map<std::string, const plugin::Function *, util::insensitive_hash, util::insensitive_equal_to> UdfMap;
00085 typedef boost::unordered_map<std::string, const plugin::Function *, util::insensitive_hash, util::insensitive_equal_to> Map;
00086
00087 static const UdfMap &getMap();
00088 };
00089
00090 template<class T>
00091 class Create_function
00092 : public Function
00093 {
00094 public:
00095 typedef T FunctionClass;
00096 Create_function(std::string in_name)
00097 : Function(in_name)
00098 { }
00099 virtual result_type operator()(argument_type root) const
00100 {
00101 return new (root) FunctionClass();
00102 }
00103 };
00104
00105 }
00106 }
00107
00108