💿🐜 Antkeeper source code https://antkeeper.com
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.

100 lines
2.6 KiB

  1. /*
  2. * Copyright (C) 2023 Christopher J. Howard
  3. *
  4. * This file is part of Antkeeper source code.
  5. *
  6. * Antkeeper source code is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Antkeeper source code is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef ANTKEEPER_RESOURCES_SERIALIZE_CONTEXT_HPP
  20. #define ANTKEEPER_RESOURCES_SERIALIZE_CONTEXT_HPP
  21. #include <cstddef>
  22. #include <bit>
  23. /**
  24. * Provides access to a serialization state.
  25. */
  26. struct serialize_context
  27. {
  28. public:
  29. static inline constexpr std::endian endian = std::endian::little;
  30. /**
  31. * Writes 8-bit (byte) data.
  32. *
  33. * @param data Pointer to data source.
  34. * @param count Number of bytes to write.
  35. *
  36. * @return Number of bytes written.
  37. *
  38. * @throw serialize_error Write error.
  39. */
  40. std::size_t write8(const std::byte* data, std::size_t count) noexcept(false);
  41. /**
  42. * Writes 16-bit (word) data.
  43. *
  44. * @param data Pointer to data source.
  45. * @param count Number of words to write.
  46. *
  47. * @return Number of words written.
  48. *
  49. * @throw serialize_error Write error.
  50. */
  51. std::size_t write16(const std::byte* data, std::size_t count) noexcept(false);
  52. /**
  53. * Writes 32-bit (double word) data.
  54. *
  55. * @param data Pointer to data source.
  56. * @param count Number of double words to write.
  57. *
  58. * @return Number of double words written.
  59. *
  60. * @throw serialize_error Write error.
  61. */
  62. std::size_t write32(const std::byte* data, std::size_t count) noexcept(false);
  63. /**
  64. * Writes 64-bit (quad word) data.
  65. *
  66. * @param data Pointer to data source.
  67. * @param count Number of quad words to write.
  68. *
  69. * @return Number of quad words written.
  70. *
  71. * @throw serialize_error Write error.
  72. */
  73. std::size_t write64(const std::byte* data, std::size_t count) noexcept(false);
  74. /**
  75. * Returns `true` if an error occured during a write operation, `false` otherwise.
  76. */
  77. inline bool error() const noexcept
  78. {
  79. return m_error;
  80. }
  81. private:
  82. template <class T>
  83. friend class resource_loader;
  84. serialize_context(void* handle);
  85. void* handle;
  86. bool m_error;
  87. };
  88. #endif // ANTKEEPER_RESOURCES_SERIALIZE_CONTEXT_HPP