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 
00028 class Item_int :public Item_num
00029 {
00030 public:
00031   int64_t value;
00032 
00033   Item_int(int32_t i,uint32_t length= MY_INT32_NUM_DECIMAL_DIGITS) :
00034     value((int64_t) i)
00035     { max_length=length; fixed= 1; }
00036 
00037   Item_int(int64_t i,uint32_t length= MY_INT64_NUM_DECIMAL_DIGITS) :
00038     value(i)
00039     { max_length=length; fixed= 1; }
00040 
00041   Item_int(uint64_t i, uint32_t length= MY_INT64_NUM_DECIMAL_DIGITS) :
00042     value((int64_t)i)
00043   { max_length=length; fixed=1; }
00044 
00045   Item_int(const char *str_arg,int64_t i,uint32_t length) :
00046     value(i)
00047     { max_length= length; name= const_cast<char *>(str_arg); fixed= 1; }
00048 
00049   Item_int(const char *str_arg, uint32_t length=64);
00050 
00051   enum Type type() const { return INT_ITEM; }
00052 
00053   enum Item_result result_type () const { return INT_RESULT; }
00054 
00055   enum_field_types field_type() const { return DRIZZLE_TYPE_LONGLONG; }
00056 
00057   int64_t val_int() { assert(fixed == 1); return value; }
00058 
00059   double val_real() { assert(fixed == 1); return (double) value; }
00060 
00061   type::Decimal *val_decimal(type::Decimal *);
00062 
00063   String *val_str(String*);
00064 
00065   int save_in_field(Field *field, bool no_conversions);
00066 
00067   bool basic_const_item() const { return 1; }
00068 
00069   Item *clone_item() { return new Item_int(name,value,max_length); }
00070 
00071   virtual void print(String *str);
00072 
00073   Item_num *neg() { value= -value; return this; }
00074 
00075   uint32_t decimal_precision() const
00076   { return (uint32_t)(max_length - test(value < 0)); }
00077 
00078   bool eq(const Item *, bool binary_cmp) const;
00079 };
00080 
00081 } /* namespace drizzled */
00082