Drizzled Public API Documentation

hybrid_type_traits.cc
1 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3  *
4  * Copyright (C) 2008 Sun Microsystems, Inc.
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 #include <config.h>
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 
27 #include <math.h>
28 
29 namespace drizzled
30 {
31 
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 
79 type::Decimal *
80 Hybrid_type_traits::val_decimal(Hybrid_type *val, type::Decimal *) const
81 {
82  double2_class_decimal(E_DEC_FATAL_ERROR, val->real, val->dec_buf);
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 {}
107 
108 } /* namespace drizzled */
TODO: Rename this file - func.h is stupid.