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