~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to drizzled/plugin/function.cc

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-03-18 12:12:31 UTC
  • Revision ID: james.westby@ubuntu.com-20100318121231-k6g1xe6cshbwa0f8
Tags: upstream-2010.03.1347
ImportĀ upstreamĀ versionĀ 2010.03.1347

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
 */
 
20
 
 
21
/* This implements 'user defined functions' */
 
22
#include "config.h"
 
23
#include <drizzled/gettext.h>
 
24
#include "drizzled/hash.h"
 
25
#include "drizzled/plugin/function.h"
 
26
 
 
27
using namespace std;
 
28
 
 
29
namespace drizzled
 
30
{
 
31
 
 
32
typedef hash_map<string, const plugin::Function *> UdfMap;
 
33
static UdfMap udf_registry;
 
34
 
 
35
bool plugin::Function::addPlugin(const plugin::Function *udf)
 
36
{
 
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));
 
49
  if (ret.second == false)
 
50
  {
 
51
    errmsg_printf(ERRMSG_LVL_ERROR,
 
52
                  _("Could not add Function!\n"));
 
53
    return true;
 
54
  }
 
55
  return false;
 
56
}
 
57
 
 
58
 
 
59
void plugin::Function::removePlugin(const plugin::Function *udf)
 
60
{
 
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);
 
65
}
 
66
 
 
67
const plugin::Function *plugin::Function::get(const char *name, size_t length)
 
68
{
 
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);
 
73
  if (iter == udf_registry.end())
 
74
  {
 
75
    return NULL;
 
76
  }
 
77
  return (*iter).second;
 
78
}
 
79
 
 
80
} /* namespace drizzled */