~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/function.cc

  • Committer: Monty Taylor
  • Date: 2009-10-06 19:40:45 UTC
  • mto: This revision was merged to the branch mainline in revision 1184.
  • Revision ID: mordred@inaugust.com-20091006194045-ojptaq2sx6ck6q63
No more server_includes.h in headers.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 */
20
20
 
21
21
/* This implements 'user defined functions' */
22
 
#include <config.h>
23
 
 
24
 
#include <boost/unordered_map.hpp>
25
 
 
 
22
#include <drizzled/server_includes.h>
26
23
#include <drizzled/gettext.h>
27
 
#include <drizzled/plugin/function.h>
28
 
#include <drizzled/function_container.h>
 
24
#include <drizzled/name_map.h>
 
25
#include "drizzled/plugin/function.h"
29
26
 
30
 
#include <drizzled/util/string.h>
 
27
using namespace std;
31
28
 
32
29
namespace drizzled
33
30
{
34
31
 
35
 
static plugin::Function::UdfMap udf_registry;
36
 
 
37
 
const plugin::Function::UdfMap &plugin::Function::getMap()
38
 
{
39
 
  return udf_registry;
40
 
}
 
32
NameMap<const plugin::Function *> udf_registry;
41
33
 
42
34
bool plugin::Function::addPlugin(const plugin::Function *udf)
43
35
{
44
 
  if (FunctionContainer::getMap().find(udf->getName()) != FunctionContainer::getMap().end())
45
 
  {
46
 
    errmsg_printf(error::ERROR,
47
 
                  _("A function named %s already exists!\n"),
48
 
                  udf->getName().c_str());
49
 
    return true;
50
 
  }
51
 
 
52
 
  if (udf_registry.find(udf->getName()) != udf_registry.end())
53
 
  {
54
 
    errmsg_printf(error::ERROR,
55
 
                  _("A function named %s already exists!\n"),
56
 
                  udf->getName().c_str());
57
 
    return true;
58
 
  }
59
 
 
60
 
  std::pair<UdfMap::iterator, bool> ret=
61
 
    udf_registry.insert(make_pair(udf->getName(), udf));
62
 
  if (ret.second == false)
63
 
  {
64
 
    errmsg_printf(error::ERROR,
65
 
                  _("Could not add Function!\n"));
66
 
    return true;
67
 
  }
68
 
 
 
36
  if (udf_registry.add(udf))
 
37
  {
 
38
    errmsg_printf(ERRMSG_LVL_ERROR,
 
39
                  _("Could not add Function!"));
 
40
    return true;
 
41
  }
69
42
  return false;
70
43
}
71
44
 
72
45
 
73
46
void plugin::Function::removePlugin(const plugin::Function *udf)
74
47
{
75
 
  udf_registry.erase(udf->getName());
 
48
  udf_registry.remove(udf);
76
49
}
77
50
 
78
51
const plugin::Function *plugin::Function::get(const char *name, size_t length)
79
52
{
80
 
  UdfMap::iterator iter= udf_registry.find(std::string(name, length));
81
 
  if (iter == udf_registry.end())
82
 
  {
83
 
    return NULL;
84
 
  }
85
 
  return (*iter).second;
 
53
  return udf_registry.find(name, length);
86
54
}
87
55
 
88
56
} /* namespace drizzled */