Drizzled Public API Documentation

function.cc
1 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3  *
4  * Copyright (C) 2000 MySQL AB
5  * Copyright (C) 2008, 2009 Sun Microsystems, Inc.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; version 2 of the License.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /* This implements 'user defined functions' */
22 #include <config.h>
23 
24 #include <boost/unordered_map.hpp>
25 
26 #include <drizzled/gettext.h>
27 #include <drizzled/plugin/function.h>
28 #include <drizzled/function_container.h>
29 #include <drizzled/util/find_ptr.h>
30 #include <drizzled/util/string.h>
31 
32 namespace drizzled {
33 
34 static plugin::Function::UdfMap udf_registry;
35 
36 const plugin::Function::UdfMap &plugin::Function::getMap()
37 {
38  return udf_registry;
39 }
40 
42 {
43  if (FunctionContainer::getMap().count(udf->getName()))
44  {
45  errmsg_printf(error::ERROR, _("A function named %s already exists!\n"), udf->getName().c_str());
46  return true;
47  }
48 
49  if (udf_registry.count(udf->getName()))
50  {
51  errmsg_printf(error::ERROR, _("A function named %s already exists!\n"), udf->getName().c_str());
52  return true;
53  }
54 
55  if (not udf_registry.insert(make_pair(udf->getName(), udf)).second)
56  {
57  errmsg_printf(error::ERROR, _("Could not add Function!\n"));
58  return true;
59  }
60 
61  return false;
62 }
63 
64 
66 {
67  udf_registry.erase(udf->getName());
68 }
69 
70 const plugin::Function *plugin::Function::get(const std::string &name)
71 {
72  return find_ptr2(udf_registry, name);
73 }
74 
75 } /* namespace drizzled */
static void removePlugin(const plugin::Function *function_obj)
Definition: function.cc:65
static bool addPlugin(const plugin::Function *function_obj)
Definition: function.cc:41