~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/boolean.h

  • Committer: Olaf van der Spek
  • Date: 2011-03-24 00:16:14 UTC
  • mto: This revision was merged to the branch mainline in revision 2251.
  • Revision ID: olafvdspek@gmail.com-20110324001614-wvmgc6eg52oq2321
Remove const_reference and reference from Session

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
{
 
26
 
 
27
namespace item
 
28
{
 
29
 
 
30
class Boolean: public Item_basic_constant
 
31
{
 
32
  bool value;
 
33
 
 
34
public:
 
35
  Boolean(const char *str_arg, bool arg) :
 
36
    Item_basic_constant(),
 
37
    value(arg)
 
38
  {
 
39
    max_length= value ? 4 : 5;
 
40
    fixed= true;
 
41
    name= (const_cast<char *>(str_arg));
 
42
  }
 
43
 
 
44
  Boolean(bool arg) :
 
45
    value(arg)
 
46
  {
 
47
    max_length= value ? 4 : 5;
 
48
    fixed= true;
 
49
 
 
50
    if (value)
 
51
    {
 
52
      name= const_cast<char *>("TRUE");
 
53
    }
 
54
    else
 
55
    {
 
56
      name= const_cast<char *>("FALSE");
 
57
    }
 
58
  }
 
59
 
 
60
  enum Type type() const { return BOOLEAN_ITEM; }
 
61
 
 
62
  virtual bool val_bool()
 
63
  {
 
64
    return value;
 
65
  }
 
66
 
 
67
  double val_real()
 
68
  {
 
69
    return value ? 1 : 0;
 
70
  }
 
71
 
 
72
  int64_t val_int() 
 
73
  {
 
74
    return value ? 1 : 0;
 
75
  }
 
76
 
 
77
  drizzled::String* val_str(drizzled::String *value_buffer)
 
78
  {
 
79
    value_buffer->realloc(5);
 
80
 
 
81
    if (value)
 
82
    {
 
83
      value_buffer->append("TRUE");
 
84
    }
 
85
    else
 
86
    {
 
87
      value_buffer->append("FALSE");
 
88
    }
 
89
 
 
90
    return value_buffer;
 
91
  }
 
92
 
 
93
  type::Decimal* val_decimal(type::Decimal *dec)
 
94
  {
 
95
    (void)dec;
 
96
    return 0;
 
97
  }
 
98
 
 
99
};
 
100
 
 
101
} /* namespace item */
 
102
} /* namespace drizzled */
 
103
 
 
104
#include <drizzled/item/true.h>
 
105
#include <drizzled/item/false.h>
 
106