Drizzled Public API Documentation

int.h
00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2008 Sun Microsystems, Inc.
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; version 2 of the License.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  */
00019 
00020 #pragma once
00021 
00022 #include <drizzled/item/num.h>
00023 #include <drizzled/util/test.h>
00024 
00025 namespace drizzled {
00026 
00027 class Item_int : public Item_num
00028 {
00029 public:
00030   int64_t value;
00031 
00032   Item_int(int32_t i,uint32_t length= MY_INT32_NUM_DECIMAL_DIGITS) :
00033     value((int64_t) i)
00034     { max_length=length; fixed= 1; }
00035 
00036   Item_int(int64_t i,uint32_t length= MY_INT64_NUM_DECIMAL_DIGITS) :
00037     value(i)
00038     { max_length=length; fixed= 1; }
00039 
00040   Item_int(uint64_t i, uint32_t length= MY_INT64_NUM_DECIMAL_DIGITS) :
00041     value((int64_t)i)
00042   { max_length=length; fixed=1; }
00043 
00044   Item_int(const char *str_arg,int64_t i,uint32_t length) :
00045     value(i)
00046     { max_length= length; name= const_cast<char *>(str_arg); fixed= 1; }
00047 
00048   Item_int(const char *str_arg, uint32_t length=64);
00049 
00050   enum Type type() const { return INT_ITEM; }
00051 
00052   enum Item_result result_type () const { return INT_RESULT; }
00053 
00054   enum_field_types field_type() const { return DRIZZLE_TYPE_LONGLONG; }
00055 
00056   int64_t val_int() { assert(fixed == 1); return value; }
00057 
00058   double val_real() { assert(fixed == 1); return (double) value; }
00059 
00060   type::Decimal *val_decimal(type::Decimal *);
00061 
00062   String *val_str(String*);
00063 
00064   int save_in_field(Field *field, bool no_conversions);
00065 
00066   bool basic_const_item() const { return 1; }
00067 
00068   Item *clone_item() { return new Item_int(name,value,max_length); }
00069 
00070   virtual void print(String *str);
00071 
00072   Item_num *neg() { value= -value; return this; }
00073 
00074   uint32_t decimal_precision() const
00075   { return (uint32_t)(max_length - test(value < 0)); }
00076 
00077   bool eq(const Item *, bool binary_cmp) const;
00078 };
00079 
00080 } /* namespace drizzled */
00081