source: trunk/IPs/systemC/processor/Morpheo/Include/ToString.h @ 3

Last change on this file since 3 was 2, checked in by kane, 17 years ago

Import Morpheo

File size: 1.3 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
17using std::setprecision ; 
18using std::ostringstream ; 
19using std::boolalpha ;
20
21namespace 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.