~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_string.h

Merge Trond

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
  const CHARSET_INFO *str_charset;
63
63
 
64
64
public:
65
 
  String()
66
 
  {
67
 
    Ptr=0; str_length=Alloced_length=0; alloced=0;
68
 
    str_charset= &my_charset_bin;
69
 
  }
70
 
  String(uint32_t length_arg)
71
 
  {
72
 
    alloced=0; Alloced_length=0; (void) real_alloc(length_arg);
73
 
    str_charset= &my_charset_bin;
74
 
  }
75
 
  String(const char *str, const CHARSET_INFO * const cs)
76
 
  {
77
 
    Ptr=(char*) str; str_length=(uint32_t) strlen(str); Alloced_length=0; alloced=0;
78
 
    str_charset=cs;
79
 
  }
80
 
  String(const char *str,uint32_t len, const CHARSET_INFO * const cs)
81
 
  {
82
 
    Ptr=(char*) str; str_length=len; Alloced_length=0; alloced=0;
83
 
    str_charset=cs;
84
 
  }
85
 
  String(char *str,uint32_t len, const CHARSET_INFO * const cs)
86
 
  {
87
 
    Ptr=(char*) str; Alloced_length=str_length=len; alloced=0;
88
 
    str_charset=cs;
89
 
  }
90
 
  String(const String &str)
91
 
  {
92
 
    Ptr=str.Ptr ; str_length=str.str_length ;
93
 
    Alloced_length=str.Alloced_length; alloced=0;
94
 
    str_charset=str.str_charset;
95
 
  }
 
65
  String() :
 
66
    Ptr(0),
 
67
    str_length(0),
 
68
    Alloced_length(0),
 
69
    alloced(0),
 
70
    str_charset(&my_charset_bin) { }
 
71
 
 
72
  String(uint32_t length_arg) :
 
73
    Ptr(0),
 
74
    str_length(0),
 
75
    Alloced_length(0),
 
76
    alloced(0),
 
77
    str_charset(&my_charset_bin)
 
78
  {
 
79
    (void) real_alloc(length_arg);
 
80
  }
 
81
 
 
82
  String(const char *str, const CHARSET_INFO * const cs) :
 
83
    Ptr(const_cast<char*>(str)),
 
84
    str_length(static_cast<uint32_t>(strlen(str))),
 
85
    Alloced_length(0),
 
86
    alloced(0),
 
87
    str_charset(cs) { }
 
88
 
 
89
  String(const char *str, uint32_t len, const CHARSET_INFO * const cs) :
 
90
    Ptr(const_cast<char*>(str)),
 
91
    str_length(len),
 
92
    Alloced_length(0),
 
93
    alloced(0),
 
94
    str_charset(cs) { }
 
95
 
 
96
  String(char *str,uint32_t len, const CHARSET_INFO * const cs) :
 
97
    Ptr(str),
 
98
    str_length(len),
 
99
    Alloced_length(len),
 
100
    alloced(0),
 
101
    str_charset(cs) { }
 
102
 
 
103
  String(const String &str) :
 
104
    Ptr(str.Ptr),
 
105
    str_length(str.str_length),
 
106
    Alloced_length(str.Alloced_length),
 
107
    alloced(0),
 
108
    str_charset(str.str_charset) { }
 
109
 
96
110
  static void *operator new(size_t size, MEM_ROOT *mem_root)
97
 
  { return (void*) alloc_root(mem_root, (uint32_t) size); } 
 
111
  { return alloc_root(mem_root, static_cast<uint32_t>(size)); }
98
112
  static void operator delete(void *, size_t)
99
113
  { TRASH(ptr_arg, size); }
100
114
  static void operator delete(void *, MEM_ROOT *)
118
132
      (void) realloc(str_length);
119
133
    else
120
134
      Ptr[str_length]= 0;
121
 
    
 
135
 
122
136
    return Ptr;
123
137
  }
124
138
  inline char *c_ptr_quick()
141
155
  {
142
156
    assert(&str != this);
143
157
    free();
144
 
    Ptr=(char*) str.ptr()+offset; str_length=arg_length; alloced=0;
 
158
    Ptr= str.ptr()+offset; str_length=arg_length; alloced=0;
145
159
    if (str.Alloced_length)
146
160
      Alloced_length=str.Alloced_length-offset;
147
161
    else
151
165
  inline void set(char *str,uint32_t arg_length, const CHARSET_INFO * const cs)
152
166
  {
153
167
    free();
154
 
    Ptr=(char*) str; str_length=Alloced_length=arg_length ; alloced=0;
 
168
    Ptr= str; str_length=Alloced_length=arg_length ; alloced=0;
155
169
    str_charset=cs;
156
170
  }
157
171
  inline void set(const char *str,uint32_t arg_length, const CHARSET_INFO * const cs)
158
172
  {
159
173
    free();
160
 
    Ptr=(char*) str; str_length=arg_length; Alloced_length=0 ; alloced=0;
 
174
    Ptr= const_cast<char*>(str);
 
175
    str_length=arg_length; Alloced_length=0 ; alloced=0;
161
176
    str_charset=cs;
162
177
  }
163
178
  bool set_ascii(const char *str, uint32_t arg_length);
165
180
  {
166
181
    if (!alloced)
167
182
    {
168
 
      Ptr=(char*) str; str_length=Alloced_length=arg_length;
 
183
      Ptr= str; str_length= Alloced_length= arg_length;
169
184
    }
170
 
    str_charset=cs;
 
185
    str_charset= cs;
171
186
  }
172
187
  bool set_int(int64_t num, bool unsigned_flag, const CHARSET_INFO * const cs);
173
188
  bool set(int64_t num, const CHARSET_INFO * const cs)
174
189
  { return set_int(num, false, cs); }
175
190
  bool set(uint64_t num, const CHARSET_INFO * const cs)
176
 
  { return set_int((int64_t)num, true, cs); }
 
191
  { return set_int(static_cast<int64_t>(num), true, cs); }
177
192
  bool set_real(double num,uint32_t decimals, const CHARSET_INFO * const cs);
178
193
 
179
194
  /*
227
242
    if (arg_length < Alloced_length)
228
243
    {
229
244
      char *new_ptr;
230
 
      if (!(new_ptr=(char*) ::realloc(Ptr,arg_length)))
 
245
      if (!(new_ptr= reinterpret_cast<char*>(::realloc(Ptr,arg_length))))
231
246
      {
232
247
        Alloced_length = 0;
233
248
        real_alloc(arg_length);