~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/function.cc

  • Committer: Mark Atwood
  • Date: 2011-08-09 01:21:52 UTC
  • mfrom: (2380.1.2 drizzle-autoconf)
  • Revision ID: me@mark.atwood.name-20110809012152-zxq2dgan8e6nsvse
mergeĀ lp:~brianaker/drizzle/autoreconf

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"
 
22
#include <config.h>
23
23
 
24
24
#include <boost/unordered_map.hpp>
25
25
 
26
26
#include <drizzled/gettext.h>
27
 
#include "drizzled/plugin/function.h"
 
27
#include <drizzled/plugin/function.h>
28
28
#include <drizzled/function_container.h>
29
 
 
30
 
#include "drizzled/util/string.h"
31
 
 
32
 
namespace drizzled
33
 
{
 
29
#include <drizzled/util/find_ptr.h>
 
30
#include <drizzled/util/string.h>
 
31
 
 
32
namespace drizzled {
34
33
 
35
34
static plugin::Function::UdfMap udf_registry;
36
35
 
41
40
 
42
41
bool plugin::Function::addPlugin(const plugin::Function *udf)
43
42
{
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"));
 
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"));
66
58
    return true;
67
59
  }
68
60
 
75
67
  udf_registry.erase(udf->getName());
76
68
}
77
69
 
78
 
const plugin::Function *plugin::Function::get(const char *name, size_t length)
 
70
const plugin::Function *plugin::Function::get(const std::string &name)
79
71
{
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;
 
72
  return find_ptr2(udf_registry, name);
86
73
}
87
74
 
88
75
} /* namespace drizzled */