~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/function.cc

  • Committer: pcrews
  • Date: 2011-05-24 17:36:24 UTC
  • mfrom: (1099.4.232 drizzle)
  • Revision ID: pcrews@lucid32-20110524173624-mwr1bvq6fa1r01ao
Updated translations + 2011.05.18 tarball tag

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"
 
29
#include <drizzled/util/find_ptr.h>
 
30
#include <drizzled/util/string.h>
31
31
 
32
32
namespace drizzled
33
33
{
41
41
 
42
42
bool plugin::Function::addPlugin(const plugin::Function *udf)
43
43
{
44
 
  if (FunctionContainer::getMap().find(udf->getName()) != FunctionContainer::getMap().end())
 
44
  if (FunctionContainer::getMap().count(udf->getName()))
45
45
  {
46
46
    errmsg_printf(error::ERROR,
47
47
                  _("A function named %s already exists!\n"),
49
49
    return true;
50
50
  }
51
51
 
52
 
  if (udf_registry.find(udf->getName()) != udf_registry.end())
 
52
  if (udf_registry.count(udf->getName()))
53
53
  {
54
54
    errmsg_printf(error::ERROR,
55
55
                  _("A function named %s already exists!\n"),
59
59
 
60
60
  std::pair<UdfMap::iterator, bool> ret=
61
61
    udf_registry.insert(make_pair(udf->getName(), udf));
 
62
 
62
63
  if (ret.second == false)
63
64
  {
64
65
    errmsg_printf(error::ERROR,
75
76
  udf_registry.erase(udf->getName());
76
77
}
77
78
 
78
 
const plugin::Function *plugin::Function::get(const char *name, size_t length)
 
79
const plugin::Function *plugin::Function::get(const std::string &name)
79
80
{
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;
 
81
  UdfMap::mapped_type* ptr= find_ptr(udf_registry, name);
 
82
  return ptr ? *ptr : NULL;
86
83
}
87
84
 
88
85
} /* namespace drizzled */