Drizzled Public API Documentation

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