Drizzled Public API Documentation

crc32udf.cc
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 #include <config.h>
21 
22 #include <drizzled/plugin.h>
23 #include <drizzled/plugin/function.h>
24 #include <drizzled/item/func.h>
25 #include <drizzled/algorithm/crc32.h>
26 
27 #include <string>
28 
29 using namespace std;
30 using namespace drizzled;
31 
33 {
34 public:
35  int64_t val_int();
36 
38  {
39  unsigned_flag= true;
40  }
41 
42  const char *func_name() const
43  {
44  return "crc32";
45  }
46 
47  void fix_length_and_dec()
48  {
49  max_length= 10;
50  }
51 
52  bool check_argument_count(int n)
53  {
54  return (n == 1);
55  }
56 };
57 
59 {
60  assert(fixed == true);
61  String value;
62  String *res=args[0]->val_str(&value);
63 
64  if (res == NULL)
65  {
66  null_value= true;
67  return 0;
68  }
69 
70  null_value= false;
71  return static_cast<int64_t>(drizzled::algorithm::crc32(res->ptr(), res->length()));
72 }
73 
74 static int initialize(module::Context &context)
75 {
76  context.add(new plugin::Create_function<Crc32Function>("crc32"));
77  return 0;
78 }
79 
80 DRIZZLE_DECLARE_PLUGIN
81 {
82  DRIZZLE_VERSION_ID,
83  "crc32",
84  "1.0",
85  "Stewart Smith",
86  N_("CRC32 function"),
87  PLUGIN_LICENSE_GPL,
88  initialize,
89  NULL,
90  NULL,
91 }
92 DRIZZLE_DECLARE_PLUGIN_END;