source: trunk/IPs/systemC/processor/Morpheo/Common/include/ToString.h @ 66

Last change on this file since 66 was 66, checked in by rosiere, 17 years ago
  • un pas de plus vers la compatibilite avec systemC
  • modification de l'interface de read_queue : context_id devient context_id, front_end_id et ooo_engine_id
File size: 2.5 KB
Line 
1#ifndef morpheo_tostring
2#define morpheo_tostring
3
4/*
5 * $Id$
6 *
7 * with a stephane dubuisson initial idea
8 *
9 * [ Description ]
10 *
11 */
12
13#include <iosfwd>
14#include <sstream>
15#include <iomanip>
16#include <string>
17#include <limits>
18
19using std::setprecision ; 
20using std::ostringstream ; 
21using std::boolalpha ;
22
23namespace morpheo              {
24 
25  template<typename T> inline std::string toString             (const T& x)
26  {
27    ostringstream out("");
28    out << x;
29    return out.str();
30  }
31 
32  template<>           inline std::string toString<bool>       (const bool& x)
33  {
34    ostringstream out("");
35    //out << boolalpha << x;
36    out << x;
37    return out.str();
38  }
39 
40  template<>           inline std::string toString<float>      (const float& x)
41  {
42    const int sigdigits = std::numeric_limits<float>::digits10;
43    ostringstream out("");
44    out << setprecision(sigdigits) << x;
45    return out.str();
46  }
47 
48  template<>           inline std::string toString<double>     (const double& x)
49  {
50    const int sigdigits = std::numeric_limits<double>::digits10;
51    ostringstream out("");
52    out << setprecision(sigdigits) << x;
53    return out.str();
54  }
55 
56  template<>           inline std::string toString<long double>(const long double& x)
57  {
58    const int sigdigits = std::numeric_limits<long double>::digits10;
59    ostringstream out("");
60    out << setprecision(sigdigits) << x;
61    return out.str();
62  }
63
64//   template<>           inline std::string toString< int8_t>       (const int8_t& x)
65//   {
66//     ostringstream out("");
67//     out << x;
68//     return out.str();
69//   }
70
71//   template<>           inline std::string toString<uint8_t>       (const uint8_t& x)
72//   {
73//     ostringstream out("");
74//     out << x;
75//     return out.str();
76//   }
77
78//   template<>           inline std::string toString< int16_t>      (const int16_t& x)
79//   {
80//     ostringstream out("");
81//     out << x;
82//     return out.str();
83//   }
84
85//   template<>           inline std::string toString<uint16_t>      (const uint16_t& x)
86//   {
87//     ostringstream out("");
88//     out << x;
89//     return out.str();
90//   }
91
92//   template<>           inline std::string toString< int32_t>      (const int32_t& x)
93//   {
94//     ostringstream out("");
95//     out << x;
96//     return out.str();
97//   }
98
99//   template<>           inline std::string toString<uint32_t>      (const uint32_t& x)
100//   {
101//     ostringstream out("");
102//     out << x;
103//     return out.str();
104//   }
105 
106}; // end namespace morpheo             
107
108#endif
Note: See TracBrowser for help on using the repository browser.