to_text.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Converters of non-character C++ fundamental types to some text representation
  2. //
  3. // Platform: ISO C++ 98/11
  4. // $Id$
  5. //
  6. // (c) __vic 2007
  7. #ifndef __VIC_TO_TEXT_H
  8. #define __VIC_TO_TEXT_H
  9. #include<__vic/defs.h>
  10. #include<string>
  11. namespace __vic {
  12. void to_text_append(long , std::string & );
  13. void to_text_append(unsigned long , std::string & );
  14. void to_text_append(__VIC_LONGLONG , std::string & );
  15. void to_text_append(unsigned __VIC_LONGLONG , std::string & );
  16. void to_text_append(double , std::string & );
  17. void to_text_append(long double , std::string & );
  18. void to_text_append(const void * , std::string & );
  19. //----------------------------------------------------------------------------
  20. inline void to_text_append(int n, std::string &s)
  21. {
  22. to_text_append(static_cast<long>(n), s);
  23. }
  24. inline void to_text_append(unsigned n, std::string &s)
  25. {
  26. to_text_append(static_cast<unsigned long>(n), s);
  27. }
  28. //----------------------------------------------------------------------------
  29. //----------------------------------------------------------------------------
  30. inline void to_text_append(short n, std::string &s)
  31. {
  32. to_text_append(static_cast<long>(n), s);
  33. }
  34. inline void to_text_append(unsigned short n, std::string &s)
  35. {
  36. to_text_append(static_cast<unsigned long>(n), s);
  37. }
  38. //----------------------------------------------------------------------------
  39. //----------------------------------------------------------------------------
  40. // [un]signed char is treated as an integer type!!
  41. //----------------------------------------------------------------------------
  42. inline void to_text_append(signed char n, std::string &s)
  43. {
  44. to_text_append(static_cast<int>(n), s);
  45. }
  46. inline void to_text(unsigned char n, std::string &s)
  47. {
  48. to_text_append(static_cast<unsigned>(n), s);
  49. }
  50. //----------------------------------------------------------------------------
  51. //----------------------------------------------------------------------------
  52. inline void to_text_append(float n, std::string &s)
  53. {
  54. to_text_append(static_cast<double>(n), s);
  55. }
  56. //----------------------------------------------------------------------------
  57. //----------------------------------------------------------------------------
  58. inline void to_text_append(bool f, std::string &s)
  59. {
  60. s += (f ? '1' : '0');
  61. }
  62. //----------------------------------------------------------------------------
  63. } // namespace
  64. #endif // header guard