~drizzle-trunk/drizzle/development

942.1.12 by Monty Taylor
Converted udf_func into a factory.
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
942.1.12 by Monty Taylor
Converted udf_func into a factory.
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; version 2 of the License.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU General Public License
16
 *  along with this program; if not, write to the Free Software
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 */
19
1093.1.62 by Monty Taylor
Moved UDFs to slot organization.
20
#ifndef DRIZZLED_PLUGIN_FUNCTION_H
21
#define DRIZZLED_PLUGIN_FUNCTION_H
942.1.12 by Monty Taylor
Converted udf_func into a factory.
22
23
2148.7.12 by Brian Aker
Merge in header fixes.
24
#include <drizzled/item/func.h>
25
#include <drizzled/plugin.h>
26
#include <drizzled/plugin/plugin.h>
1130.1.12 by Monty Taylor
Moved service stuff into plugin/
27
942.1.12 by Monty Taylor
Converted udf_func into a factory.
28
#include <string>
971.1.23 by Monty Taylor
Add generalized registry to be used for case-insensitive mappings.
29
#include <vector>
942.1.12 by Monty Taylor
Converted udf_func into a factory.
30
#include <functional>
31
2154.2.4 by Brian Aker
This fixes 716459
32
#include <boost/unordered_map.hpp>
33
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
34
#include <drizzled/visibility.h>
2119.4.1 by Monty Taylor
Turns on -fvisibility=hidden by default. Symbols intended to be used by
35
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
36
namespace drizzled
37
{
38
1241.10.1 by Monty Taylor
Added ability to specify all of the meta information in the plugin.ini file. This allows us to have a streamlined out-of-tree build.
39
class Item_func;
1093.1.62 by Monty Taylor
Moved UDFs to slot organization.
40
1253.1.3 by Monty Taylor
MEM_ROOT == memory::Root
41
namespace memory
42
{
43
  class Root;
44
}
45
2154.2.4 by Brian Aker
This fixes 716459
46
namespace util
47
{
48
struct insensitive_hash;
49
struct insensitive_equal_to;
50
}
51
1093.1.62 by Monty Taylor
Moved UDFs to slot organization.
52
namespace plugin
53
{
54
55
/**
56
 * Functions in the server: AKA UDF
57
 */
2119.4.1 by Monty Taylor
Turns on -fvisibility=hidden by default. Symbols intended to be used by
58
class DRIZZLED_API Function
1130.2.16 by Monty Taylor
Cleaned up the constructor initializer lists per Brian.
59
  : public Plugin,
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
60
    public std::unary_function<memory::Root*, Item_func *>
942.1.12 by Monty Taylor
Converted udf_func into a factory.
61
{
1130.2.16 by Monty Taylor
Cleaned up the constructor initializer lists per Brian.
62
  Function();
63
  Function(const Function &);
64
  Function& operator=(const Function &);
942.1.12 by Monty Taylor
Converted udf_func into a factory.
65
public:
1130.2.1 by Monty Taylor
Introduced plugin::Plugin class. Made Function use it.
66
  Function(std::string in_name)
1192.2.5 by Monty Taylor
Replaced overridable virtual methods with passing name to constructor. Now individual plugins will not be allowed to set their own plugin type name. :)
67
   : Plugin(in_name, "Function"),
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
68
     std::unary_function<memory::Root*, Item_func *>()
1130.2.1 by Monty Taylor
Introduced plugin::Plugin class. Made Function use it.
69
  { }
70
  virtual result_type operator()(argument_type root) const= 0;
1093.1.62 by Monty Taylor
Moved UDFs to slot organization.
71
  virtual ~Function() {}
942.1.12 by Monty Taylor
Converted udf_func into a factory.
72
1130.1.12 by Monty Taylor
Moved service stuff into plugin/
73
  /**
74
   * Add a new Function factory to the list of factories we manage.
75
   */
1130.1.19 by Monty Taylor
Added error reporting to plugin registration.
76
  static bool addPlugin(const plugin::Function *function_obj);
1130.1.12 by Monty Taylor
Moved service stuff into plugin/
77
78
  /**
79
   * Remove a Function factory from the list of factory we manage.
80
   */
1130.1.18 by Monty Taylor
Changed ::add() and ::remove() to ::addPlugin() and ::removePlugin() so that
81
  static void removePlugin(const plugin::Function *function_obj);
1130.1.12 by Monty Taylor
Moved service stuff into plugin/
82
83
  static const plugin::Function *get(const char *name, size_t len=0);
84
1751.3.2 by Brian Aker
Adding in data dictionary table to list out functions.
85
  typedef boost::unordered_map<std::string, const plugin::Function *, util::insensitive_hash, util::insensitive_equal_to> UdfMap;
2060 by Brian Aker
Added native functions into the function table.
86
  typedef boost::unordered_map<std::string, const plugin::Function *, util::insensitive_hash, util::insensitive_equal_to> Map;
1751.3.2 by Brian Aker
Adding in data dictionary table to list out functions.
87
88
  static const UdfMap &getMap();
942.1.12 by Monty Taylor
Converted udf_func into a factory.
89
};
90
91
template<class T>
1130.2.1 by Monty Taylor
Introduced plugin::Plugin class. Made Function use it.
92
class Create_function
93
 : public Function
942.1.12 by Monty Taylor
Converted udf_func into a factory.
94
{
95
public:
1130.2.1 by Monty Taylor
Introduced plugin::Plugin class. Made Function use it.
96
  typedef T FunctionClass;
97
  Create_function(std::string in_name)
98
    : Function(in_name)
99
  { }
942.1.12 by Monty Taylor
Converted udf_func into a factory.
100
  virtual result_type operator()(argument_type root) const
101
  {
1130.2.1 by Monty Taylor
Introduced plugin::Plugin class. Made Function use it.
102
    return new (root) FunctionClass();
942.1.12 by Monty Taylor
Converted udf_func into a factory.
103
  }
104
};
105
1130.2.6 by Monty Taylor
Merged in latest plugin-slot-reorg.
106
} /* namespace plugin */
107
} /* namespace drizzled */
1093.1.62 by Monty Taylor
Moved UDFs to slot organization.
108
109
110
#endif /* DRIZZLED_PLUGIN_FUNCTION_H */