~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/function.cc

Merge Joe, plus I updated the tests.

Show diffs side-by-side

added added

removed removed

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