Merge lp:~billy-earney/drizzle/bug621331 into lp:~drizzle-trunk/drizzle/development

Proposed by Billy Earney
Status: Merged
Approved by: Brian Aker
Approved revision: 1777
Merged at revision: 1814
Proposed branch: lp:~billy-earney/drizzle/bug621331
Merge into: lp:~drizzle-trunk/drizzle/development
Diff against target: 346 lines (+38/-65)
10 files modified
drizzled/field/date.cc (+4/-4)
drizzled/field/datetime.cc (+5/-9)
drizzled/field/enum.cc (+3/-5)
drizzled/field/timestamp.cc (+5/-6)
drizzled/function/time/from_days.cc (+2/-3)
drizzled/function/time/from_unixtime.cc (+2/-4)
drizzled/identifier/table.cc (+1/-1)
drizzled/message/statement_transform.cc (+8/-20)
drizzled/status_helper.cc (+6/-10)
drizzled/util/convert.h (+2/-3)
To merge this branch: bzr merge lp:~billy-earney/drizzle/bug621331
Reviewer Review Type Date Requested Status
Brian Aker Pending
Monty Taylor Pending
Review via email: mp+37465@code.launchpad.net

This proposal supersedes a proposal from 2010-09-21.

Description of the change

modified simple uses of stringstream to use boost::lexical_cast instead.

Lines directly related to stringstream were only commented out. Whomever inspects this modification may want to remove the comments once they are happy with the changes.

To post a comment you must log in.
Revision history for this message
Stewart Smith (stewart) wrote : Posted in a previous version of this proposal
Revision history for this message
Brian Aker (brianaker) wrote : Posted in a previous version of this proposal

My concern with this patch is that we won't get consistent formatting (especially with Decimal). I believe LinuxJedi and Monty should chime in here.

review: Needs Information
Revision history for this message
Billy Earney (billy-earney) wrote : Posted in a previous version of this proposal

Brian,

Yes, that was a concern of mine as well. Most of the stringstreams I didn't replace modified the precision with setprecision. I could create a wrapper function with an argument for the precision. We could set the default to be 0. For decimals we would set it to some other value. Or we could create a wrapper function that deals only with decimals and leave the other modifications as is

Let me know your thoughts.

Billy

Revision history for this message
Monty Taylor (mordred) wrote : Posted in a previous version of this proposal

Yes. Sorry - I should have been more clear. If there is actually real value coming from the use of stringstream (such as using precision) then we should keep stringstream in those cases.

However, where it's being used purely to cast the value one way or the other, boost::lexical_cast I believe reads much cleaner. (for instance, first change in drizzled/field/date.cc should be reverted, second change is good)

If you could put the ones with precision calls back to stringstream, and then delete the comments from the other ones, I think we'll be good to go to merge this in!

review: Needs Fixing
Revision history for this message
Monty Taylor (mordred) wrote : Posted in a previous version of this proposal

