584.4.2
by Monty Taylor
Split out hybrid_type_traits. |
1 |
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
1999.6.1
by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file |
4 |
* Copyright (C) 2008 Sun Microsystems, Inc.
|
584.4.2
by Monty Taylor
Split out hybrid_type_traits. |
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 |
||
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
20 |
#include <config.h> |
2154.2.4
by Brian Aker
This fixes 716459 |
21 |
|
22 |
#include <drizzled/field.h> |
|
23 |
#include <drizzled/hybrid_type.h> |
|
24 |
#include <drizzled/hybrid_type_traits.h> |
|
25 |
#include <drizzled/item.h> |
|
26 |
||
1241.9.1
by Monty Taylor
Removed global.h. Fixed all the headers. |
27 |
#include <math.h> |
584.4.7
by Monty Taylor
Removed a big bank of includes from item.h. |
28 |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
29 |
namespace drizzled |
30 |
{
|
|
31 |
||
584.4.2
by Monty Taylor
Split out hybrid_type_traits. |
32 |
static const Hybrid_type_traits real_traits_instance; |
33 |
||
34 |
Item_result Hybrid_type_traits::type() const |
|
35 |
{
|
|
36 |
return REAL_RESULT; |
|
37 |
}
|
|
38 |
||
39 |
||
40 |
void Hybrid_type_traits::fix_length_and_dec(Item *item, Item *arg) const |
|
41 |
{
|
|
42 |
item->decimals= NOT_FIXED_DEC; |
|
43 |
item->max_length= item->float_length(arg->decimals); |
|
44 |
}
|
|
45 |
||
46 |
||
47 |
/* Hybrid_type operations. */
|
|
48 |
void Hybrid_type_traits::set_zero(Hybrid_type *val) const |
|
49 |
{
|
|
50 |
val->real= 0.0; |
|
51 |
}
|
|
52 |
||
53 |
||
54 |
void Hybrid_type_traits::add(Hybrid_type *val, Field *f) const |
|
55 |
{
|
|
56 |
val->real+= f->val_real(); |
|
57 |
}
|
|
58 |
||
59 |
||
60 |
void Hybrid_type_traits::div(Hybrid_type *val, uint64_t u) const |
|
61 |
{
|
|
62 |
val->real/= uint64_t2double(u); |
|
63 |
}
|
|
64 |
||
65 |
||
66 |
int64_t Hybrid_type_traits::val_int(Hybrid_type *val, |
|
67 |
bool) const |
|
68 |
{
|
|
69 |
return (int64_t) rint(val->real); |
|
70 |
}
|
|
71 |
||
72 |
||
73 |
double Hybrid_type_traits::val_real(Hybrid_type *val) const |
|
74 |
{
|
|
75 |
return val->real; |
|
76 |
}
|
|
77 |
||
78 |
||
2030.1.4
by Brian Aker
Change my_decimal to Decimal |
79 |
type::Decimal * |
80 |
Hybrid_type_traits::val_decimal(Hybrid_type *val, type::Decimal *) const |
|
584.4.2
by Monty Taylor
Split out hybrid_type_traits. |
81 |
{
|
2030.1.3
by Brian Aker
Second pass through function names. |
82 |
double2_class_decimal(E_DEC_FATAL_ERROR, val->real, val->dec_buf); |
584.4.2
by Monty Taylor
Split out hybrid_type_traits. |
83 |
return val->dec_buf; |
84 |
}
|
|
85 |
||
86 |
||
87 |
String * |
|
88 |
Hybrid_type_traits::val_str(Hybrid_type *val, String *to, |
|
89 |
uint8_t decimals) const |
|
90 |
{
|
|
91 |
to->set_real(val->real, decimals, &my_charset_bin); |
|
92 |
return to; |
|
93 |
}
|
|
94 |
||
95 |
||
96 |
const Hybrid_type_traits *Hybrid_type_traits::instance() |
|
97 |
{
|
|
98 |
return &real_traits_instance; |
|
99 |
}
|
|
100 |
||
101 |
||
102 |
Hybrid_type_traits::Hybrid_type_traits() |
|
103 |
{}
|
|
104 |
||
105 |
Hybrid_type_traits::~Hybrid_type_traits() |
|
106 |
{}
|
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
107 |
|
108 |
} /* namespace drizzled */ |