~drizzle-trunk/drizzle/development

1130.3.10 by Monty Taylor
Cleaned up service namespacing.
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 by brian
clean slate
20
21
/* This implements 'user defined functions' */
1241.9.36 by Monty Taylor
ZOMG. I deleted drizzled/server_includes.h.
22
#include "config.h"
1429.3.1 by Monty Taylor
Use unordered_map from the upcoming c++0x standard instead of a homemade
23
24
#include <drizzled/unordered_map.h>
25
538 by Monty Taylor
Moved gettext.h into drizzled in anticipation of the new client lib.
26
#include <drizzled/gettext.h>
1130.1.12 by Monty Taylor
Moved service stuff into plugin/
27
#include "drizzled/plugin/function.h"
873.2.22 by Monty Taylor
Got rid of my_hash_sort_utf8mb4 for udfs.
28
29
using namespace std;
1130.1.12 by Monty Taylor
Moved service stuff into plugin/
30
1130.3.10 by Monty Taylor
Cleaned up service namespacing.
31
namespace drizzled
32
{
1130.1.12 by Monty Taylor
Moved service stuff into plugin/
33
1429.3.1 by Monty Taylor
Use unordered_map from the upcoming c++0x standard instead of a homemade
34
typedef unordered_map<string, const plugin::Function *> UdfMap;
1228.3.1 by Monty Taylor
Removed NameMap. Also remove the aliases from the plugin, since we can just
35
static UdfMap udf_registry;
1130.1.12 by Monty Taylor
Moved service stuff into plugin/
36
1130.1.19 by Monty Taylor
Added error reporting to plugin registration.
37
bool plugin::Function::addPlugin(const plugin::Function *udf)
134.1.1 by Mark Atwood
more hackery to get plugin UDFs working
38
{
1228.3.1 by Monty Taylor
Removed NameMap. Also remove the aliases from the plugin, since we can just
39
  string lower_name(udf->getName());
40
  transform(lower_name.begin(), lower_name.end(),
41
            lower_name.begin(), ::tolower);
42
  if (udf_registry.find(lower_name) != udf_registry.end())
43
  {
44
    errmsg_printf(ERRMSG_LVL_ERROR,
45
                  _("A function named %s already exists!\n"),
46
                  udf->getName().c_str());
47
    return true;
48
  }
49
  pair<UdfMap::iterator, bool> ret=
50
    udf_registry.insert(make_pair(lower_name, udf));
51
  if (ret.second == false)
52
  {
53
    errmsg_printf(ERRMSG_LVL_ERROR,
54
                  _("Could not add Function!\n"));
1130.1.19 by Monty Taylor
Added error reporting to plugin registration.
55
    return true;
56
  }
57
  return false;
134.1.1 by Mark Atwood
more hackery to get plugin UDFs working
58
}
59
1130.1.12 by Monty Taylor
Moved service stuff into plugin/
60
1130.1.18 by Monty Taylor
Changed ::add() and ::remove() to ::addPlugin() and ::removePlugin() so that
61
void plugin::Function::removePlugin(const plugin::Function *udf)
968.2.31 by Monty Taylor
Fixed UDF de-initialization.
62
{
1228.3.1 by Monty Taylor
Removed NameMap. Also remove the aliases from the plugin, since we can just
63
  string lower_name(udf->getName());
64
  transform(lower_name.begin(), lower_name.end(),
65
            lower_name.begin(), ::tolower);
66
  udf_registry.erase(lower_name);
968.2.31 by Monty Taylor
Fixed UDF de-initialization.
67
}
68
1130.1.12 by Monty Taylor
Moved service stuff into plugin/
69
const plugin::Function *plugin::Function::get(const char *name, size_t length)
70
{
1228.3.1 by Monty Taylor
Removed NameMap. Also remove the aliases from the plugin, since we can just
71
  string lower_name(name, length);
72
  transform(lower_name.begin(), lower_name.end(),
73
            lower_name.begin(), ::tolower);
74
  UdfMap::iterator iter= udf_registry.find(lower_name);
75
  if (iter == udf_registry.end())
76
  {
77
    return NULL;
78
  }
79
  return (*iter).second;
1130.1.12 by Monty Taylor
Moved service stuff into plugin/
80
}
81
1130.3.10 by Monty Taylor
Cleaned up service namespacing.
82
} /* namespace drizzled */