flex_string_details.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. ////////////////////////////////////////////////////////////////////////////////
  2. // flex_string
  3. // Copyright (c) 2001 by Andrei Alexandrescu
  4. // Permission to use, copy, modify, distribute and sell this software for any
  5. // purpose is hereby granted without fee, provided that the above copyright
  6. // notice appear in all copies and that both that copyright notice and this
  7. // permission notice appear in supporting documentation.
  8. // The author makes no representations about the
  9. // suitability of this software for any purpose. It is provided "as is"
  10. // without express or implied warranty.
  11. ////////////////////////////////////////////////////////////////////////////////
  12. #ifndef DAHUA_FLEX_STRING_DETAILS_INC_
  13. #define DAHUA_FLEX_STRING_DETAILS_INC_
  14. // revision 754
  15. #include <cstring> // for memmove memcpy
  16. #include <iterator>
  17. #include <utility> // for vc6 iterator_traits
  18. namespace Dahua {
  19. namespace Infra {
  20. namespace flex_string_details
  21. {
  22. template <class InIt, class OutIt>
  23. #if defined(_MSC_VER) && (_MSC_VER < 1300)
  24. OutIt copy_n(InIt b, typename std::iterator_traits<InIt>::distance_type n, OutIt d)
  25. #else
  26. OutIt copy_n(InIt b, typename std::iterator_traits<InIt>::difference_type n, OutIt d)
  27. #endif
  28. {
  29. for (; n != 0; --n, ++b, ++d)
  30. {
  31. *d = *b;
  32. }
  33. return d;
  34. }
  35. template <class Pod, class T>
  36. inline void pod_fill(Pod* b, Pod* e, T c)
  37. {
  38. switch ((e - b) & 7)
  39. {
  40. case 0:
  41. while (b != e)
  42. {
  43. *b = c; ++b;
  44. case 7: *b = c; ++b;
  45. case 6: *b = c; ++b;
  46. case 5: *b = c; ++b;
  47. case 4: *b = c; ++b;
  48. case 3: *b = c; ++b;
  49. case 2: *b = c; ++b;
  50. case 1: *b = c; ++b;
  51. }
  52. }
  53. }
  54. template <class Pod>
  55. inline void pod_move(const Pod* b, const Pod* e, Pod* d)
  56. {
  57. using namespace std;
  58. memmove(d, b, (e - b) * sizeof(*b));
  59. }
  60. template <class Pod>
  61. inline Pod* pod_copy(const Pod* b, const Pod* e, Pod* d)
  62. {
  63. const size_t s = e - b;
  64. using namespace std;
  65. memcpy(d, b, s * sizeof(*b));
  66. return d + s;
  67. }
  68. template <typename T> struct get_unsigned
  69. {
  70. typedef T result;
  71. };
  72. template <> struct get_unsigned<char>
  73. {
  74. typedef unsigned char result;
  75. };
  76. template <> struct get_unsigned<signed char>
  77. {
  78. typedef unsigned char result;
  79. };
  80. template <> struct get_unsigned<short int>
  81. {
  82. typedef unsigned short int result;
  83. };
  84. template <> struct get_unsigned<int>
  85. {
  86. typedef unsigned int result;
  87. };
  88. template <> struct get_unsigned<long int>
  89. {
  90. typedef unsigned long int result;
  91. };
  92. enum Shallow {};
  93. }
  94. } // namespace Infra
  95. } // namespace Dahua
  96. #endif // DAHUA_FLEX_STRING_DETAILS_INC_