soci-exchange-cast.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. //
  2. // Copyright (C) 2015 Vadim Zeitlin
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. #ifndef SOCI_EXCHANGE_CAST_H_INCLUDED
  8. #define SOCI_EXCHANGE_CAST_H_INCLUDED
  9. #include "soci/soci-backend.h"
  10. #include "soci/type-wrappers.h"
  11. #include "soci/blob.h"
  12. #include <cstdint>
  13. #include <ctime>
  14. namespace soci
  15. {
  16. namespace details
  17. {
  18. // cast the given non-null untyped pointer to its corresponding type
  19. template <exchange_type e> struct exchange_type_traits;
  20. template <>
  21. struct exchange_type_traits<x_char>
  22. {
  23. typedef char value_type;
  24. };
  25. template <>
  26. struct exchange_type_traits<x_stdstring>
  27. {
  28. typedef std::string value_type;
  29. };
  30. template <>
  31. struct exchange_type_traits<x_int8>
  32. {
  33. typedef int8_t value_type;
  34. };
  35. template <>
  36. struct exchange_type_traits<x_uint8>
  37. {
  38. typedef uint8_t value_type;
  39. };
  40. template <>
  41. struct exchange_type_traits<x_int16>
  42. {
  43. typedef int16_t value_type;
  44. };
  45. template <>
  46. struct exchange_type_traits<x_uint16>
  47. {
  48. typedef uint16_t value_type;
  49. };
  50. template <>
  51. struct exchange_type_traits<x_int32>
  52. {
  53. typedef int32_t value_type;
  54. };
  55. template <>
  56. struct exchange_type_traits<x_uint32>
  57. {
  58. typedef uint32_t value_type;
  59. };
  60. template <>
  61. struct exchange_type_traits<x_int64>
  62. {
  63. typedef int64_t value_type;
  64. };
  65. template <>
  66. struct exchange_type_traits<x_uint64>
  67. {
  68. typedef uint64_t value_type;
  69. };
  70. template <>
  71. struct exchange_type_traits<x_double>
  72. {
  73. typedef double value_type;
  74. };
  75. template <>
  76. struct exchange_type_traits<x_stdtm>
  77. {
  78. typedef std::tm value_type;
  79. };
  80. template <>
  81. struct exchange_type_traits<x_longstring>
  82. {
  83. typedef long_string value_type;
  84. };
  85. template <>
  86. struct exchange_type_traits<x_xmltype>
  87. {
  88. typedef xml_type value_type;
  89. };
  90. template <>
  91. struct exchange_type_traits<x_blob>
  92. {
  93. typedef blob value_type;
  94. };
  95. // exchange_type_traits not defined for x_statement, x_rowid and x_blob here.
  96. template <exchange_type e>
  97. typename exchange_type_traits<e>::value_type& exchange_type_cast(void *data)
  98. {
  99. return *static_cast<typename exchange_type_traits<e>::value_type*>(data);
  100. }
  101. } // namespace details
  102. } // namespace soci
  103. #endif // SOCI_EXCHANGE_CAST_H_INCLUDED