Last change
on this file since 60 was
43,
checked in by rosiere, 17 years ago
|
Modif mineur : ajout d'info de débug
Release non stable
|
File size:
1.4 KB
|
Line | |
---|
1 | #ifndef morpheo_tostring |
---|
2 | #define morpheo_tostring |
---|
3 | |
---|
4 | /* |
---|
5 | * $Id$ |
---|
6 | * |
---|
7 | * [ Description ] |
---|
8 | * |
---|
9 | */ |
---|
10 | |
---|
11 | #include <iosfwd> |
---|
12 | #include <sstream> |
---|
13 | #include <iomanip> |
---|
14 | #include <string> |
---|
15 | #include <limits> |
---|
16 | |
---|
17 | using std::setprecision ; |
---|
18 | using std::ostringstream ; |
---|
19 | using std::boolalpha ; |
---|
20 | |
---|
21 | namespace morpheo { |
---|
22 | |
---|
23 | template<typename T> inline std::string toString (const T& x) |
---|
24 | { |
---|
25 | ostringstream out; |
---|
26 | out << x; |
---|
27 | return out.str(); |
---|
28 | } |
---|
29 | |
---|
30 | template<> inline std::string toString<bool> (const bool& x) |
---|
31 | { |
---|
32 | ostringstream out; |
---|
33 | //out << boolalpha << x; |
---|
34 | out << x; |
---|
35 | return out.str(); |
---|
36 | } |
---|
37 | |
---|
38 | template<> inline std::string toString<float> (const float& x) |
---|
39 | { |
---|
40 | const int sigdigits = std::numeric_limits<float>::digits10; |
---|
41 | ostringstream out; |
---|
42 | out << setprecision(sigdigits) << x; |
---|
43 | return out.str(); |
---|
44 | } |
---|
45 | |
---|
46 | template<> inline std::string toString<double> (const double& x) |
---|
47 | { |
---|
48 | const int sigdigits = std::numeric_limits<double>::digits10; |
---|
49 | ostringstream out; |
---|
50 | out << setprecision(sigdigits) << x; |
---|
51 | return out.str(); |
---|
52 | } |
---|
53 | |
---|
54 | template<> inline std::string toString<long double>(const long double& x) |
---|
55 | { |
---|
56 | const int sigdigits = std::numeric_limits<long double>::digits10; |
---|
57 | ostringstream out; |
---|
58 | out << setprecision(sigdigits) << x; |
---|
59 | return out.str(); |
---|
60 | } |
---|
61 | |
---|
62 | }; // end namespace morpheo |
---|
63 | |
---|
64 | #endif |
---|
Note: See
TracBrowser
for help on using the repository browser.