Drizzled Public API Documentation

boolean.h

00001 /* - mode: c++ c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2010 Brian Aker
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; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019  */
00020 
00021 #pragma once
00022 
00023 #include <drizzled/field.h>
00024 #include <string>
00025 
00026 namespace drizzled
00027 {
00028 namespace field
00029 {
00030 
00031 class Boolean :public Field {
00032   bool ansi_display;
00033 
00034 public:
00035   Boolean(unsigned char *ptr_arg,
00036           uint32_t len_arg,
00037           unsigned char *null_ptr_arg,
00038           unsigned char null_bit_arg,
00039           const char *field_name_arg,
00040           bool ansi_display= false);
00041 
00042   enum_field_types type() const { return DRIZZLE_TYPE_BOOLEAN; }
00043   enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; }
00044   bool zero_pack() const { return 0; }
00045   int  reset(void) { ptr[0]= 0; return 0; }
00046   uint32_t pack_length() const { return sizeof(unsigned char); }
00047   uint32_t key_length() const { return sizeof(unsigned char); }
00048 
00049   int store(const char *to, uint32_t length, const CHARSET_INFO * const charset);
00050   int store(double );
00051   int store(int64_t nr, bool unsigned_val);
00052   int store_decimal(const drizzled::type::Decimal*);
00053 
00054   String *val_str(String*,String *) const;
00055   double val_real() const;
00056   int64_t val_int() const;
00057   type::Decimal *val_decimal(type::Decimal *) const;
00058 
00059   void sql_type(drizzled::String&) const;
00060 
00061   Item_result result_type () const { return STRING_RESULT; }
00062   int cmp(const unsigned char*, const unsigned char*);
00063   void sort_string(unsigned char*, uint32_t);
00064   uint32_t max_display_length() { return 5; } // longest string is "false"
00065 
00066   bool can_be_compared_as_int64_t() const
00067   {
00068     return true;
00069   }
00070 
00071   inline String *val_str(String *str) { return val_str(str, str); }
00072   uint32_t size_of() const { return sizeof(*this); }
00073 
00074   static size_t max_string_length()
00075   {
00076     return sizeof(unsigned char);
00077   }
00078 
00079 private:
00080   void setTrue();
00081 
00082   void setFalse()
00083   {
00084     ptr[0]= 0;
00085   }
00086 
00087   bool isTrue() const
00088   {
00089     return ptr[0] ? true : false;
00090   }
00091 };
00092 
00093 } /* namespace field */
00094 } /* namespace drizzled */
00095 
00096