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.
 
 
 

115 line
2.5 KiB

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