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

Last change on this file since 81 was 81, checked in by rosiere, 16 years ago
  • Finish Environment (and test)
  • Continue predictor_unit
  • Add external tools
  • svn keyword "Id" set
  • Property svn:keywords set to Id
File size: 2.4 KB
RevLine 
[15]1#ifndef morpheo_tostring
2#define morpheo_tostring
[2]3
4/*
5 * $Id: ToString.h 81 2008-04-15 18:40:01Z rosiere $
6 *
[66]7 * with a stephane dubuisson initial idea
8 *
9 * [ Description ]
[2]10 *
11 */
12
13#include <iosfwd>
14#include <sstream>
15#include <iomanip>
16#include <string>
17#include <limits>
18
19namespace morpheo              {
20 
[15]21  template<typename T> inline std::string toString             (const T& x)
[2]22  {
[71]23    std::ostringstream out("");
[2]24    out << x;
25    return out.str();
26  }
27 
[15]28  template<>           inline std::string toString<bool>       (const bool& x)
[2]29  {
[71]30    std::ostringstream out("");
[2]31    //out << boolalpha << x;
32    out << x;
33    return out.str();
34  }
35 
[15]36  template<>           inline std::string toString<float>      (const float& x)
[2]37  {
38    const int sigdigits = std::numeric_limits<float>::digits10;
[71]39    std::ostringstream out("");
40    out << std::setprecision(sigdigits) << x;
[2]41    return out.str();
42  }
43 
[15]44  template<>           inline std::string toString<double>     (const double& x)
[2]45  {
46    const int sigdigits = std::numeric_limits<double>::digits10;
[71]47    std::ostringstream out("");
48    out << std::setprecision(sigdigits) << x;
[2]49    return out.str();
50  }
51 
[15]52  template<>           inline std::string toString<long double>(const long double& x)
[2]53  {
54    const int sigdigits = std::numeric_limits<long double>::digits10;
[71]55    std::ostringstream out("");
56    out << std::setprecision(sigdigits) << x;
[2]57    return out.str();
58  }
[66]59
[78]60  template<>           inline std::string toString< int8_t>       (const int8_t& x)
61  {
62    std::ostringstream out("");
63    out << static_cast< int32_t>(x);
64    return out.str();
65  }
[66]66
[78]67  template<>           inline std::string toString<uint8_t>       (const uint8_t& x)
68  {
69    std::ostringstream out("");
70    out << static_cast<uint32_t>(x);
71    return out.str();
72  }
[66]73
[78]74  template<>           inline std::string toString< int16_t>      (const int16_t& x)
75  {
76    std::ostringstream out("");
77    out << static_cast< int32_t>(x);
78    return out.str();
79  }
[66]80
[78]81  template<>           inline std::string toString<uint16_t>      (const uint16_t& x)
82  {
83    std::ostringstream out("");
84    out << static_cast<uint32_t>(x);
85    return out.str();
86  }
[66]87
[78]88  template<>           inline std::string toString< int32_t>      (const int32_t& x)
89  {
90    std::ostringstream out("");
91    out << x;
92    return out.str();
93  }
[66]94
[78]95  template<>           inline std::string toString<uint32_t>      (const uint32_t& x)
96  {
97    std::ostringstream out("");
98    out << x;
99    return out.str();
100  }
[2]101 
102}; // end namespace morpheo             
103
104#endif
Note: See TracBrowser for help on using the repository browser.