~drizzle-trunk/drizzle/development

1097.2.2 by clint at fewbar
style/documentation cleanups and replacing copyright notices
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) 2009 Sun Microsystems, Inc.
1097.2.2 by clint at fewbar
style/documentation cleanups and replacing copyright notices
5
 *
1093.1.36 by Jay Pipes
Fix indentation of temporal_interval.h per IRC conversation with clint
6
 *  Authors: 
7
 *
8
 *  Clint Byrum <clint@fewbar.com>
1097.2.2 by clint at fewbar
style/documentation cleanups and replacing copyright notices
9
 *
10
 *  This program is free software; you can redistribute it and/or modify
11
 *  it under the terms of the GNU General Public License as published by
12
 *  the Free Software Foundation; version 2 of the License.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU General Public License
20
 *  along with this program; if not, write to the Free Software
21
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22
 */
1122.2.10 by Monty Taylor
Fixed all of the include guards.
23
2234 by Brian Aker
Mass removal of ifdef/endif in favor of pragma once.
24
#pragma once
1122.2.10 by Monty Taylor
Fixed all of the include guards.
25
26
/* @TODO Replace this include with some forward decls */
2154.2.4 by Brian Aker
This fixes 716459
27
#include <drizzled/item.h>
28
#include <drizzled/type/time.h>
1097.2.1 by clint at fewbar
refactoring INTERVAL into C++ class
29
1093.1.36 by Jay Pipes
Fix indentation of temporal_interval.h per IRC conversation with clint
30
namespace drizzled 
31
{
32
33
/**
34
 * @brief
35
 *  Stores time interval for date/time manipulation
36
 */
37
class TemporalInterval
38
{
39
public:
40
41
  TemporalInterval(uint32_t in_year,
2154.2.4 by Brian Aker
This fixes 716459
42
                   uint32_t in_month,
43
                   uint32_t in_day,
44
                   uint32_t in_hour,
45
                   uint64_t in_minute,
46
                   uint64_t in_second,
47
                   uint64_t in_second_part,
48
                   bool in_neg) :
49
    year(in_year),
50
    month(in_month),
51
    day(in_day),
52
    hour(in_hour),
53
    minute(in_minute),
54
    second(in_second),
55
    second_part(in_second_part),
56
    neg(in_neg)
1093.1.36 by Jay Pipes
Fix indentation of temporal_interval.h per IRC conversation with clint
57
  {}
58
2154.2.4 by Brian Aker
This fixes 716459
59
  TemporalInterval() :
60
    year(0),
61
    month(0),
62
    day(0),
63
    hour(0),
64
    minute(0),
65
    second(0),
66
    second_part(0),
67
    neg(false)
1093.1.36 by Jay Pipes
Fix indentation of temporal_interval.h per IRC conversation with clint
68
  {}
69
70
  /**
71
   * Sets whether or not this object specifies a negative interval
72
   * @param[in] in_neg true if this is a negative interval, false if not
73
   */
1377.8.29 by Paweł Blokus
tests for init/deinit_temporal_formats
74
  inline void setNegative(bool in_neg= true)
1093.1.36 by Jay Pipes
Fix indentation of temporal_interval.h per IRC conversation with clint
75
  {
76
    neg= in_neg;
77
  }
78
79
  /**
80
   * reverse boolean value of the negative flag
81
   */
1377.8.29 by Paweł Blokus
tests for init/deinit_temporal_formats
82
  inline void toggleNegative()
1093.1.36 by Jay Pipes
Fix indentation of temporal_interval.h per IRC conversation with clint
83
  {
84
    neg= !neg;
85
  }
86
87
  /**
88
   * @retval true this is a negative temporal interval
89
   * @retval false this is a positive temporal interval
90
   */
1377.8.29 by Paweł Blokus
tests for init/deinit_temporal_formats
91
  inline bool getNegative() const
1093.1.36 by Jay Pipes
Fix indentation of temporal_interval.h per IRC conversation with clint
92
  {
93
    return neg;
94
  }
95
1891.2.1 by Monty Taylor
Fixed things to make things compile with clang
96
  inline uint32_t  get_year() { return year; }
97
  inline void set_year(uint32_t new_year) { year = new_year; }
98
99
  inline uint32_t  get_month(){ return month; }
100
  inline void set_month(uint32_t new_month) { month = new_month; }
101
102
  inline uint32_t  get_day(){ return day; }
103
  inline void set_day(uint32_t new_day) { day = new_day; }
104
105
  inline uint32_t  get_hour(){ return hour; }
106
  inline void set_hour(uint32_t new_hour) { hour = new_hour; }
107
108
  inline uint64_t  get_minute(){ return minute; }
109
  inline void set_minute(uint32_t new_minute) { minute = new_minute; }
110
111
  inline uint64_t  get_second(){ return second; }
112
  inline void set_second(uint32_t new_second) { second = new_second; }
113
114
  inline uint64_t  get_second_part(){ return second_part; }
115
  inline void set_second_part(uint32_t new_second_part) { second_part = new_second_part; }
1377.8.29 by Paweł Blokus
tests for init/deinit_temporal_formats
116
1093.1.36 by Jay Pipes
Fix indentation of temporal_interval.h per IRC conversation with clint
117
  /**
118
   * Populate this TemporalInterval from a string value
119
   *
120
   * To make code easy, allow interval objects without separators.
121
   *
122
   * @param args argument Item structure
123
   * @param int_type type of interval to create
124
   * @param str_value String pointer to the input value
125
   * @return true if the string would result in a null interval
126
   * 
127
   */
128
  bool initFromItem(Item *args, interval_type int_type, String *str_value);
129
130
  /**
131
   * Adds this interval to a DRIZZLE_LTIME structure
132
   *
133
   * @param[in,out] ltime the interval will be added to ltime directly in the ltime structure
134
   * @param[in] int_type the type of interval requested
135
   * @retval true date was added and value stored properly
136
   * @retval false result of addition is a null value
137
   */
2030.1.5 by Brian Aker
Update for moving DRIZZLE_TIME to type::Time
138
  bool addDate(type::Time *ltime, interval_type int_type);
1093.1.36 by Jay Pipes
Fix indentation of temporal_interval.h per IRC conversation with clint
139
140
private:
141
142
  /**
143
   * The maximum number of text elements to extract into a temporal interval
144
   */
145
  static const uint32_t MAX_STRING_ELEMENTS = 5;
146
147
  /**
148
   * Each of these corresponds to an 'interval_type'
149
   */
150
  static const uint32_t NUM_YEAR_MONTH_STRING_ELEMENTS         = 2;
151
  static const uint32_t NUM_DAY_HOUR_STRING_ELEMENTS           = 2; 
152
  static const uint32_t NUM_DAY_MICROSECOND_STRING_ELEMENTS    = 5;
153
  static const uint32_t NUM_DAY_MINUTE_STRING_ELEMENTS         = 3;
154
  static const uint32_t NUM_DAY_SECOND_STRING_ELEMENTS         = 4;
155
  static const uint32_t NUM_HOUR_MICROSECOND_STRING_ELEMENTS   = 4;
156
  static const uint32_t NUM_HOUR_MINUTE_STRING_ELEMENTS        = 2;
157
  static const uint32_t NUM_HOUR_SECOND_STRING_ELEMENTS        = 3;
158
  static const uint32_t NUM_MINUTE_MICROSECOND_STRING_ELEMENTS = 3;
159
  static const uint32_t NUM_MINUTE_SECOND_STRING_ELEMENTS      = 2;
160
  static const uint32_t NUM_SECOND_MICROSECOND_STRING_ELEMENTS = 2;
161
162
  /**
163
   *  @details
164
   *  Get a array of positive numbers from a string object.
165
   *  Each number is separated by 1 non digit character
166
   *  Return error if there is too many numbers.
167
   *  If there is too few numbers, assume that the numbers are left out
168
   *  from the high end. This allows one to give:
169
   *  DAY_TO_SECOND as "D MM:HH:SS", "MM:HH:SS" "HH:SS" or as seconds.
170
   *
171
   *  @param[in] length:         length of str
172
   *  @param[in] cs:             charset of str
173
   *  @param[out] values:         array of results
174
   *  @param[out] count:          count of elements in result array
175
   *  @param transform_msec: if value is true we suppose
176
   *  that the last part of string value is microseconds
177
   *  and we should transform value to six digit value.
178
   *  For example, '1.1' -> '1.100000'
179
   */
180
  bool getIntervalFromString(const char *str,
181
                             uint32_t length, 
2254 by Brian Aker
Shift CHARSET_INFO to charset_info_st
182
                             const charset_info_st * const cs,
1093.1.36 by Jay Pipes
Fix indentation of temporal_interval.h per IRC conversation with clint
183
                             uint32_t count, 
184
                             uint64_t *values,
185
                             bool transform_msec);
186
187
  uint32_t  year;
188
  uint32_t  month;
189
  uint32_t  day;
190
  uint32_t  hour;
191
  uint64_t  minute;
192
  uint64_t  second;
193
  uint64_t  second_part;
194
  bool      neg;
195
196
};
197
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
198
} /* namespace drizzled */
1122.2.10 by Monty Taylor
Fixed all of the include guards.
199