ChipMaster's trial hacks on C++CMS starting with v1.2.1. Not sure I'll follow on with the v2 since it looks to be breaking and mostly frivolous.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

113 lines
2.3 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (C) 2008-2012 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>
  4. //
  5. // See accompanying file COPYING.TXT file for licensing details.
  6. //
  7. ///////////////////////////////////////////////////////////////////////////////
  8. #ifndef CPPCMS_IMPL_TODEC_H
  9. #define CPPCMS_IMPL_TODEC_H
  10. #include <limits>
  11. #include <ostream>
  12. namespace cppcms {
  13. namespace impl {
  14. namespace details {
  15. template<bool sig>
  16. struct decimal_traits;
  17. template<>
  18. struct decimal_traits<false> {
  19. template<typename T>
  20. static void conv(T v,char *&begin,char *&buf)
  21. {
  22. begin = buf;
  23. while(v!=0) {
  24. *buf++ = '0' + v % 10;
  25. v/=10;
  26. }
  27. }
  28. };
  29. template<>
  30. struct decimal_traits<true> {
  31. template<typename T>
  32. static void conv(T v,char *&begin,char *&buf)
  33. {
  34. if(v<0) {
  35. *buf++ = '-';
  36. begin=buf;
  37. while(v!=0) {
  38. *buf++ = '0' - (v % 10);
  39. v/=10;
  40. }
  41. }
  42. else {
  43. decimal_traits<false>::conv(v,begin,buf);
  44. }
  45. }
  46. };
  47. }
  48. template<typename Integer>
  49. void todec(Integer v,char *buf)
  50. {
  51. typedef std::numeric_limits<Integer> limits;
  52. if(v == 0) {
  53. *buf++ = '0';
  54. *buf++ = 0;
  55. return;
  56. }
  57. char *begin=0;
  58. details::decimal_traits<limits::is_signed>::conv(v,begin,buf);
  59. *buf-- = 0;
  60. while(begin < buf) {
  61. char tmp = *begin;
  62. *begin = *buf;
  63. *buf = tmp;
  64. buf--;
  65. begin++;
  66. }
  67. }
  68. template<typename I>
  69. std::string todec_string(I v)
  70. {
  71. char buf[std::numeric_limits<I>::digits10 + 4];
  72. todec<I>(v,buf);
  73. std::string tmp = buf;
  74. return tmp;
  75. }
  76. namespace details {
  77. template<typename T>
  78. struct write_int_to_stream {
  79. write_int_to_stream(T vi = 0) : v(vi) {}
  80. T v;
  81. void operator()(std::ostream &out) const
  82. {
  83. char buf[std::numeric_limits<T>::digits10 + 4];
  84. todec<T>(v,buf);
  85. out << buf;
  86. }
  87. };
  88. template<typename T>
  89. std::ostream &operator<<(std::ostream &out,write_int_to_stream<T> const &v)
  90. {
  91. v(out);
  92. return out;
  93. }
  94. } // details
  95. template<typename T>
  96. details::write_int_to_stream<T> cint(T v)
  97. {
  98. return details::write_int_to_stream<T>(v);
  99. }
  100. }
  101. }
  102. #endif