~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
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
1751.3.2 by Brian Aker
Adding in data dictionary table to list out functions.
34
static plugin::Function::UdfMap udf_registry;
35
36
const plugin::Function::UdfMap &plugin::Function::getMap()
37
{
38
  return udf_registry;
39
}
1130.1.12 by Monty Taylor
Moved service stuff into plugin/
40
1130.1.19 by Monty Taylor
Added error reporting to plugin registration.
41
bool plugin::Function::addPlugin(const plugin::Function *udf)
134.1.1 by Mark Atwood
more hackery to get plugin UDFs working
42
{
1669.3.8 by Brian Aker
Udf lookup now done via case insensitive unordered map
43
  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
44
  {
45
    errmsg_printf(ERRMSG_LVL_ERROR,
46
                  _("A function named %s already exists!\n"),
47
                  udf->getName().c_str());
48
    return true;
49
  }
1966.2.9 by Brian Aker
Remove the use of "using std" from the plugin interface .cc files.
50
  std::pair<UdfMap::iterator, bool> ret=
1669.3.8 by Brian Aker
Udf lookup now done via case insensitive unordered map
51
    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
52
  if (ret.second == false)
53
  {
54
    errmsg_printf(ERRMSG_LVL_ERROR,
55
                  _("Could not add Function!\n"));
1130.1.19 by Monty Taylor
Added error reporting to plugin registration.
56
    return true;
57
  }
58
  return false;
134.1.1 by Mark Atwood
more hackery to get plugin UDFs working
59
}
60
1130.1.12 by Monty Taylor
Moved service stuff into plugin/
61
1130.1.18 by Monty Taylor
Changed ::add() and ::remove() to ::addPlugin() and ::removePlugin() so that
62
void plugin::Function::removePlugin(const plugin::Function *udf)
968.2.31 by Monty Taylor
Fixed UDF de-initialization.
63
{
1669.3.8 by Brian Aker
Udf lookup now done via case insensitive unordered map
64
  udf_registry.erase(udf->getName());
968.2.31 by Monty Taylor
Fixed UDF de-initialization.
65
}
66
1130.1.12 by Monty Taylor
Moved service stuff into plugin/
67
const plugin::Function *plugin::Function::get(const char *name, size_t length)
68
{
1669.3.8 by Brian Aker
Udf lookup now done via case insensitive unordered map
69
  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
70
  if (iter == udf_registry.end())
71
  {
72
    return NULL;
73
  }
74
  return (*iter).second;
1130.1.12 by Monty Taylor
Moved service stuff into plugin/
75
}
76
1130.3.10 by Monty Taylor
Cleaned up service namespacing.
77
} /* namespace drizzled */