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