Drizzled Public API Documentation

hybrid_type_traits_integer.cc
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 
00021 #include <config.h>
00022 
00023 #include <drizzled/definitions.h>
00024 #include <drizzled/field.h>
00025 #include <drizzled/hybrid_type.h>
00026 #include <drizzled/hybrid_type_traits_integer.h>
00027 #include <drizzled/item.h>
00028 
00029 namespace drizzled
00030 {
00031 
00032 /* Hybrid_type_traits_integer */
00033 static const Hybrid_type_traits_integer integer_traits_instance;
00034 
00035 
00036 Item_result Hybrid_type_traits_integer::type() const
00037 {
00038   return INT_RESULT;
00039 }
00040 
00041 
00042 void
00043 Hybrid_type_traits_integer::fix_length_and_dec(Item *item, Item *) const
00044 {
00045   item->decimals= 0;
00046   item->max_length= MY_INT64_NUM_DECIMAL_DIGITS;
00047   item->unsigned_flag= 0;
00048 }
00049 
00050 
00051 /* Hybrid_type operations. */
00052 void Hybrid_type_traits_integer::set_zero(Hybrid_type *val) const
00053 {
00054   val->integer= 0;
00055 }
00056 
00057 
00058 void Hybrid_type_traits_integer::add(Hybrid_type *val, Field *f) const
00059 {
00060   val->integer+= f->val_int();
00061 }
00062 
00063 
00064 void Hybrid_type_traits_integer::div(Hybrid_type *val, uint64_t u) const
00065 {
00066   val->integer/= (int64_t) u;
00067 }
00068 
00069 
00070 int64_t Hybrid_type_traits_integer::val_int(Hybrid_type *val, bool) const
00071 {
00072   return val->integer;
00073 }
00074 
00075 
00076 double Hybrid_type_traits_integer::val_real(Hybrid_type *val) const
00077 {
00078   return (double) val->integer;
00079 }
00080 
00081 
00082 type::Decimal *Hybrid_type_traits_integer::val_decimal(Hybrid_type *val,
00083                                                     type::Decimal *) const
00084 {
00085   int2_class_decimal(E_DEC_FATAL_ERROR, val->integer, 0, &val->dec_buf[2]);
00086   return &val->dec_buf[2];
00087 }
00088 
00089 
00090 String *Hybrid_type_traits_integer::val_str(Hybrid_type *val, String *buf,
00091                                             uint8_t) const
00092 {
00093   buf->set(val->integer, &my_charset_bin);
00094   return buf;
00095 }
00096 
00097 
00098 const Hybrid_type_traits_integer *Hybrid_type_traits_integer::instance()
00099 {
00100   return &integer_traits_instance;
00101 }
00102 
00103 
00104 Hybrid_type_traits_integer::Hybrid_type_traits_integer()
00105 {}
00106 
00107 
00108 } /* namespace drizzled */