390.1.2
by Monty Taylor
Fixed copyright headers in drizzled/ |
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) 2008 Sun Microsystems, Inc.
|
390.1.2
by Monty Taylor
Fixed copyright headers in drizzled/ |
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or modify
|
|
7 |
* it under the terms of the GNU General Public License as published by
|
|
8 |
* the Free Software Foundation; version 2 of the License.
|
|
9 |
*
|
|
10 |
* This program is distributed in the hope that it will be useful,
|
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 |
* GNU General Public License for more details.
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License
|
|
16 |
* along with this program; if not, write to the Free Software
|
|
17 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
18 |
*/
|
|
1
by brian
clean slate |
19 |
|
2234
by Brian Aker
Mass removal of ifdef/endif in favor of pragma once. |
20 |
#pragma once
|
243.1.5
by Jay Pipes
* Pulled the remainder of the log and parse stuff out into |
21 |
|
1
by brian
clean slate |
22 |
/* This file is originally from the mysql distribution. Coded by monty */
|
23 |
||
543
by Monty Taylor
Renamed drizzle_common again. Removed sql_common. (empty) |
24 |
#include <drizzled/common.h> |
2318.8.1
by Olaf van der Spek
Add data_ref.h |
25 |
#include <drizzled/util/data_ref.h> |
2154.2.3
by Brian Aker
Update headers (more removal of session). |
26 |
|
1241.9.51
by Monty Taylor
More mysys stuff out of headers. |
27 |
#include <cassert> |
28 |
#include <cstdlib> |
|
29 |
#include <cstring> |
|
1271.2.4
by Tim Penhey
Add some standard converstion functions. |
30 |
#include <string> |
390.1.6
by Monty Taylor
Oh dear god the changes. The changes. I'd tell you what they are, but I'd just be making stuff up. Suffice it to day it's mostly all around splitting files in libdrizzle into different files and removing interdepends. And whatever else I happened to see... |
31 |
|
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
32 |
#include <drizzled/visibility.h> |
2462.1.2
by Brian Aker
Remove common_fwd.h from visibility.h |
33 |
#include <drizzled/common_fwd.h> |
2119.4.1
by Monty Taylor
Turns on -fvisibility=hidden by default. Symbols intended to be used by |
34 |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
35 |
#ifndef NOT_FIXED_DEC
|
36 |
#define NOT_FIXED_DEC (uint8_t)31
|
|
37 |
#endif
|
|
38 |
||
2252.1.17
by Olaf van der Spek
Common fwd |
39 |
namespace drizzled { |
584.1.13
by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes. |
40 |
|
2119.4.3
by Monty Taylor
We want to add visibility markers into the headers... not take them away |
41 |
extern DRIZZLED_API String my_empty_string; |
1241.9.12
by Monty Taylor
Trims more out of server_includes.h. |
42 |
extern const String my_null_string; |
43 |
||
2254
by Brian Aker
Shift CHARSET_INFO to charset_info_st |
44 |
int sortcmp(const String *a,const String *b, const charset_info_st * const cs); |
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
45 |
int stringcmp(const String *a,const String *b); |
1816.3.1
by Brian Aker
Convert sql_string to use size_t (this should clean up ICC warnings). |
46 |
String *copy_if_not_alloced(String *a,String *b,size_t arg_length); |
2254
by Brian Aker
Shift CHARSET_INFO to charset_info_st |
47 |
size_t well_formed_copy_nchars(const charset_info_st * const to_cs, |
1816.3.1
by Brian Aker
Convert sql_string to use size_t (this should clean up ICC warnings). |
48 |
char *to, size_t to_length, |
2254
by Brian Aker
Shift CHARSET_INFO to charset_info_st |
49 |
const charset_info_st * const from_cs, |
1816.3.1
by Brian Aker
Convert sql_string to use size_t (this should clean up ICC warnings). |
50 |
const char *from, size_t from_length, |
51 |
size_t nchars, |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
52 |
const char **well_formed_error_pos, |
53 |
const char **cannot_convert_error_pos, |
|
54 |
const char **from_end_pos); |
|
55 |
||
1
by brian
clean slate |
56 |
|
2119.4.1
by Monty Taylor
Turns on -fvisibility=hidden by default. Symbols intended to be used by |
57 |
class DRIZZLED_API String |
1
by brian
clean slate |
58 |
{
|
511.2.4
by Monty Taylor
Fixed warnings before we got to sql_yacc. |
59 |
char *Ptr; |
1816.3.1
by Brian Aker
Convert sql_string to use size_t (this should clean up ICC warnings). |
60 |
size_t str_length,Alloced_length; |
1
by brian
clean slate |
61 |
bool alloced; |
2254
by Brian Aker
Shift CHARSET_INFO to charset_info_st |
62 |
const charset_info_st *str_charset; |
794
by Brian Aker
Refactor append_identifier and remove dead OPTION_QUOTE_SHOW_CREATE option |
63 |
|
1
by brian
clean slate |
64 |
public: |
1241.16.2
by Monty Taylor
Cleaned effc++ warnings from sql_string. |
65 |
String(); |
1816.3.1
by Brian Aker
Convert sql_string to use size_t (this should clean up ICC warnings). |
66 |
String(size_t length_arg); |
2440.2.1
by Olaf van der Spek
Use str_ref |
67 |
String(const char*, const charset_info_st*); |
68 |
String(const char*, size_t, const charset_info_st*); |
|
69 |
String(char *str, size_t len, const charset_info_st*); |
|
70 |
String(str_ref, const charset_info_st*); |
|
71 |
String(const String&); |
|
1241.16.2
by Monty Taylor
Cleaned effc++ warnings from sql_string. |
72 |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
73 |
static void *operator new(size_t size, memory::Root *mem_root); |
1241.16.2
by Monty Taylor
Cleaned effc++ warnings from sql_string. |
74 |
static void operator delete(void *, size_t) |
75 |
{ } |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
76 |
static void operator delete(void *, memory::Root *) |
1241.16.2
by Monty Taylor
Cleaned effc++ warnings from sql_string. |
77 |
{ } |
1022.2.29
by Monty Taylor
Fixed some no-inline warnings. |
78 |
~String(); |
1
by brian
clean slate |
79 |
|
2254
by Brian Aker
Shift CHARSET_INFO to charset_info_st |
80 |
inline void set_charset(const charset_info_st * const charset_arg) |
1
by brian
clean slate |
81 |
{ str_charset= charset_arg; } |
2254
by Brian Aker
Shift CHARSET_INFO to charset_info_st |
82 |
inline const charset_info_st *charset() const { return str_charset; } |
1816.3.1
by Brian Aker
Convert sql_string to use size_t (this should clean up ICC warnings). |
83 |
inline size_t length() const { return str_length;} |
84 |
inline size_t alloced_length() const { return Alloced_length;} |
|
85 |
inline char& operator [] (size_t i) const { return Ptr[i]; } |
|
2318.7.11
by Olaf van der Spek
Use String::c_str() instead of c_ptr_safe() |
86 |
inline void length(size_t len) { str_length=len; } |
87 |
inline bool empty() const { return str_length == 0; } |
|
88 |
inline void mark_as_const() { Alloced_length= 0; } |
|
212.6.6
by Mats Kindahl
Removing redundant use of casts in drizzled/ for memcmp(), memcpy(), memset(), and memmove(). |
89 |
inline char *ptr() { return Ptr; } |
1
by brian
clean slate |
90 |
inline const char *ptr() const { return Ptr; } |
91 |
inline char *c_ptr() |
|
92 |
{
|
|
1022.5.1
by nlw
Fix buffer overrun in string::c_ptr, now handles all cases properly |
93 |
if (str_length == Alloced_length) |
2318.7.11
by Olaf van der Spek
Use String::c_str() instead of c_ptr_safe() |
94 |
realloc(str_length); |
1022.5.1
by nlw
Fix buffer overrun in string::c_ptr, now handles all cases properly |
95 |
else
|
96 |
Ptr[str_length]= 0; |
|
1241.3.4
by Trond Norbye
Cleanup: use C++ style casting, init-list and virtual destructors |
97 |
|
1
by brian
clean slate |
98 |
return Ptr; |
99 |
}
|
|
2318.7.12
by Olaf van der Spek
Remove String::c_ptr_quick() |
100 |
inline const char* begin() const |
101 |
{
|
|
102 |
return Ptr; |
|
103 |
}
|
|
104 |
inline const char* end() const |
|
105 |
{
|
|
106 |
return begin() + size(); |
|
107 |
}
|
|
108 |
inline const char* data() const |
|
109 |
{
|
|
110 |
return Ptr; |
|
111 |
}
|
|
112 |
inline size_t size() const |
|
113 |
{
|
|
114 |
return length(); |
|
115 |
}
|
|
116 |
inline const char* c_str() |
|
2318.7.11
by Olaf van der Spek
Use String::c_str() instead of c_ptr_safe() |
117 |
{
|
118 |
if (Ptr && str_length < Alloced_length) |
|
119 |
Ptr[str_length]=0; |
|
120 |
else
|
|
121 |
realloc(str_length); |
|
1273.13.38
by Brian Aker
Add in new show work. |
122 |
return Ptr; |
123 |
}
|
|
1816.3.1
by Brian Aker
Convert sql_string to use size_t (this should clean up ICC warnings). |
124 |
void append_identifier(const char *name, size_t length); |
2318.8.1
by Olaf van der Spek
Add data_ref.h |
125 |
void append_identifier(str_ref); |
1
by brian
clean slate |
126 |
|
1816.3.1
by Brian Aker
Convert sql_string to use size_t (this should clean up ICC warnings). |
127 |
void set(String &str,size_t offset,size_t arg_length) |
1
by brian
clean slate |
128 |
{
|
51.1.75
by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols |
129 |
assert(&str != this); |
1
by brian
clean slate |
130 |
free(); |
1241.3.4
by Trond Norbye
Cleanup: use C++ style casting, init-list and virtual destructors |
131 |
Ptr= str.ptr()+offset; str_length=arg_length; alloced=0; |
1
by brian
clean slate |
132 |
if (str.Alloced_length) |
133 |
Alloced_length=str.Alloced_length-offset; |
|
134 |
else
|
|
135 |
Alloced_length=0; |
|
136 |
str_charset=str.str_charset; |
|
137 |
}
|
|
2254
by Brian Aker
Shift CHARSET_INFO to charset_info_st |
138 |
inline void set(char *str,size_t arg_length, const charset_info_st * const cs) |
1
by brian
clean slate |
139 |
{
|
140 |
free(); |
|
1241.3.4
by Trond Norbye
Cleanup: use C++ style casting, init-list and virtual destructors |
141 |
Ptr= str; str_length=Alloced_length=arg_length ; alloced=0; |
1
by brian
clean slate |
142 |
str_charset=cs; |
143 |
}
|
|
2363.1.4
by Brian Aker
Fixes bug where true/false would not be interpreted correctly/displayed correctly. |
144 |
|
2254
by Brian Aker
Shift CHARSET_INFO to charset_info_st |
145 |
inline void set(const char *str,size_t arg_length, const charset_info_st * const cs) |
1
by brian
clean slate |
146 |
{
|
147 |
free(); |
|
1241.3.4
by Trond Norbye
Cleanup: use C++ style casting, init-list and virtual destructors |
148 |
Ptr= const_cast<char*>(str); |
149 |
str_length=arg_length; Alloced_length=0 ; alloced=0; |
|
1
by brian
clean slate |
150 |
str_charset=cs; |
151 |
}
|
|
2281.6.1
by Olaf van der Spek
Return void |
152 |
void set_ascii(const char *str, size_t arg_length); |
2363.1.4
by Brian Aker
Fixes bug where true/false would not be interpreted correctly/displayed correctly. |
153 |
|
2254
by Brian Aker
Shift CHARSET_INFO to charset_info_st |
154 |
inline void set_quick(char *str,size_t arg_length, const charset_info_st * const cs) |
1
by brian
clean slate |
155 |
{
|
156 |
if (!alloced) |
|
157 |
{
|
|
1241.3.4
by Trond Norbye
Cleanup: use C++ style casting, init-list and virtual destructors |
158 |
Ptr= str; str_length= Alloced_length= arg_length; |
1
by brian
clean slate |
159 |
}
|
1241.3.4
by Trond Norbye
Cleanup: use C++ style casting, init-list and virtual destructors |
160 |
str_charset= cs; |
1
by brian
clean slate |
161 |
}
|
2363.1.4
by Brian Aker
Fixes bug where true/false would not be interpreted correctly/displayed correctly. |
162 |
|
2297.1.5
by Olaf van der Spek
Return void |
163 |
void set_int(int64_t num, bool unsigned_flag, const charset_info_st * const cs); |
164 |
void set(int64_t num, const charset_info_st * const cs) |
|
165 |
{ set_int(num, false, cs); } |
|
166 |
void set(uint64_t num, const charset_info_st * const cs) |
|
167 |
{ set_int(static_cast<int64_t>(num), true, cs); } |
|
2281.6.1
by Olaf van der Spek
Return void |
168 |
void set_real(double num,size_t decimals, const charset_info_st* cs); |
1
by brian
clean slate |
169 |
|
170 |
/*
|
|
171 |
PMG 2004.11.12
|
|
172 |
This is a method that works the same as perl's "chop". It simply
|
|
173 |
drops the last character of a string. This is useful in the case
|
|
174 |
of the federated storage handler where I'm building a unknown
|
|
175 |
number, list of values and fields to be used in a sql insert
|
|
176 |
statement to be run on the remote server, and have a comma after each.
|
|
177 |
When the list is complete, I "chop" off the trailing comma
|
|
178 |
||
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
179 |
ex.
|
180 |
String stringobj;
|
|
1
by brian
clean slate |
181 |
stringobj.append("VALUES ('foo', 'fi', 'fo',");
|
182 |
stringobj.chop();
|
|
183 |
stringobj.append(")");
|
|
184 |
||
185 |
In this case, the value of string was:
|
|
186 |
||
187 |
VALUES ('foo', 'fi', 'fo',
|
|
188 |
VALUES ('foo', 'fi', 'fo'
|
|
189 |
VALUES ('foo', 'fi', 'fo')
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
190 |
|
1
by brian
clean slate |
191 |
*/
|
192 |
inline void chop() |
|
193 |
{
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
194 |
Ptr[str_length--]= '\0'; |
1
by brian
clean slate |
195 |
}
|
196 |
||
197 |
inline void free() |
|
198 |
{
|
|
199 |
if (alloced) |
|
200 |
{
|
|
201 |
alloced=0; |
|
202 |
Alloced_length=0; |
|
477
by Monty Taylor
Removed my_free(). It turns out that it had been def'd to ignore the flags passed to it in the second arg anyway. Gotta love that. |
203 |
::free(Ptr); |
1
by brian
clean slate |
204 |
Ptr=0; |
205 |
str_length=0; /* Safety */ |
|
206 |
}
|
|
207 |
}
|
|
2275.2.12
by Olaf van der Spek
Return void |
208 |
inline void alloc(size_t arg_length) |
1
by brian
clean slate |
209 |
{
|
2275.2.12
by Olaf van der Spek
Return void |
210 |
if (arg_length >= Alloced_length) |
211 |
real_alloc(arg_length); |
|
1
by brian
clean slate |
212 |
}
|
2275.2.12
by Olaf van der Spek
Return void |
213 |
void real_alloc(size_t arg_length); // Empties old string |
2281.6.3
by Olaf van der Spek
Return void |
214 |
void realloc(size_t arg_length); |
1816.3.1
by Brian Aker
Convert sql_string to use size_t (this should clean up ICC warnings). |
215 |
inline void shrink(size_t arg_length) // Shrink buffer |
1
by brian
clean slate |
216 |
{
|
217 |
if (arg_length < Alloced_length) |
|
218 |
{
|
|
219 |
char *new_ptr; |
|
1241.3.4
by Trond Norbye
Cleanup: use C++ style casting, init-list and virtual destructors |
220 |
if (!(new_ptr= reinterpret_cast<char*>(::realloc(Ptr,arg_length)))) |
1
by brian
clean slate |
221 |
{
|
2023.2.7
by Brian Aker
Create an Bool primtive type for item. |
222 |
Alloced_length = 0; |
223 |
real_alloc(arg_length); |
|
1
by brian
clean slate |
224 |
}
|
225 |
else
|
|
226 |
{
|
|
2023.2.7
by Brian Aker
Create an Bool primtive type for item. |
227 |
Ptr=new_ptr; |
228 |
Alloced_length=arg_length; |
|
1
by brian
clean slate |
229 |
}
|
230 |
}
|
|
231 |
}
|
|
2281.6.3
by Olaf van der Spek
Return void |
232 |
bool is_alloced() { return alloced; } const |
1
by brian
clean slate |
233 |
inline String& operator = (const String &s) |
234 |
{
|
|
235 |
if (&s != this) |
|
236 |
{
|
|
237 |
/*
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
238 |
It is forbidden to do assignments like
|
1
by brian
clean slate |
239 |
some_string = substring_of_that_string
|
240 |
*/
|
|
51.1.75
by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols |
241 |
assert(!s.uses_buffer_owned_by(this)); |
1
by brian
clean slate |
242 |
free(); |
243 |
Ptr=s.Ptr ; str_length=s.str_length ; Alloced_length=s.Alloced_length; |
|
244 |
alloced=0; |
|
245 |
}
|
|
246 |
return *this; |
|
247 |
}
|
|
248 |
||
2281.4.12
by Olaf van der Spek
Return void |
249 |
void copy(); // Alloc string if not alloced |
2281.4.11
by Olaf van der Spek
Merge ~olafvdspek/drizzle/bool |
250 |
void copy(const String&); // Allocate new string |
251 |
void copy(const std::string&, const charset_info_st*); // Allocate new string |
|
252 |
void copy(const char*, size_t, const charset_info_st*); // Allocate new string |
|
2318.7.8
by Olaf van der Spek
Remove unused param |
253 |
static bool needs_conversion(size_t arg_length, const charset_info_st* cs_from, const charset_info_st* cs_to); |
2281.4.16
by Olaf van der Spek
Return void |
254 |
void set_or_copy_aligned(const char *s, size_t arg_length, const charset_info_st*); |
2281.6.2
by Olaf van der Spek
Return void |
255 |
void copy(const char*s,size_t arg_length, const charset_info_st& csto); |
2385.1.4
by Olaf van der Spek
Refactor setTableName |
256 |
void append(const char*); |
257 |
void append(const char*, size_t); |
|
2385.1.3
by Olaf van der Spek
Refactor getTableName |
258 |
void append(str_ref); |
2318.7.5
by Olaf van der Spek
Remove unused param |
259 |
void append_with_prefill(const char *s, size_t arg_length, size_t full_length, char fill_char); |
1816.3.1
by Brian Aker
Convert sql_string to use size_t (this should clean up ICC warnings). |
260 |
int strstr(const String &search,size_t offset=0); // Returns offset to substring or -1 |
261 |
int strrstr(const String &search,size_t offset=0); // Returns offset to substring or -1 |
|
2281.4.13
by Olaf van der Spek
Return void |
262 |
void replace(size_t offset,size_t arg_length,const char *to,size_t length); |
263 |
void replace(size_t offset,size_t arg_length,const String &to); |
|
264 |
||
265 |
inline void append(char chr) |
|
1
by brian
clean slate |
266 |
{
|
267 |
if (str_length < Alloced_length) |
|
268 |
{
|
|
269 |
Ptr[str_length++]=chr; |
|
270 |
}
|
|
271 |
else
|
|
272 |
{
|
|
2281.4.13
by Olaf van der Spek
Return void |
273 |
realloc(str_length+1); |
1
by brian
clean slate |
274 |
Ptr[str_length++]=chr; |
275 |
}
|
|
276 |
}
|
|
2254
by Brian Aker
Shift CHARSET_INFO to charset_info_st |
277 |
friend int sortcmp(const String *a,const String *b, const charset_info_st * const cs); |
1
by brian
clean slate |
278 |
friend int stringcmp(const String *a,const String *b); |
1816.3.1
by Brian Aker
Convert sql_string to use size_t (this should clean up ICC warnings). |
279 |
friend String *copy_if_not_alloced(String *a,String *b,size_t arg_length); |
2385.2.6
by Olaf van der Spek
Refactor |
280 |
size_t numchars() const; |
281 |
int charpos(int i, size_t offset= 0) const; |
|
1
by brian
clean slate |
282 |
|
2281.6.3
by Olaf van der Spek
Return void |
283 |
void reserve(size_t space_needed) |
1
by brian
clean slate |
284 |
{
|
2281.6.3
by Olaf van der Spek
Return void |
285 |
realloc(str_length + space_needed); |
1
by brian
clean slate |
286 |
}
|
2281.6.3
by Olaf van der Spek
Return void |
287 |
void reserve(size_t space_needed, size_t grow_by); |
1
by brian
clean slate |
288 |
|
2281.4.16
by Olaf van der Spek
Return void |
289 |
inline void append(const char *s, size_t arg_length, size_t step_alloc) |
1
by brian
clean slate |
290 |
{
|
1816.3.1
by Brian Aker
Convert sql_string to use size_t (this should clean up ICC warnings). |
291 |
size_t new_length= arg_length + str_length; |
2281.4.16
by Olaf van der Spek
Return void |
292 |
if (new_length > Alloced_length) |
293 |
realloc(new_length + step_alloc); |
|
1
by brian
clean slate |
294 |
memcpy(Ptr+str_length, s, arg_length); |
295 |
str_length+= arg_length; |
|
296 |
}
|
|
2281.4.16
by Olaf van der Spek
Return void |
297 |
|
2318.7.8
by Olaf van der Spek
Remove unused param |
298 |
void print(String&) const; |
1
by brian
clean slate |
299 |
|
300 |
/* Swap two string objects. Efficient way to exchange data without memcpy. */
|
|
301 |
void swap(String &s); |
|
302 |
||
303 |
inline bool uses_buffer_owned_by(const String *s) const |
|
304 |
{
|
|
305 |
return (s->alloced && Ptr >= s->Ptr && Ptr < s->Ptr + s->str_length); |
|
306 |
}
|
|
307 |
};
|
|
308 |
||
2318.7.6
by Olaf van der Spek
Remove unused declarations |
309 |
bool check_if_only_end_space(const charset_info_st* const, char *str, char *end); |
1
by brian
clean slate |
310 |
|
2318.7.6
by Olaf van der Spek
Remove unused declarations |
311 |
std::ostream& operator<<(std::ostream&, const String&); |
2023.2.1
by Brian Aker
Merge in BOOL type. |
312 |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
313 |
} /* namespace drizzled */ |
314 |
||
315 |
bool operator==(const drizzled::String &s1, const drizzled::String &s2); |
|
316 |
bool operator!=(const drizzled::String &s1, const drizzled::String &s2); |