IOStream.hpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (assimp)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2025, assimp team
  6. All rights reserved.
  7. Redistribution and use of this software in source and binary forms,
  8. with or without modification, are permitted provided that the following
  9. conditions are met:
  10. * Redistributions of source code must retain the above
  11. copyright notice, this list of conditions and the
  12. following disclaimer.
  13. * Redistributions in binary form must reproduce the above
  14. copyright notice, this list of conditions and the
  15. following disclaimer in the documentation and/or other
  16. materials provided with the distribution.
  17. * Neither the name of the assimp team, nor the names of its
  18. contributors may be used to endorse or promote products
  19. derived from this software without specific prior
  20. written permission of the assimp team.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. ---------------------------------------------------------------------------
  33. */
  34. /** @file IOStream.hpp
  35. * @brief File I/O wrappers for C++.
  36. */
  37. #pragma once
  38. #ifndef AI_IOSTREAM_H_INC
  39. #define AI_IOSTREAM_H_INC
  40. #ifdef __GNUC__
  41. # pragma GCC system_header
  42. #endif
  43. #include <assimp/types.h>
  44. #ifndef __cplusplus
  45. # error This header requires C++ to be used. aiFileIO.h is the \
  46. corresponding C interface.
  47. #endif
  48. namespace Assimp {
  49. // ----------------------------------------------------------------------------------
  50. /** @brief CPP-API: Class to handle file I/O for C++
  51. *
  52. * Derive an own implementation from this interface to provide custom IO handling
  53. * to the Importer. If you implement this interface, be sure to also provide an
  54. * implementation for IOSystem that creates instances of your custom IO class.
  55. */
  56. class ASSIMP_API IOStream
  57. #ifndef SWIG
  58. : public Intern::AllocateFromAssimpHeap
  59. #endif
  60. {
  61. protected:
  62. /** Constructor protected, use IOSystem::Open() to create an instance. */
  63. IOStream() AI_NO_EXCEPT = default;
  64. public:
  65. // -------------------------------------------------------------------
  66. /** @brief Destructor. Deleting the object closes the underlying file,
  67. * alternatively you may use IOSystem::Close() to release the file.
  68. */
  69. virtual ~IOStream() = default;
  70. // -------------------------------------------------------------------
  71. /** @brief Read from the file
  72. *
  73. * See fread() for more details
  74. * This fails for write-only files */
  75. virtual size_t Read(void* pvBuffer,
  76. size_t pSize,
  77. size_t pCount) = 0;
  78. // -------------------------------------------------------------------
  79. /** @brief Write to the file
  80. *
  81. * See fwrite() for more details
  82. * This fails for read-only files */
  83. virtual size_t Write(const void* pvBuffer,
  84. size_t pSize,
  85. size_t pCount) = 0;
  86. // -------------------------------------------------------------------
  87. /** @brief Set the read/write cursor of the file
  88. *
  89. * Note that the offset is _negative_ for aiOrigin_END.
  90. * See fseek() for more details */
  91. virtual aiReturn Seek(size_t pOffset,
  92. aiOrigin pOrigin) = 0;
  93. // -------------------------------------------------------------------
  94. /** @brief Get the current position of the read/write cursor
  95. *
  96. * See ftell() for more details */
  97. virtual size_t Tell() const = 0;
  98. // -------------------------------------------------------------------
  99. /** @brief Returns filesize
  100. * Returns the filesize. */
  101. virtual size_t FileSize() const = 0;
  102. // -------------------------------------------------------------------
  103. /** @brief Flush the contents of the file buffer (for writers)
  104. * See fflush() for more details.
  105. */
  106. virtual void Flush() = 0;
  107. }; //! class IOStream
  108. } //!namespace Assimp
  109. #endif //!!AI_IOSTREAM_H_INC