cfileio.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 cfileio.h
  35. * @brief Defines generic C routines to access memory-mapped files
  36. */
  37. #pragma once
  38. #ifndef AI_FILEIO_H_INC
  39. #define AI_FILEIO_H_INC
  40. #ifdef __GNUC__
  41. # pragma GCC system_header
  42. #endif
  43. #include <assimp/types.h>
  44. #ifdef __cplusplus
  45. extern "C" {
  46. #endif
  47. struct aiFileIO;
  48. struct aiFile;
  49. // aiFile callbacks
  50. typedef size_t (*aiFileWriteProc) (C_STRUCT aiFile*, const char*, size_t, size_t);
  51. typedef size_t (*aiFileReadProc) (C_STRUCT aiFile*, char*, size_t,size_t);
  52. typedef size_t (*aiFileTellProc) (C_STRUCT aiFile*);
  53. typedef void (*aiFileFlushProc) (C_STRUCT aiFile*);
  54. typedef C_ENUM aiReturn (*aiFileSeek) (C_STRUCT aiFile*, size_t, C_ENUM aiOrigin);
  55. // aiFileIO callbacks
  56. typedef C_STRUCT aiFile* (*aiFileOpenProc) (C_STRUCT aiFileIO*, const char*, const char*);
  57. typedef void (*aiFileCloseProc) (C_STRUCT aiFileIO*, C_STRUCT aiFile*);
  58. // Represents user-defined data
  59. typedef char* aiUserData;
  60. // ----------------------------------------------------------------------------------
  61. /** @brief C-API: File system callbacks
  62. *
  63. * Provided are functions to open and close files. Supply a custom structure to
  64. * the import function. If you don't, a default implementation is used. Use custom
  65. * file systems to enable reading from other sources, such as ZIPs
  66. * or memory locations. */
  67. struct aiFileIO
  68. {
  69. /** Function used to open a new file
  70. */
  71. aiFileOpenProc OpenProc;
  72. /** Function used to close an existing file
  73. */
  74. aiFileCloseProc CloseProc;
  75. /** User-defined, opaque data */
  76. aiUserData UserData;
  77. };
  78. // ----------------------------------------------------------------------------------
  79. /** @brief C-API: File callbacks
  80. *
  81. * Actually, it's a data structure to wrap a set of fXXXX (e.g fopen)
  82. * replacement functions.
  83. *
  84. * The default implementation of the functions utilizes the fXXX functions from
  85. * the CRT. However, you can supply a custom implementation to Assimp by
  86. * delivering a custom aiFileIO. Use this to enable reading from other sources,
  87. * such as ZIP archives or memory locations. */
  88. struct aiFile {
  89. /** Callback to read from a file */
  90. aiFileReadProc ReadProc;
  91. /** Callback to write to a file */
  92. aiFileWriteProc WriteProc;
  93. /** Callback to retrieve the current position of
  94. * the file cursor (ftell())
  95. */
  96. aiFileTellProc TellProc;
  97. /** Callback to retrieve the size of the file,
  98. * in bytes
  99. */
  100. aiFileTellProc FileSizeProc;
  101. /** Callback to set the current position
  102. * of the file cursor (fseek())
  103. */
  104. aiFileSeek SeekProc;
  105. /** Callback to flush the file contents
  106. */
  107. aiFileFlushProc FlushProc;
  108. /** User-defined, opaque data
  109. */
  110. aiUserData UserData;
  111. };
  112. #ifdef __cplusplus
  113. }
  114. #endif
  115. #endif // AI_FILEIO_H_INC