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 namespace plugin {
00037 
00041 class DRIZZLED_API Function : public Plugin
00042 {
00043 public:
00044   Function(std::string in_name) : Plugin(in_name, "Function")
00045   { }
00046   virtual Item_func* operator()(memory::Root*) const= 0;
00047 
00051   static bool addPlugin(const plugin::Function *function_obj);
00052 
00056   static void removePlugin(const plugin::Function *function_obj);
00057 
00058   static const plugin::Function *get(const std::string &name);
00059 
00060   typedef boost::unordered_map<std::string, const plugin::Function *, util::insensitive_hash, util::insensitive_equal_to> UdfMap;
00061   typedef boost::unordered_map<std::string, const plugin::Function *, util::insensitive_hash, util::insensitive_equal_to> Map;
00062 
00063   static const UdfMap &getMap();
00064 };
00065 
00066 template<class T>
00067 class Create_function : public Function
00068 {
00069 public:
00070   Create_function(const std::string& in_name) : Function(in_name)
00071   { 
00072   }
00073 
00074   virtual Item_func* operator()(memory::Root* root) const
00075   {
00076     return new (*root) T();
00077   }
00078 };
00079 
00080 } /* namespace plugin */
00081 } /* namespace drizzled */
00082 
00083