~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/function.cc

  • Committer: Stewart Smith
  • Date: 2010-02-05 01:20:18 UTC
  • mto: (1286.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 1287.
  • Revision ID: stewart@flamingspork.com-20100205012018-blvmeky20wze8eyg
initial TableProtoTester engine. We can't just use table_write as some protobuf library versions don't let us write invalid protobuf messages :(

Show diffs side-by-side

added added

removed removed

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