~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/function.h

Added autoconf tests for location of cstdint and cinttypes. Use those in C++ programs now, so that we don't have to define _STDC_LIMIT_MACROS, etc by hand. Stop, in fact, defining those by hand.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
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
 
 
20
 
#ifndef DRIZZLED_PLUGIN_FUNCTION_H
21
 
#define DRIZZLED_PLUGIN_FUNCTION_H
22
 
 
23
 
 
24
 
#include <drizzled/item/func.h>
25
 
#include <drizzled/plugin.h>
26
 
#include <drizzled/plugin/plugin.h>
27
 
 
28
 
#include <string>
29
 
#include <vector>
30
 
#include <functional>
31
 
 
32
 
#include <boost/unordered_map.hpp>
33
 
 
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
 
{
54
 
 
55
 
/**
56
 
 * Functions in the server: AKA UDF
57
 
 */
58
 
class DRIZZLED_API Function
59
 
  : public Plugin,
60
 
    public std::unary_function<memory::Root*, Item_func *>
61
 
{
62
 
  Function();
63
 
  Function(const Function &);
64
 
  Function& operator=(const Function &);
65
 
public:
66
 
  Function(std::string in_name)
67
 
   : Plugin(in_name, "Function"),
68
 
     std::unary_function<memory::Root*, Item_func *>()
69
 
  { }
70
 
  virtual result_type operator()(argument_type root) const= 0;
71
 
  virtual ~Function() {}
72
 
 
73
 
  /**
74
 
   * Add a new Function factory to the list of factories we manage.
75
 
   */
76
 
  static bool addPlugin(const plugin::Function *function_obj);
77
 
 
78
 
  /**
79
 
   * Remove a Function factory from the list of factory we manage.
80
 
   */
81
 
  static void removePlugin(const plugin::Function *function_obj);
82
 
 
83
 
  static const plugin::Function *get(const char *name, size_t len=0);
84
 
 
85
 
  typedef boost::unordered_map<std::string, const plugin::Function *, util::insensitive_hash, util::insensitive_equal_to> UdfMap;
86
 
  typedef boost::unordered_map<std::string, const plugin::Function *, util::insensitive_hash, util::insensitive_equal_to> Map;
87
 
 
88
 
  static const UdfMap &getMap();
89
 
};
90
 
 
91
 
template<class T>
92
 
class Create_function
93
 
 : public Function
94
 
{
95
 
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
101
 
  {
102
 
    return new (root) FunctionClass();
103
 
  }
104
 
};
105
 
 
106
 
} /* namespace plugin */
107
 
} /* namespace drizzled */
108
 
 
109
 
 
110
 
#endif /* DRIZZLED_PLUGIN_FUNCTION_H */