~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/function.cc

Rename of handler to Cursor.  You would not believe how long I have wanted
to do that.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2000 MySQL AB
5
 
 *  Copyright (C) 2008, 2009 Sun Microsystems, Inc.
6
 
 *
7
 
 *  This program is free software; you can redistribute it and/or modify
8
 
 *  it under the terms of the GNU General Public License as published by
9
 
 *  the Free Software Foundation; version 2 of the License.
10
 
 *
11
 
 *  This program is distributed in the hope that it will be useful,
12
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 *  GNU General Public License for more details.
15
 
 *
16
 
 *  You should have received a copy of the GNU General Public License
17
 
 *  along with this program; if not, write to the Free Software
18
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 
 */
 
1
/* Copyright (C) 2000 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
20
15
 
21
16
/* This implements 'user defined functions' */
22
 
#include "config.h"
23
 
 
24
 
#include <boost/unordered_map.hpp>
25
 
 
 
17
#include <drizzled/server_includes.h>
26
18
#include <drizzled/gettext.h>
 
19
#include <drizzled/registry.h>
27
20
#include "drizzled/plugin/function.h"
28
 
#include <drizzled/function_container.h>
29
21
 
30
 
#include "drizzled/util/string.h"
 
22
using namespace std;
31
23
 
32
24
namespace drizzled
33
25
{
34
26
 
35
 
static plugin::Function::UdfMap udf_registry;
36
 
 
37
 
const plugin::Function::UdfMap &plugin::Function::getMap()
38
 
{
39
 
  return udf_registry;
40
 
}
 
27
Registry<const plugin::Function *> udf_registry;
41
28
 
42
29
bool plugin::Function::addPlugin(const plugin::Function *udf)
43
30
{
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"));
66
 
    return true;
67
 
  }
68
 
 
 
31
  if (udf_registry.add(udf))
 
32
  {
 
33
    errmsg_printf(ERRMSG_LVL_ERROR,
 
34
                  _("Could not add Function!"));
 
35
    return true;
 
36
  }
69
37
  return false;
70
38
}
71
39
 
72
40
 
73
41
void plugin::Function::removePlugin(const plugin::Function *udf)
74
42
{
75
 
  udf_registry.erase(udf->getName());
 
43
  udf_registry.remove(udf);
76
44
}
77
45
 
 
46
 
78
47
const plugin::Function *plugin::Function::get(const char *name, size_t length)
79
48
{
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;
 
49
  return udf_registry.find(name, length);
86
50
}
87
51
 
88
52
} /* namespace drizzled */