~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/function.h

  • Committer: Brian Aker
  • Date: 2010-08-18 20:55:22 UTC
  • mfrom: (1711.6.3 staging)
  • Revision ID: brian@tangent.org-20100818205522-esgel82hp9kyl3l2
Merge mutex patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#pragma once
21
 
 
22
 
 
23
 
#include <drizzled/item/func.h>
24
 
#include <drizzled/plugin.h>
25
 
#include <drizzled/plugin/plugin.h>
 
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"
26
26
 
27
27
#include <string>
28
28
#include <vector>
29
29
#include <functional>
30
30
 
31
 
#include <boost/unordered_map.hpp>
32
 
 
33
 
#include <drizzled/visibility.h>
34
 
 
35
 
namespace drizzled {
36
 
namespace plugin {
 
31
namespace drizzled
 
32
{
 
33
 
 
34
class Item_func;
 
35
 
 
36
namespace memory
 
37
{
 
38
  class Root;
 
39
}
 
40
 
 
41
namespace plugin
 
42
{
37
43
 
38
44
/**
39
45
 * Functions in the server: AKA UDF
40
46
 */
41
 
class DRIZZLED_API Function : public Plugin
 
47
class Function
 
48
  : public Plugin,
 
49
    public std::unary_function<memory::Root*, Item_func *>
42
50
{
 
51
  Function();
 
52
  Function(const Function &);
 
53
  Function& operator=(const Function &);
43
54
public:
44
 
  Function(std::string in_name) : Plugin(in_name, "Function")
 
55
  Function(std::string in_name)
 
56
   : Plugin(in_name, "Function"),
 
57
     std::unary_function<memory::Root*, Item_func *>()
45
58
  { }
46
 
  virtual Item_func* operator()(memory::Root*) const= 0;
 
59
  virtual result_type operator()(argument_type root) const= 0;
 
60
  virtual ~Function() {}
47
61
 
48
62
  /**
49
63
   * Add a new Function factory to the list of factories we manage.
55
69
   */
56
70
  static void removePlugin(const plugin::Function *function_obj);
57
71
 
58
 
  static const plugin::Function *get(const std::string &name);
59
 
 
60
 
  typedef boost::unordered_map<std::string, const plugin::Function *, util::insensitive_hash, util::insensitive_equal_to> UdfMap;
61
 
  typedef boost::unordered_map<std::string, const plugin::Function *, util::insensitive_hash, util::insensitive_equal_to> Map;
62
 
 
63
 
  static const UdfMap &getMap();
 
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
 
64
78
};
65
79
 
66
80
template<class T>
67
 
class Create_function : public Function
 
81
class Create_function
 
82
 : public Function
68
83
{
69
84
public:
70
 
  Create_function(const std::string& in_name) : Function(in_name)
71
 
  { 
72
 
  }
73
 
 
74
 
  virtual Item_func* operator()(memory::Root* root) const
 
85
  typedef T FunctionClass;
 
86
  Create_function(std::string in_name)
 
87
    : Function(in_name)
 
88
  { }
 
89
  virtual result_type operator()(argument_type root) const
75
90
  {
76
 
    return new (*root) T();
 
91
    return new (root) FunctionClass();
77
92
  }
78
93
};
79
94
 
81
96
} /* namespace drizzled */
82
97
 
83
98
 
 
99
#endif /* DRIZZLED_PLUGIN_FUNCTION_H */