00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <config.h>
00023
00024 #include <boost/unordered_map.hpp>
00025
00026 #include <drizzled/gettext.h>
00027 #include <drizzled/plugin/function.h>
00028 #include <drizzled/function_container.h>
00029 #include <drizzled/util/find_ptr.h>
00030 #include <drizzled/util/string.h>
00031
00032 namespace drizzled {
00033
00034 static plugin::Function::UdfMap udf_registry;
00035
00036 const plugin::Function::UdfMap &plugin::Function::getMap()
00037 {
00038 return udf_registry;
00039 }
00040
00041 bool plugin::Function::addPlugin(const plugin::Function *udf)
00042 {
00043 if (FunctionContainer::getMap().count(udf->getName()))
00044 {
00045 errmsg_printf(error::ERROR, _("A function named %s already exists!\n"), udf->getName().c_str());
00046 return true;
00047 }
00048
00049 if (udf_registry.count(udf->getName()))
00050 {
00051 errmsg_printf(error::ERROR, _("A function named %s already exists!\n"), udf->getName().c_str());
00052 return true;
00053 }
00054
00055 if (not udf_registry.insert(make_pair(udf->getName(), udf)).second)
00056 {
00057 errmsg_printf(error::ERROR, _("Could not add Function!\n"));
00058 return true;
00059 }
00060
00061 return false;
00062 }
00063
00064
00065 void plugin::Function::removePlugin(const plugin::Function *udf)
00066 {
00067 udf_registry.erase(udf->getName());
00068 }
00069
00070 const plugin::Function *plugin::Function::get(const std::string &name)
00071 {
00072 return find_ptr2(udf_registry, name);
00073 }
00074
00075 }