~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/crc32/crc32udf.cc

  • Committer: Brian Aker
  • Date: 2008-10-12 01:59:02 UTC
  • Revision ID: brian@tangent.org-20081012015902-prhy6wsimdqr28om
Dead code around unsigned (first pass)

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
 
#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
 
 
32
 
class Crc32Function :public Item_int_func
 
1
/* Copyright (C) 2006 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
15
 
 
16
#include "config.h"
 
17
 
 
18
#include CSTDINT_H
 
19
#include <drizzled/common_includes.h>
 
20
#include <drizzled/item_func.h>
 
21
#include <zlib.h>
 
22
 
 
23
class Item_func_crc32 :public Item_int_func
33
24
{
 
25
  String value;
34
26
public:
 
27
  Item_func_crc32() :Item_int_func() { unsigned_flag= 1; }
 
28
  const char *func_name() const { return "crc32"; }
 
29
  void fix_length_and_dec() { max_length=10; }
35
30
  int64_t val_int();
36
 
  
37
 
  Crc32Function() :Item_int_func() 
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
31
};
57
32
 
58
 
int64_t Crc32Function::val_int()
 
33
int64_t Item_func_crc32::val_int()
59
34
{
60
 
  assert(fixed == true);
61
 
  String value;
 
35
  assert(fixed == 1);
62
36
  String *res=args[0]->val_str(&value);
63
 
  
64
 
  if (res == NULL)
 
37
  if (!res)
65
38
  {
66
 
    null_value= true;
67
 
    return 0;
 
39
    null_value=1;
 
40
    return 0; /* purecov: inspected */
68
41
  }
69
 
 
70
 
  null_value= false;
71
 
  return static_cast<int64_t>(drizzled::algorithm::crc32(res->ptr(), res->length()));
72
 
}
73
 
 
74
 
plugin::Create_function<Crc32Function> *crc32udf= NULL;
75
 
 
76
 
static int initialize(module::Context &context)
77
 
{
78
 
  crc32udf= new plugin::Create_function<Crc32Function>("crc32");
79
 
  context.add(crc32udf);
80
 
  return 0;
81
 
}
82
 
 
83
 
DRIZZLE_PLUGIN(initialize, NULL, NULL);
 
42
  null_value=0;
 
43
  return (int64_t) crc32(0L, (unsigned char*)res->ptr(), res->length());
 
44
}
 
45
 
 
46
Item_func* create_crc32udf_item(MEM_ROOT* m)
 
47
{
 
48
  return  new (m) Item_func_crc32();
 
49
}
 
50
 
 
51
static struct udf_func crc32udf = {
 
52
  { C_STRING_WITH_LEN("crc32") },
 
53
  create_crc32udf_item
 
54
};
 
55
 
 
56
static int crc32udf_plugin_init(void *p)
 
57
{
 
58
  udf_func **f = (udf_func**) p;
 
59
 
 
60
  *f= &crc32udf;
 
61
 
 
62
  return 0;
 
63
}
 
64
 
 
65
static int crc32udf_plugin_deinit(void *p)
 
66
{
 
67
  udf_func *udff = (udf_func *) p;
 
68
  (void)udff;
 
69
  return 0;
 
70
}
 
71
 
 
72
mysql_declare_plugin(crc32)
 
73
{
 
74
  DRIZZLE_UDF_PLUGIN,
 
75
  "crc32",
 
76
  "1.0",
 
77
  "Stewart Smith",
 
78
  "UDF for computing CRC32",
 
79
  PLUGIN_LICENSE_GPL,
 
80
  crc32udf_plugin_init, /* Plugin Init */
 
81
  crc32udf_plugin_deinit, /* Plugin Deinit */
 
82
  NULL,   /* status variables */
 
83
  NULL,   /* system variables */
 
84
  NULL    /* config options */
 
85
}
 
86
mysql_declare_plugin_end;