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/definitions.h> |
|
23 |
#include <drizzled/field.h> |
|
24 |
#include <drizzled/hybrid_type.h> |
|
25 |
#include <drizzled/hybrid_type_traits_decimal.h> |
|
26 |
#include <drizzled/item.h> |
|
584.4.2
by Monty Taylor
Split out hybrid_type_traits. |
27 |
|
1067.4.4
by Nathan Williams
The rest of the files in the drizzled directory were purged of the cmin macro and replace with std::min (except for the definition in globals.h and 1 usage in stacktrace.cc). |
28 |
#include <algorithm> |
29 |
||
30 |
using namespace std; |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
31 |
namespace drizzled |
32 |
{
|
|
584.4.2
by Monty Taylor
Split out hybrid_type_traits. |
33 |
|
34 |
/* Hybrid_type_traits_decimal */
|
|
35 |
static const Hybrid_type_traits_decimal decimal_traits_instance; |
|
36 |
||
37 |
||
38 |
Item_result Hybrid_type_traits_decimal::type() const { return DECIMAL_RESULT; } |
|
39 |
||
40 |
||
41 |
void
|
|
42 |
Hybrid_type_traits_decimal::fix_length_and_dec(Item *item, Item *arg) const |
|
43 |
{
|
|
44 |
item->decimals= arg->decimals; |
|
1067.4.4
by Nathan Williams
The rest of the files in the drizzled directory were purged of the cmin macro and replace with std::min (except for the definition in globals.h and 1 usage in stacktrace.cc). |
45 |
item->max_length= min(arg->max_length + DECIMAL_LONGLONG_DIGITS, |
584.4.2
by Monty Taylor
Split out hybrid_type_traits. |
46 |
(unsigned int)DECIMAL_MAX_STR_LENGTH); |
47 |
}
|
|
48 |
||
49 |
||
50 |
void Hybrid_type_traits_decimal::set_zero(Hybrid_type *val) const |
|
51 |
{
|
|
2034.2.4
by Brian Aker
Further encapsulation for DECIMAL. |
52 |
val->dec_buf[0].set_zero(); |
584.4.2
by Monty Taylor
Split out hybrid_type_traits. |
53 |
val->used_dec_buf_no= 0; |
54 |
}
|
|
55 |
||
56 |
||
57 |
void Hybrid_type_traits_decimal::add(Hybrid_type *val, Field *f) const |
|
58 |
{
|
|
2030.1.2
by Brian Aker
First pass in refactoring of the name of my_decimal. |
59 |
class_decimal_add(E_DEC_FATAL_ERROR, |
584.4.2
by Monty Taylor
Split out hybrid_type_traits. |
60 |
&val->dec_buf[val->used_dec_buf_no ^ 1], |
61 |
&val->dec_buf[val->used_dec_buf_no], |
|
62 |
f->val_decimal(&val->dec_buf[2])); |
|
63 |
val->used_dec_buf_no^= 1; |
|
64 |
}
|
|
65 |
||
66 |
||
67 |
/**
|
|
68 |
@todo
|
|
69 |
what is '4' for scale?
|
|
70 |
*/
|
|
71 |
void Hybrid_type_traits_decimal::div(Hybrid_type *val, uint64_t u) const |
|
72 |
{
|
|
2030.1.3
by Brian Aker
Second pass through function names. |
73 |
int2_class_decimal(E_DEC_FATAL_ERROR, u, true, &val->dec_buf[2]); |
584.4.2
by Monty Taylor
Split out hybrid_type_traits. |
74 |
/* XXX: what is '4' for scale? */
|
2030.1.2
by Brian Aker
First pass in refactoring of the name of my_decimal. |
75 |
class_decimal_div(E_DEC_FATAL_ERROR, |
584.4.2
by Monty Taylor
Split out hybrid_type_traits. |
76 |
&val->dec_buf[val->used_dec_buf_no ^ 1], |
77 |
&val->dec_buf[val->used_dec_buf_no], |
|
78 |
&val->dec_buf[2], 4); |
|
79 |
val->used_dec_buf_no^= 1; |
|
80 |
}
|
|
81 |
||
82 |
||
83 |
int64_t
|
|
84 |
Hybrid_type_traits_decimal::val_int(Hybrid_type *val, bool unsigned_flag) const |
|
85 |
{
|
|
86 |
int64_t result; |
|
2034.2.1
by Brian Aker
Move class_decimal2int to a method on Decimal. |
87 |
val->dec_buf[val->used_dec_buf_no].val_int32(E_DEC_FATAL_ERROR, unsigned_flag, &result); |
88 |
||
584.4.2
by Monty Taylor
Split out hybrid_type_traits. |
89 |
return result; |
90 |
}
|
|
91 |
||
92 |
||
93 |
double
|
|
94 |
Hybrid_type_traits_decimal::val_real(Hybrid_type *val) const |
|
95 |
{
|
|
2030.1.3
by Brian Aker
Second pass through function names. |
96 |
class_decimal2double(E_DEC_FATAL_ERROR, &val->dec_buf[val->used_dec_buf_no], |
584.4.2
by Monty Taylor
Split out hybrid_type_traits. |
97 |
&val->real); |
98 |
return val->real; |
|
99 |
}
|
|
100 |
||
101 |
||
2030.1.4
by Brian Aker
Change my_decimal to Decimal |
102 |
type::Decimal *Hybrid_type_traits_decimal::val_decimal(Hybrid_type *val, |
103 |
type::Decimal *) const |
|
584.4.2
by Monty Taylor
Split out hybrid_type_traits. |
104 |
{ return &val->dec_buf[val->used_dec_buf_no]; } |
105 |
||
106 |
||
107 |
String * |
|
108 |
Hybrid_type_traits_decimal::val_str(Hybrid_type *val, String *to, |
|
109 |
uint8_t decimals) const |
|
110 |
{
|
|
2030.1.2
by Brian Aker
First pass in refactoring of the name of my_decimal. |
111 |
class_decimal_round(E_DEC_FATAL_ERROR, &val->dec_buf[val->used_dec_buf_no], |
584.4.2
by Monty Taylor
Split out hybrid_type_traits. |
112 |
decimals, false, &val->dec_buf[2]); |
2137.1.8
by Brian Aker
Remove error type from str convert since we always want an error. |
113 |
class_decimal2string(&val->dec_buf[2], 0, to); |
584.4.2
by Monty Taylor
Split out hybrid_type_traits. |
114 |
return to; |
115 |
}
|
|
116 |
||
117 |
||
118 |
const Hybrid_type_traits_decimal *Hybrid_type_traits_decimal::instance() |
|
119 |
{
|
|
120 |
return &decimal_traits_instance; |
|
121 |
}
|
|
122 |
||
123 |
||
124 |
Hybrid_type_traits_decimal::Hybrid_type_traits_decimal() |
|
125 |
{}
|
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
126 |
|
127 |
} /* namespace drizzled */ |