cfileio.h 4.5 KB

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