Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

135 lignes
2.9 KiB

  1. #pragma once
  2. #include <string>
  3. #include <cstddef>
  4. #include <iostream>
  5. #include <cpphibernate/config.h>
  6. #include <cppcore/misc/exception.h>
  7. namespace cpphibernate
  8. {
  9. /**
  10. * @brief Hibernate exception class.
  11. */
  12. struct exception
  13. : public cppcore::exception
  14. {
  15. using cppcore::exception::exception;
  16. };
  17. /**
  18. * @brief Represents a string with an fixed length.
  19. */
  20. template<size_t N>
  21. struct string
  22. : public std::string
  23. {
  24. static constexpr decltype(auto) max_size = N;
  25. using std::string::string;
  26. using std::string::operator=;
  27. };
  28. /**
  29. * @brief Timestamp class.
  30. */
  31. struct timestamp
  32. {
  33. uint64_t value;
  34. /**
  35. * @brief Default constructor.
  36. */
  37. inline timestamp() = default;
  38. /**
  39. * @brief Value constructor.
  40. */
  41. inline timestamp(uint64_t v);
  42. /**
  43. * @brief Value assignment constructor.
  44. */
  45. inline timestamp& operator=(const uint64_t& v);
  46. /**
  47. * @brief Impicit type conversion to base type.
  48. */
  49. inline operator uint64_t() const;
  50. };
  51. /**
  52. * @brief A typical UUID implementation.
  53. */
  54. struct uuid
  55. : public std::array<uint8_t, 16>
  56. {
  57. public:
  58. /**
  59. * @brief Default constructor.
  60. */
  61. inline uuid();
  62. /**
  63. * @brief Construtor to create a UUID from a string.
  64. *
  65. * @param[in] str String to create UUID from.
  66. */
  67. inline uuid(const std::string& str);
  68. /**
  69. * @brief Move constructor.
  70. */
  71. inline uuid(uuid&&) = default;
  72. /**
  73. * @brief Copy constructor.
  74. */
  75. inline uuid(const uuid&) = default;
  76. /**
  77. * @brief Move assignment constructor.
  78. */
  79. inline uuid& operator = (uuid&&) = default;
  80. /**
  81. * @brief Copy assignment constructor.
  82. */
  83. inline uuid& operator = (const uuid&) = default;
  84. /**
  85. * @brief Write the UUID to passed stream.
  86. *
  87. * @param[in] os Stream to write UUID to.
  88. */
  89. void to_string(std::ostream& os) const;
  90. /**
  91. * @brief Write the UUID to passed stream.
  92. *
  93. * @param[in] os Stream to write UUID to.
  94. *
  95. * @return Stream passed as parameter.
  96. */
  97. std::ostream& operator<<(std::ostream& os) const;
  98. public:
  99. /**
  100. * @brief Create an UUID object from an string.
  101. *
  102. * @param[in] str String to create UUID from.
  103. * @param[in] val Parameter to store converted object in
  104. *
  105. * @retval true If the convertion was successful.
  106. * @retval false If the string could not be converted.
  107. */
  108. static bool from_string(const std::string& str, uuid& val);
  109. };
  110. }
  111. #include "types.inl"