~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
1678.1.1 by Monty Taylor
Removed our unordered wrappers. We use Boost now.
24
#include <boost/unordered_map.hpp>
1429.3.1 by Monty Taylor
Use unordered_map from the upcoming c++0x standard instead of a homemade
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
1669.3.8 by Brian Aker
Udf lookup now done via case insensitive unordered map
29
#include "drizzled/util/string.h"
30
873.2.22 by Monty Taylor
Got rid of my_hash_sort_utf8mb4 for udfs.
31
using namespace std;
1130.1.12 by Monty Taylor
Moved service stuff into plugin/
32
1130.3.10 by Monty Taylor
Cleaned up service namespacing.
33
namespace drizzled
34
{
1130.1.12 by Monty Taylor
Moved service stuff into plugin/
35
1751.3.2 by Brian Aker
Adding in data dictionary table to list out functions.
36
static plugin::Function::UdfMap udf_registry;
37
38
const plugin::Function::UdfMap &plugin::Function::getMap()
39
{
40
  return udf_registry;
41
}
1130.1.12 by Monty Taylor
Moved service stuff into plugin/
42
1130.1.19 by Monty Taylor
Added error reporting to plugin registration.
43
bool plugin::Function::addPlugin(const plugin::Function *udf)
134.1.1 by Mark Atwood
more hackery to get plugin UDFs working
44
{
1669.3.8 by Brian Aker
Udf lookup now done via case insensitive unordered map
45
  if (udf_registry.find(udf->getName()) != udf_registry.end())
1228.3.1 by Monty Taylor
Removed NameMap. Also remove the aliases from the plugin, since we can just
46
  {
47
    errmsg_printf(ERRMSG_LVL_ERROR,
48
                  _("A function named %s already exists!\n"),
49
                  udf->getName().c_str());
50
    return true;
51
  }
52
  pair<UdfMap::iterator, bool> ret=
1669.3.8 by Brian Aker
Udf lookup now done via case insensitive unordered map
53
    udf_registry.insert(make_pair(udf->getName(), udf));
1228.3.1 by Monty Taylor
Removed NameMap. Also remove the aliases from the plugin, since we can just
54
  if (ret.second == false)
55
  {
56
    errmsg_printf(ERRMSG_LVL_ERROR,
57
                  _("Could not add Function!\n"));
1130.1.19 by Monty Taylor
Added error reporting to plugin registration.
58
    return true;
59
  }
60
  return false;
134.1.1 by Mark Atwood
more hackery to get plugin UDFs working
61
}
62
1130.1.12 by Monty Taylor
Moved service stuff into plugin/
63
1130.1.18 by Monty Taylor
Changed ::add() and ::remove() to ::addPlugin() and ::removePlugin() so that
64
void plugin::Function::removePlugin(const plugin::Function *udf)
968.2.31 by Monty Taylor
Fixed UDF de-initialization.
65
{
1669.3.8 by Brian Aker
Udf lookup now done via case insensitive unordered map
66
  udf_registry.erase(udf->getName());
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
{
1669.3.8 by Brian Aker
Udf lookup now done via case insensitive unordered map
71
  UdfMap::iterator iter= udf_registry.find(std::string(name, length));
1228.3.1 by Monty Taylor
Removed NameMap. Also remove the aliases from the plugin, since we can just
72
  if (iter == udf_registry.end())
73
  {
74
    return NULL;
75
  }
76
  return (*iter).second;
1130.1.12 by Monty Taylor
Moved service stuff into plugin/
77
}
78
1130.3.10 by Monty Taylor
Cleaned up service namespacing.
79
} /* namespace drizzled */