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