~drizzle-trunk/drizzle/development

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
31
#ifndef DRIZZLED_TEMPORAL_FORMAT_MATCH_H
32
#define DRIZZLED_TEMPORAL_FORMAT_MATCH_H
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
  int32_t _match_vector[OUT_VECTOR_SIZE]; /**< Stores match substring indexes */
53
  /* Index of the pattern which is a specific temporal part */
54
  uint32_t _year_part_index;
55
  uint32_t _month_part_index;
56
  uint32_t _day_part_index;
57
  uint32_t _hour_part_index;
58
  uint32_t _minute_part_index;
59
  uint32_t _second_part_index;
60
  uint32_t _usecond_part_index;
813.1.12 by Jay Pipes
Fixes for SECOND() function to use new Temporal system. Because
61
  uint32_t _nsecond_part_index;
813.1.2 by Jay Pipes
First function cleanup for temporal handling: YEAR()
62
public:
63
  /**
64
   * Constructor which takes a regex string as
65
   * it's only parameter.
66
   *
67
   * @param Pattern to use in matching
68
   */
69
  TemporalFormat(const char *pattern);
70
  /**
71
   * Returns whether the instance is compiled
72
   * and contains a valid regular expression.
73
   */
74
  inline bool is_valid() const {return _re && (_error == NULL);}
75
  /**
76
   * Sets the index for the year part of the pattern.
77
   *
78
   * @param index of the temporal part
79
   */
80
  inline void set_year_part_index(int32_t index) {_year_part_index= ((index - 1) * 2) + 2;}
81
  /**
82
   * Sets the index for the month part of the pattern.
83
   *
84
   * @param index of the temporal part
85
   */
86
  inline void set_month_part_index(int32_t index) {_month_part_index= ((index - 1) * 2) + 2;}
87
  /**
88
   * Sets the index for the day part of the pattern.
89
   *
90
   * @param index of the temporal part
91
   */
92
  inline void set_day_part_index(int32_t index) {_day_part_index= ((index - 1) * 2) + 2;}
93
  /**
94
   * Sets the index for the hour part of the pattern.
95
   *
96
   * @param index of the temporal part
97
   */
98
  inline void set_hour_part_index(int32_t index) {_hour_part_index= ((index - 1) * 2) + 2;}
99
  /**
100
   * Sets the index for the minute part of the pattern.
101
   *
102
   * @param index of the temporal part
103
   */
104
  inline void set_minute_part_index(int32_t index) {_minute_part_index= ((index - 1) * 2) + 2;}
105
  /**
106
   * Sets the index for the second part of the pattern.
107
   *
108
   * @param index of the temporal part
109
   */
110
  inline void set_second_part_index(int32_t index) {_second_part_index= ((index - 1) * 2) + 2;}
111
  /**
813.1.12 by Jay Pipes
Fixes for SECOND() function to use new Temporal system. Because
112
   * Sets the index for the microsecond part of the pattern.
813.1.2 by Jay Pipes
First function cleanup for temporal handling: YEAR()
113
   *
114
   * @param index of the temporal part
115
   */
116
  inline void set_usecond_part_index(int32_t index) {_usecond_part_index= ((index - 1) * 2) + 2;}
117
  /**
813.1.12 by Jay Pipes
Fixes for SECOND() function to use new Temporal system. Because
118
   * Sets the index for the nanosecond part of the pattern.
119
   *
120
   * @param index of the temporal part
121
   */
122
  inline void set_nsecond_part_index(int32_t index) {_nsecond_part_index= ((index - 1) * 2) + 2;}
123
  /**
813.1.2 by Jay Pipes
First function cleanup for temporal handling: YEAR()
124
   * Returns true or false whether a supplied
125
   * string matches the internal pattern for this
126
   * temporal format string.
127
   *
128
   * @param Subject to match
129
   * @param Length of subject string
130
   */
131
  bool matches(const char *data, size_t data_len, Temporal *to);
132
};
133
134
} /* end namespace drizzled */
135
136
/**
137
 * Initializes the regular expressions used by the datetime
138
 * string matching conversion functions.
139
 *
140
 * Returns whether initialization was successful.
141
 *
142
 * @note
143
 *
144
 * This function is not thread-safe.  Call before threading
145
 * is initialized on server init.
146
 */
147
bool init_temporal_formats();
148
149
#endif /* DRIZZLED_TEMPORAL_FORMAT_MATCH_H */