~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/function.cc

  • Committer: patrick crews
  • Date: 2011-06-08 03:02:27 UTC
  • mto: This revision was merged to the branch mainline in revision 2329.
  • Revision ID: gleebix@gmail.com-20110608030227-updkyv2652zvfajc
Initial voodoo worked to give us a crashme mode.  Need docs still

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