~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/function.h

  • Committer: Mark Atwood
  • Date: 2011-08-11 03:05:03 UTC
  • mfrom: (2385.1.12 refactor4)
  • Revision ID: me@mark.atwood.name-20110811030503-rp9xjihc5x3y0x4q
mergeĀ lp:~olafvdspek/drizzle/refactor4

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
 
20
#pragma once
22
21
 
23
22
 
24
23
#include <drizzled/item/func.h>
31
30
 
32
31
#include <boost/unordered_map.hpp>
33
32
 
34
 
#include "drizzled/visibility.h"
35
 
 
36
 
namespace drizzled
37
 
{
38
 
 
39
 
class Item_func;
40
 
 
41
 
namespace memory
42
 
{
43
 
  class Root;
44
 
}
45
 
 
46
 
namespace util
47
 
{
48
 
struct insensitive_hash;
49
 
struct insensitive_equal_to;
50
 
}
51
 
 
52
 
namespace plugin
53
 
{
 
33
#include <drizzled/visibility.h>
 
34
 
 
35
namespace drizzled {
 
36
namespace plugin {
54
37
 
55
38
/**
56
39
 * Functions in the server: AKA UDF
57
40
 */
58
 
class DRIZZLED_API Function
59
 
  : public Plugin,
60
 
    public std::unary_function<memory::Root*, Item_func *>
 
41
class DRIZZLED_API Function : public Plugin
61
42
{
62
 
  Function();
63
 
  Function(const Function &);
64
 
  Function& operator=(const Function &);
65
43
public:
66
 
  Function(std::string in_name)
67
 
   : Plugin(in_name, "Function"),
68
 
     std::unary_function<memory::Root*, Item_func *>()
 
44
  Function(std::string in_name) : Plugin(in_name, "Function")
69
45
  { }
70
 
  virtual result_type operator()(argument_type root) const= 0;
71
 
  virtual ~Function() {}
 
46
  virtual Item_func* operator()(memory::Root*) const= 0;
72
47
 
73
48
  /**
74
49
   * Add a new Function factory to the list of factories we manage.
80
55
   */
81
56
  static void removePlugin(const plugin::Function *function_obj);
82
57
 
83
 
  static const plugin::Function *get(const char *name, size_t len=0);
 
58
  static const plugin::Function *get(const std::string &name);
84
59
 
85
60
  typedef boost::unordered_map<std::string, const plugin::Function *, util::insensitive_hash, util::insensitive_equal_to> UdfMap;
86
61
  typedef boost::unordered_map<std::string, const plugin::Function *, util::insensitive_hash, util::insensitive_equal_to> Map;
89
64
};
90
65
 
91
66
template<class T>
92
 
class Create_function
93
 
 : public Function
 
67
class Create_function : public Function
94
68
{
95
69
public:
96
 
  typedef T FunctionClass;
97
 
  Create_function(std::string in_name)
98
 
    : Function(in_name)
99
 
  { }
100
 
  virtual result_type operator()(argument_type root) const
 
70
  Create_function(const std::string& in_name) : Function(in_name)
 
71
  { 
 
72
  }
 
73
 
 
74
  virtual Item_func* operator()(memory::Root* root) const
101
75
  {
102
 
    return new (root) FunctionClass();
 
76
    return new (*root) T();
103
77
  }
104
78
};
105
79
 
107
81
} /* namespace drizzled */
108
82
 
109
83
 
110
 
#endif /* DRIZZLED_PLUGIN_FUNCTION_H */