PS. I put this back to "work-in-progress" - set the status to "needs review" once you're ready for it to be looked at again. Thanks for the work!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'drizzled/field/date.cc'
2--- drizzled/field/date.cc 2010-09-22 17:46:49 +0000
3+++ drizzled/field/date.cc 2010-10-04 13:27:46 +0000
4@@ -19,6 +19,8 @@
5 */
6
7 #include "config.h"
8+#include <boost/lexical_cast.hpp>
9+
10 #include "drizzled/field/date.h"
11 #include "drizzled/error.h"
12 #include "drizzled/table.h"
13@@ -108,10 +110,8 @@
14 DateTime temporal;
15 if (! temporal.from_int64_t(from))
16 {
17- /* Convert the integer to a string using stringstream */
18- std::stringstream ss;
19- std::string tmp;
20- ss << from; ss >> tmp;
21+ /* Convert the integer to a string using boost::lexical_cast */
22+ std::string tmp(boost::lexical_cast<std::string>(from));
23
24 my_error(ER_INVALID_DATETIME_VALUE, MYF(ME_FATALERROR), tmp.c_str());
25 return 2;
26
27=== modified file 'drizzled/field/datetime.cc'
28--- drizzled/field/datetime.cc 2010-09-22 17:46:49 +0000
29+++ drizzled/field/datetime.cc 2010-10-04 13:27:46 +0000
30@@ -19,6 +19,7 @@
31 */
32
33 #include "config.h"
34+#include <boost/lexical_cast.hpp>
35 #include "drizzled/field/datetime.h"
36 #include "drizzled/error.h"
37 #include "drizzled/table.h"
38@@ -75,11 +76,8 @@
39 ASSERT_COLUMN_MARKED_FOR_WRITE;
40 if (from < 0.0 || from > 99991231235959.0)
41 {
42- /* Convert the double to a string using stringstream */
43- std::stringstream ss;
44- std::string tmp;
45- ss.precision(18); /* 18 places should be fine for error display of double input. */
46- ss << from; ss >> tmp;
47+ /* Convert the double to a string using boost::lexical_cast */
48+ std::string tmp(boost::lexical_cast<std::string>(from));
49
50 my_error(ER_INVALID_DATETIME_VALUE, MYF(ME_FATALERROR), tmp.c_str());
51 return 2;
52@@ -97,10 +95,8 @@
53 DateTime temporal;
54 if (! temporal.from_int64_t(from))
55 {
56- /* Convert the integer to a string using stringstream */
57- std::stringstream ss;
58- std::string tmp;
59- ss << from; ss >> tmp;
60+ /* Convert the integer to a string using boost::lexical_cast */
61+ std::string tmp(boost::lexical_cast<std::string>(from));
62
63 my_error(ER_INVALID_DATETIME_VALUE, MYF(ME_FATALERROR), tmp.c_str());
64 return 2;
65
66=== modified file 'drizzled/field/enum.cc'
67--- drizzled/field/enum.cc 2010-09-22 22:29:55 +0000
68+++ drizzled/field/enum.cc 2010-10-04 13:27:46 +0000
69@@ -18,8 +18,8 @@
70 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
71 */
72
73-
74 #include "config.h"
75+#include <boost/lexical_cast.hpp>
76 #include "drizzled/field/enum.h"
77 #include "drizzled/error.h"
78 #include "drizzled/table.h"
79@@ -110,10 +110,8 @@
80
81 if (from <= 0 || (uint64_t) from > typelib->count)
82 {
83- /* Convert the integer to a string using stringstream */
84- std::stringstream ss;
85- std::string tmp;
86- ss << from; ss >> tmp;
87+ /* Convert the integer to a string using boost::lexical_cast */
88+ std::string tmp(boost::lexical_cast<std::string>(from));
89
90 my_error(ER_INVALID_ENUM_VALUE, MYF(ME_FATALERROR), tmp.c_str());
91 return 1;
92
93=== modified file 'drizzled/field/timestamp.cc'
94--- drizzled/field/timestamp.cc 2010-09-22 15:41:38 +0000
95+++ drizzled/field/timestamp.cc 2010-10-04 13:27:46 +0000
96@@ -18,8 +18,8 @@
97 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
98 */
99
100-
101 #include "config.h"
102+#include <boost/lexical_cast.hpp>
103 #include <drizzled/field/timestamp.h>
104 #include <drizzled/error.h>
105 #include <drizzled/tztime.h>
106@@ -187,7 +187,8 @@
107 std::stringstream ss;
108 std::string tmp;
109 ss.precision(18); /* 18 places should be fine for error display of double input. */
110- ss << from; ss >> tmp;
111+ ss << from;
112+ ss >> tmp;
113
114 my_error(ER_INVALID_UNIX_TIMESTAMP_VALUE, MYF(ME_FATALERROR), tmp.c_str());
115 return 2;
116@@ -206,10 +207,8 @@
117 Timestamp temporal;
118 if (! temporal.from_int64_t(from))
119 {
120- /* Convert the integer to a string using stringstream */
121- std::stringstream ss;
122- std::string tmp;
123- ss << from; ss >> tmp;
124+ /* Convert the integer to a string using boost::lexical_cast */
125+ std::string tmp(boost::lexical_cast<std::string>(from));
126
127 my_error(ER_INVALID_UNIX_TIMESTAMP_VALUE, MYF(ME_FATALERROR), tmp.c_str());
128 return 2;
129
130=== modified file 'drizzled/function/time/from_days.cc'
131--- drizzled/function/time/from_days.cc 2010-02-04 08:14:46 +0000
132+++ drizzled/function/time/from_days.cc 2010-10-04 13:27:46 +0000
133@@ -18,6 +18,7 @@
134 */
135
136 #include "config.h"
137+#include <boost/lexical_cast.hpp>
138 #include "drizzled/function/time/from_days.h"
139 #include "drizzled/error.h"
140 #include "drizzled/temporal.h"
141@@ -54,9 +55,7 @@
142 if (! to.from_julian_day_number(int_value))
143 {
144 /* Bad input, throw an error */
145- std::stringstream ss;
146- std::string tmp;
147- ss << int_value; ss >> tmp;
148+ std::string tmp(boost::lexical_cast<std::string>(int_value));
149
150 my_error(ER_ARGUMENT_OUT_OF_RANGE, MYF(ME_FATALERROR), tmp.c_str(), func_name());
151 return false;
152
153=== modified file 'drizzled/function/time/from_unixtime.cc'
154--- drizzled/function/time/from_unixtime.cc 2010-02-04 08:14:46 +0000
155+++ drizzled/function/time/from_unixtime.cc 2010-10-04 13:27:46 +0000
156@@ -18,7 +18,7 @@
157 */
158
159 #include "config.h"
160-
161+#include <boost/lexical_cast.hpp>
162 #include "drizzled/function/time/from_unixtime.h"
163 #include "drizzled/session.h"
164 #include "drizzled/temporal.h"
165@@ -85,9 +85,7 @@
166 if (! temporal.from_time_t((time_t) tmp))
167 {
168 null_value= true;
169- std::stringstream ss;
170- std::string tmp_string;
171- ss << tmp; ss >> tmp_string;
172+ std::string tmp_string(boost::lexical_cast<std::string>(tmp));
173 my_error(ER_INVALID_UNIX_TIMESTAMP_VALUE, MYF(0), tmp_string.c_str());
174 return 0;
175 }
176
177=== modified file 'drizzled/identifier/table.cc'
178--- drizzled/identifier/table.cc 2010-09-23 01:53:13 +0000
179+++ drizzled/identifier/table.cc 2010-10-04 13:27:46 +0000
180@@ -21,7 +21,7 @@
181 #include "config.h"
182
183 #include <assert.h>
184-
185+#include <boost/lexical_cast.hpp>
186 #include "drizzled/identifier.h"
187 #include "drizzled/session.h"
188 #include "drizzled/internal/my_sys.h"
189
190=== modified file 'drizzled/message/statement_transform.cc'
191--- drizzled/message/statement_transform.cc 2010-09-22 21:51:30 +0000
192+++ drizzled/message/statement_transform.cc 2010-10-04 13:27:46 +0000
193@@ -31,6 +31,7 @@
194
195 #include "config.h"
196
197+#include <boost/lexical_cast.hpp>
198 #include "drizzled/message/statement_transform.h"
199 #include "drizzled/message/transaction.pb.h"
200 #include "drizzled/message/table.pb.h"
201@@ -1036,8 +1037,6 @@
202 if (sql_variant == ANSI)
203 return NONE; /* ANSI does not support table options... */
204
205- stringstream ss;
206-
207 if (options.has_comment())
208 {
209 destination.append(" COMMENT=", 9);
210@@ -1066,35 +1065,27 @@
211
212 if (options.has_max_rows())
213 {
214- ss << options.max_rows();
215 destination.append("\nMAX_ROWS = ", 12);
216- destination.append(ss.str());
217- ss.clear();
218+ destination.append(boost::lexical_cast<string>(options.max_rows()));
219 }
220
221 if (options.has_min_rows())
222 {
223- ss << options.min_rows();
224 destination.append("\nMIN_ROWS = ", 12);
225- destination.append(ss.str());
226- ss.clear();
227+ destination.append(boost::lexical_cast<string>(options.min_rows()));
228 }
229
230 if (options.has_user_set_auto_increment_value()
231 && options.has_auto_increment_value())
232 {
233- ss << options.auto_increment_value();
234 destination.append(" AUTO_INCREMENT=", 16);
235- destination.append(ss.str());
236- ss.clear();
237+ destination.append(boost::lexical_cast<string>(options.auto_increment_value()));
238 }
239
240 if (options.has_avg_row_length())
241 {
242- ss << options.avg_row_length();
243 destination.append("\nAVG_ROW_LENGTH = ", 18);
244- destination.append(ss.str());
245- ss.clear();
246+ destination.append(boost::lexical_cast<string>(options.avg_row_length()));
247 }
248
249 if (options.has_checksum() &&
250@@ -1160,10 +1151,8 @@
251 {
252 if (part.compare_length() != field.string_options().length())
253 {
254- stringstream ss;
255 destination.push_back('(');
256- ss << part.compare_length();
257- destination.append(ss.str());
258+ destination.append(boost::lexical_cast<string>(part.compare_length()));
259 destination.push_back(')');
260 }
261 }
262@@ -1325,9 +1314,8 @@
263 else
264 destination.append(" VARCHAR(", 9);
265
266- stringstream ss;
267- ss << field.string_options().length() << ")";
268- destination.append(ss.str());
269+ destination.append(boost::lexical_cast<string>(field.string_options().length()));
270+ destination.append(")");
271 }
272 break;
273 case Table::Field::BLOB:
274
275=== modified file 'drizzled/status_helper.cc'
276--- drizzled/status_helper.cc 2010-08-21 21:31:59 +0000
277+++ drizzled/status_helper.cc 2010-10-04 13:27:46 +0000
278@@ -19,6 +19,7 @@
279 */
280
281 #include "config.h"
282+#include <boost/lexical_cast.hpp>
283 #include "status_helper.h"
284 #include "drizzled/set_var.h"
285 #include "drizzled/drizzled.h"
286@@ -77,23 +78,19 @@
287 value= ((char *) status_var + (ulong) value);
288 /* fall through */
289 case SHOW_LONG:
290- oss << *(long*) value;
291- return_value= oss.str();
292+ return_value=boost::lexical_cast<std::string>(*(long*) value);
293 break;
294 case SHOW_LONGLONG_STATUS:
295 value= ((char *) status_var + (uint64_t) value);
296 /* fall through */
297 case SHOW_LONGLONG:
298- oss << *(int64_t*) value;
299- return_value= oss.str();
300+ return_value=boost::lexical_cast<std::string>(*(int64_t*) value);
301 break;
302 case SHOW_SIZE:
303- oss << *(size_t*) value;
304- return_value= oss.str();
305+ return_value=boost::lexical_cast<std::string>(*(size_t*) value);
306 break;
307 case SHOW_HA_ROWS:
308- oss << (int64_t) *(ha_rows*) value;
309- return_value= oss.str();
310+ return_value=boost::lexical_cast<std::string>((int64_t) *(ha_rows*) value);
311 break;
312 case SHOW_BOOL:
313 case SHOW_MY_BOOL:
314@@ -101,8 +98,7 @@
315 break;
316 case SHOW_INT:
317 case SHOW_INT_NOFLUSH: // the difference lies in refresh_status()
318- oss << (long) *(uint32_t*) value;
319- return_value= oss.str();
320+ return_value=boost::lexical_cast<std::string>((long) *(uint32_t*) value);
321 break;
322 case SHOW_CHAR:
323 {
324
325=== modified file 'drizzled/util/convert.h'
326--- drizzled/util/convert.h 2010-03-18 18:07:58 +0000
327+++ drizzled/util/convert.h 2010-10-04 13:27:46 +0000
328@@ -21,6 +21,7 @@
329 #ifndef DRIZZLED_UTIL_CONVERT_H
330 #define DRIZZLED_UTIL_CONVERT_H
331
332+#include <boost/lexical_cast.hpp>
333 #include <string>
334 #include <iostream>
335 #include <sstream>
336@@ -31,9 +32,7 @@
337 template <class T>
338 std::string to_string(T t)
339 {
340- std::ostringstream o;
341- o << t;
342- return o.str();
343+ return boost::lexical_cast<std::string>(t);
344 }
345
346 template <class T>