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/type/decimal.h> 00023 00024 namespace drizzled { 00025 00026 /*************************************************************************/ 00027 /* 00028 A framework to easily handle different return types for hybrid items 00029 (hybrid item is an item whose operand can be of any type, e.g. integer, 00030 real, decimal). 00031 */ 00032 00033 class Hybrid_type 00034 { 00035 public: 00036 int64_t integer; 00037 00038 double real; 00039 /* 00040 Use two decimal buffers interchangeably to speed up += operation 00041 which has no native support in decimal library. 00042 Hybrid_type+= arg is implemented as dec_buf[1]= dec_buf[0] + arg. 00043 The third decimal is used as a handy temporary storage. 00044 */ 00045 type::Decimal dec_buf[3]; 00046 int used_dec_buf_no; 00047 00048 /* 00049 Traits moved to a separate class to 00050 a) be able to easily change object traits in runtime 00051 b) they work as a differentiator for the union above 00052 */ 00053 const Hybrid_type_traits *traits; 00054 00055 Hybrid_type() {} 00056 /* XXX: add traits->copy() when needed */ 00057 Hybrid_type(const Hybrid_type &rhs) :traits(rhs.traits) {} 00058 }; 00059 00060 } /* namespace drizzled */ 00061