|
Last change
on this file was
82,
checked in by rosiere, 18 years ago
|
- support locale (now must "just" translate)
- update all component with new test format
- update all component with usage
- New component : decod queue and prediction_unit
|
-
Property svn:keywords set to
Id
|
|
File size:
763 bytes
|
| Line | |
|---|
| 1 | /* |
|---|
| 2 | * $Id: ToString.cpp 82 2008-05-01 16:48:45Z rosiere $ |
|---|
| 3 | * |
|---|
| 4 | * [ Description ] |
|---|
| 5 | * |
|---|
| 6 | */ |
|---|
| 7 | |
|---|
| 8 | #include "../include/ToString.h" |
|---|
| 9 | |
|---|
| 10 | namespace morpheo { |
|---|
| 11 | |
|---|
| 12 | std::string toString (const char *fmt, ...) |
|---|
| 13 | { |
|---|
| 14 | int size = 128; // initial size |
|---|
| 15 | char *tmp; |
|---|
| 16 | va_list ap; |
|---|
| 17 | while (1) |
|---|
| 18 | { |
|---|
| 19 | // Allocation |
|---|
| 20 | tmp = new char [size]; |
|---|
| 21 | |
|---|
| 22 | va_start(ap, fmt); |
|---|
| 23 | int n = vsnprintf (tmp, size, fmt, ap); |
|---|
| 24 | va_end(ap); |
|---|
| 25 | |
|---|
| 26 | // n : (<= GlibC 2.0.6) number of print caracter, if n == -1, tmp is truncate |
|---|
| 27 | // ( > GlibC 2.1 ) number of caracter |
|---|
| 28 | |
|---|
| 29 | // Test if ok |
|---|
| 30 | if ((n > -1) and (n < size)) |
|---|
| 31 | break; |
|---|
| 32 | |
|---|
| 33 | if (n > -1) |
|---|
| 34 | size = n+1; // ( > GlibC 2.1 ) |
|---|
| 35 | else |
|---|
| 36 | size *= 2; // (<= GlibC 2.0.6) |
|---|
| 37 | |
|---|
| 38 | delete [] tmp; |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | std::string str = toString(tmp); |
|---|
| 42 | delete [] tmp; |
|---|
| 43 | |
|---|
| 44 | return str; |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | }; // end namespace morpheo |
|---|
Note: See
TracBrowser
for help on using the repository browser.