813.1.2
by Jay Pipes
First function cleanup for temporal handling: YEAR() |
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
|
|
5 |
*
|
|
6 |
* Authors:
|
|
7 |
*
|
|
8 |
* Jay Pipes <jay.pipes@sun.com>
|
|
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; either version 2 of the License, or
|
|
13 |
* (at your option) any later version.
|
|
14 |
*
|
|
15 |
* This program is distributed in the hope that it will be useful,
|
|
16 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
18 |
* GNU General Public License for more details.
|
|
19 |
*
|
|
20 |
* You should have received a copy of the GNU General Public License
|
|
21 |
* along with this program; if not, write to the Free Software
|
|
22 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
23 |
*/
|
|
24 |
||
25 |
/**
|
|
26 |
* @file
|
|
27 |
*
|
|
28 |
* Defines the API for matching datetime formats.
|
|
29 |
*/
|
|
30 |
||
1122.2.10
by Monty Taylor
Fixed all of the include guards. |
31 |
#ifndef DRIZZLED_TEMPORAL_FORMAT_H
|
32 |
#define DRIZZLED_TEMPORAL_FORMAT_H
|
|
813.1.2
by Jay Pipes
First function cleanup for temporal handling: YEAR() |
33 |
|
859.1.6
by Monty Taylor
Fix for multi-versions of PCRE thing. |
34 |
#include PCRE_HEADER
|
813.1.2
by Jay Pipes
First function cleanup for temporal handling: YEAR() |
35 |
|
36 |
/* Output vector size for pcre matching. Should be multiple of 3. */
|
|
37 |
#define OUT_VECTOR_SIZE 30
|
|
38 |
||
39 |
namespace drizzled |
|
40 |
{
|
|
41 |
||
42 |
/* Forward declaration needed */
|
|
43 |
class Temporal; |
|
44 |
||
45 |
class TemporalFormat |
|
46 |
{
|
|
47 |
protected: |
|
48 |
const char *_pattern; /**< The regular expression string to match */ |
|
49 |
pcre *_re; /**< The compiled regular expression struct */ |
|
50 |
int32_t _error_offset; /**< Any error encountered during compilation or matching */ |
|
51 |
const char *_error; |
|
52 |
/* Index of the pattern which is a specific temporal part */
|
|
53 |
uint32_t _year_part_index; |
|
54 |
uint32_t _month_part_index; |
|
55 |
uint32_t _day_part_index; |
|
56 |
uint32_t _hour_part_index; |
|
57 |
uint32_t _minute_part_index; |
|
58 |
uint32_t _second_part_index; |
|
59 |
uint32_t _usecond_part_index; |
|
813.1.12
by Jay Pipes
Fixes for SECOND() function to use new Temporal system. Because |
60 |
uint32_t _nsecond_part_index; |
813.1.2
by Jay Pipes
First function cleanup for temporal handling: YEAR() |
61 |
public: |
62 |
/**
|
|
63 |
* Constructor which takes a regex string as
|
|
64 |
* it's only parameter.
|
|
65 |
*
|
|
66 |
* @param Pattern to use in matching
|
|
67 |
*/
|
|
68 |
TemporalFormat(const char *pattern); |
|
69 |
/**
|
|
70 |
* Returns whether the instance is compiled
|
|
71 |
* and contains a valid regular expression.
|
|
72 |
*/
|
|
73 |
inline bool is_valid() const {return _re && (_error == NULL);} |
|
74 |
/**
|
|
75 |
* Sets the index for the year part of the pattern.
|
|
76 |
*
|
|
77 |
* @param index of the temporal part
|
|
78 |
*/
|
|
79 |
inline void set_year_part_index(int32_t index) {_year_part_index= ((index - 1) * 2) + 2;} |
|
80 |
/**
|
|
81 |
* Sets the index for the month part of the pattern.
|
|
82 |
*
|
|
83 |
* @param index of the temporal part
|
|
84 |
*/
|
|
85 |
inline void set_month_part_index(int32_t index) {_month_part_index= ((index - 1) * 2) + 2;} |
|
86 |
/**
|
|
87 |
* Sets the index for the day part of the pattern.
|
|
88 |
*
|
|
89 |
* @param index of the temporal part
|
|
90 |
*/
|
|
91 |
inline void set_day_part_index(int32_t index) {_day_part_index= ((index - 1) * 2) + 2;} |
|
92 |
/**
|
|
93 |
* Sets the index for the hour part of the pattern.
|
|
94 |
*
|
|
95 |
* @param index of the temporal part
|
|
96 |
*/
|
|
97 |
inline void set_hour_part_index(int32_t index) {_hour_part_index= ((index - 1) * 2) + 2;} |
|
98 |
/**
|
|
99 |
* Sets the index for the minute part of the pattern.
|
|
100 |
*
|
|
101 |
* @param index of the temporal part
|
|
102 |
*/
|
|
103 |
inline void set_minute_part_index(int32_t index) {_minute_part_index= ((index - 1) * 2) + 2;} |
|
104 |
/**
|
|
105 |
* Sets the index for the second part of the pattern.
|
|
106 |
*
|
|
107 |
* @param index of the temporal part
|
|
108 |
*/
|
|
109 |
inline void set_second_part_index(int32_t index) {_second_part_index= ((index - 1) * 2) + 2;} |
|
110 |
/**
|
|
813.1.12
by Jay Pipes
Fixes for SECOND() function to use new Temporal system. Because |
111 |
* Sets the index for the microsecond part of the pattern.
|
813.1.2
by Jay Pipes
First function cleanup for temporal handling: YEAR() |
112 |
*
|
113 |
* @param index of the temporal part
|
|
114 |
*/
|
|
115 |
inline void set_usecond_part_index(int32_t index) {_usecond_part_index= ((index - 1) * 2) + 2;} |
|
116 |
/**
|
|
813.1.12
by Jay Pipes
Fixes for SECOND() function to use new Temporal system. Because |
117 |
* Sets the index for the nanosecond part of the pattern.
|
118 |
*
|
|
119 |
* @param index of the temporal part
|
|
120 |
*/
|
|
121 |
inline void set_nsecond_part_index(int32_t index) {_nsecond_part_index= ((index - 1) * 2) + 2;} |
|
122 |
/**
|
|
813.1.2
by Jay Pipes
First function cleanup for temporal handling: YEAR() |
123 |
* Returns true or false whether a supplied
|
124 |
* string matches the internal pattern for this
|
|
125 |
* temporal format string.
|
|
126 |
*
|
|
127 |
* @param Subject to match
|
|
128 |
* @param Length of subject string
|
|
129 |
*/
|
|
130 |
bool matches(const char *data, size_t data_len, Temporal *to); |
|
131 |
};
|
|
132 |
||
133 |
||
134 |
/**
|
|
135 |
* Initializes the regular expressions used by the datetime
|
|
136 |
* string matching conversion functions.
|
|
137 |
*
|
|
138 |
* Returns whether initialization was successful.
|
|
139 |
*
|
|
140 |
* @note
|
|
141 |
*
|
|
142 |
* This function is not thread-safe. Call before threading
|
|
143 |
* is initialized on server init.
|
|
144 |
*/
|
|
145 |
bool init_temporal_formats(); |
|
1089.1.3
by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix |
146 |
/**
|
147 |
* Frees all memory allocated for temporal format objects
|
|
148 |
*/
|
|
149 |
void deinit_temporal_formats(); |
|
813.1.2
by Jay Pipes
First function cleanup for temporal handling: YEAR() |
150 |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
151 |
} /* end namespace drizzled */ |
152 |
||
1122.2.10
by Monty Taylor
Fixed all of the include guards. |
153 |
#endif /* DRIZZLED_TEMPORAL_FORMAT_H */ |