Drizzled Public API Documentation

function.h

00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2008 Sun Microsystems, Inc.
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; version 2 of the License.
00009  *
00010  *  This program 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
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
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 } /* namespace plugin */
00106 } /* namespace drizzled */
00107 
00108