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 namespace field {
00028 
00029 class Boolean : public Field 
00030 {
00031   bool ansi_display;
00032 
00033 public:
00034   Boolean(unsigned char *ptr_arg,
00035           uint32_t len_arg,
00036           unsigned char *null_ptr_arg,
00037           unsigned char null_bit_arg,
00038           const char *field_name_arg,
00039           bool ansi_display= false);
00040 
00041   enum_field_types type() const { return DRIZZLE_TYPE_BOOLEAN; }
00042   enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; }
00043   bool zero_pack() const { return 0; }
00044   int  reset(void) { ptr[0]= 0; return 0; }
00045   uint32_t pack_length() const { return sizeof(unsigned char); }
00046   uint32_t key_length() const { return sizeof(unsigned char); }
00047 
00048   int store(const char *to, uint32_t length, const charset_info_st * const charset);
00049   int store(double );
00050   int store(int64_t nr, bool unsigned_val);
00051   int store_decimal(const drizzled::type::Decimal*);
00052 
00053   String *val_str(String*,String *) const;
00054   double val_real() const;
00055   int64_t val_int() const;
00056   type::Decimal *val_decimal(type::Decimal *) const;
00057 
00058   Item_result result_type () const { return STRING_RESULT; }
00059   int cmp(const unsigned char*, const unsigned char*);
00060   void sort_string(unsigned char*, uint32_t);
00061   uint32_t max_display_length() { return 5; } // longest string is "false"
00062 
00063   bool can_be_compared_as_int64_t() const
00064   {
00065     return true;
00066   }
00067 
00068   inline String *val_str(String *str) { return val_str(str, str); }
00069   uint32_t size_of() const { return sizeof(*this); }
00070 
00071   static size_t max_string_length()
00072   {
00073     return sizeof(unsigned char);
00074   }
00075 
00076 private:
00077   void set(bool v)
00078   {
00079     ptr[0]= v;
00080   }
00081 
00082   bool isTrue() const
00083   {
00084     return ptr[0];
00085   }
00086 };
00087 
00088 } /* namespace field */
00089 } /* namespace drizzled */
00090 
00091