Drizzled Public API Documentation

boolean.h
1 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3  *
4  * Copyright (C) 2010 Brian Aker
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 #pragma once
21 
22 #include <drizzled/item/basic_constant.h>
23 
24 namespace drizzled {
25 namespace item {
26 
28 {
29  bool value;
30 
31 public:
32  Boolean(const char *str_arg, bool arg) :
33  value(arg)
34  {
35  max_length= value ? 4 : 5;
36  fixed= true;
37  name= str_arg;
38  }
39 
40  Boolean(bool arg) :
41  value(arg)
42  {
43  max_length= value ? 4 : 5;
44  fixed= true;
45  name= value ? "TRUE" : "FALSE";
46  }
47 
48  enum Type type() const { return BOOLEAN_ITEM; }
49 
50  Item_result result_type() const
51  {
52  return INT_RESULT;
53  }
54 
55  virtual bool val_bool()
56  {
57  return value;
58  }
59 
60  double val_real()
61  {
62  return value ? 1 : 0;
63  }
64 
65  int64_t val_int()
66  {
67  return value ? 1 : 0;
68  }
69 
71  {
72  value_buffer->realloc(5);
73 
74  if (value)
75  {
76  value_buffer->copy("TRUE", 4, default_charset());
77  }
78  else
79  {
80  value_buffer->copy("FALSE", 5, default_charset());
81  }
82 
83  return value_buffer;
84  }
85 
87  {
88  return 0;
89  }
90 
91 };
92 
93 } /* namespace item */
94 } /* namespace drizzled */
95 
96 #include <drizzled/item/true.h>
97 #include <drizzled/item/false.h>
98 
virtual bool val_bool()
Definition: boolean.h:55
const char * name
Definition: item.h:110
bool fixed
Definition: item.h:120
TODO: Rename this file - func.h is stupid.
drizzled::String * val_str(drizzled::String *value_buffer)
Definition: boolean.h:70
type::Decimal * val_decimal(type::Decimal *)
Definition: boolean.h:86