~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/function/create.h

  • Committer: Brian Aker
  • Date: 2009-05-23 17:13:03 UTC
  • mfrom: (1034.1.8 merge)
  • Revision ID: brian@gaz-20090523171303-d28xhutqic0xe2b4
Merge Brian

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#ifndef DRIZZLED_PLUGIN_FUNCTION_H
21
 
#define DRIZZLED_PLUGIN_FUNCTION_H
22
 
 
23
 
 
24
 
#include "drizzled/plugin/plugin.h"
25
 
#include "drizzled/item/func.h"
 
20
#ifndef DRIZZLED_FUNCTION_CREATE_H
 
21
#define DRIZZLED_FUNCTION_CREATE_H
 
22
 
 
23
 
 
24
#include <drizzled/item.h>
 
25
#include <drizzled/sql_list.h>
 
26
#include <drizzled/item/bin_string.h>
26
27
 
27
28
#include <string>
28
29
#include <vector>
29
30
#include <functional>
30
31
 
31
 
namespace drizzled
32
 
{
33
 
 
34
 
class Item_func;
35
 
 
36
 
namespace memory
37
 
{
38
 
  class Root;
39
 
}
40
 
 
41
 
namespace plugin
42
 
{
43
 
 
44
 
/**
45
 
 * Functions in the server: AKA UDF
46
 
 */
47
 
class Function
48
 
  : public Plugin,
49
 
    public std::unary_function<memory::Root*, Item_func *>
50
 
{
51
 
  Function();
52
 
  Function(const Function &);
53
 
  Function& operator=(const Function &);
 
32
class Function_builder
 
33
  : public std::unary_function<MEM_ROOT*, Item_func *>
 
34
{
 
35
  std::string name;
 
36
  std::vector<std::string> aliases;
54
37
public:
55
 
  Function(std::string in_name)
56
 
   : Plugin(in_name, "Function"),
57
 
     std::unary_function<memory::Root*, Item_func *>()
58
 
  { }
59
 
  virtual result_type operator()(argument_type root) const= 0;
60
 
  virtual ~Function() {}
61
 
 
62
 
  /**
63
 
   * Add a new Function factory to the list of factories we manage.
64
 
   */
65
 
  static bool addPlugin(const plugin::Function *function_obj);
66
 
 
67
 
  /**
68
 
   * Remove a Function factory from the list of factory we manage.
69
 
   */
70
 
  static void removePlugin(const plugin::Function *function_obj);
71
 
 
72
 
  /**
73
 
   * Accept a new connection (Protocol object) on one of the configured
74
 
   * listener interfaces.
75
 
   */
76
 
  static const plugin::Function *get(const char *name, size_t len=0);
77
 
 
78
 
  typedef boost::unordered_map<std::string, const plugin::Function *, util::insensitive_hash, util::insensitive_equal_to> UdfMap;
79
 
 
80
 
  static const UdfMap &getMap();
 
38
  Function_builder(std::string in_name) : name(in_name) {}
 
39
  Function_builder(const char *in_name) : name(in_name) {}
 
40
  virtual result_type operator()(argument_type session) const= 0;
 
41
  virtual ~Function_builder() {}
 
42
 
 
43
  std::string getName() const
 
44
  {
 
45
    return name;
 
46
  }
 
47
 
 
48
  const std::vector<std::string>& getAliases() const
 
49
  {
 
50
    return aliases;
 
51
  }
 
52
 
 
53
  void addAlias(std::string alias)
 
54
  {
 
55
    aliases.push_back(alias);
 
56
  }
81
57
};
82
58
 
83
59
template<class T>
84
 
class Create_function
85
 
 : public Function
 
60
class Create_function : public Function_builder
86
61
{
87
62
public:
88
 
  typedef T FunctionClass;
89
 
  Create_function(std::string in_name)
90
 
    : Function(in_name)
91
 
  { }
 
63
  typedef T Function_class;
 
64
  Create_function(std::string in_name): Function_builder(in_name) {}
 
65
  Create_function(const char *in_name): Function_builder(in_name) {}
92
66
  virtual result_type operator()(argument_type root) const
93
67
  {
94
 
    return new (root) FunctionClass();
 
68
    return new (root) Function_class();
95
69
  }
96
70
};
97
71
 
98
 
} /* namespace plugin */
99
 
} /* namespace drizzled */
100
 
 
101
 
 
102
 
#endif /* DRIZZLED_PLUGIN_FUNCTION_H */
 
72
 
 
73
 
 
74
#endif /* DRIZZLED_FUNCTION_CREATE_H */