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; 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/item/basic_constant.h>
00023 
00024 namespace drizzled
00025 {
00026 
00027 namespace item
00028 {
00029 
00030 class Boolean: public Item_basic_constant
00031 {
00032   bool value;
00033 
00034 public:
00035   Boolean(const char *str_arg, bool arg) :
00036     Item_basic_constant(),
00037     value(arg)
00038   {
00039     max_length= value ? 4 : 5;
00040     fixed= true;
00041     name= (const_cast<char *>(str_arg));
00042   }
00043 
00044   Boolean(bool arg) :
00045     value(arg)
00046   {
00047     max_length= value ? 4 : 5;
00048     fixed= true;
00049 
00050     if (value)
00051     {
00052       name= const_cast<char *>("TRUE");
00053     }
00054     else
00055     {
00056       name= const_cast<char *>("FALSE");
00057     }
00058   }
00059 
00060   enum Type type() const { return BOOLEAN_ITEM; }
00061 
00062   virtual bool val_bool()
00063   {
00064     return value;
00065   }
00066 
00067   double val_real()
00068   {
00069     return value ? 1 : 0;
00070   }
00071 
00072   int64_t val_int() 
00073   {
00074     return value ? 1 : 0;
00075   }
00076 
00077   drizzled::String* val_str(drizzled::String *value_buffer)
00078   {
00079     value_buffer->realloc(5);
00080 
00081     if (value)
00082     {
00083       value_buffer->append("TRUE");
00084     }
00085     else
00086     {
00087       value_buffer->append("FALSE");
00088     }
00089 
00090     return value_buffer;
00091   }
00092 
00093   type::Decimal* val_decimal(type::Decimal *dec)
00094   {
00095     (void)dec;
00096     return 0;
00097   }
00098 
00099 };
00100 
00101 } /* namespace item */
00102 } /* namespace drizzled */
00103 
00104 #include <drizzled/item/true.h>
00105 #include <drizzled/item/false.h>
00106