1 /*
2 ---------------------------------------------------------------------------
3 Open Asset Import Library (ASSIMP)
4 ---------------------------------------------------------------------------
5 
6 Copyright (c) 2006-2020, ASSIMP Development Team
7 
8 All rights reserved.
9 
10 Redistribution and use of this software in source and binary forms,
11 with or without modification, are permitted provided that the following
12 conditions are met:
13 
14  * Redistributions of source code must retain the above
15   copyright notice, this list of conditions and the
16   following disclaimer.
17 
18  * Redistributions in binary form must reproduce the above
19   copyright notice, this list of conditions and the
20   following disclaimer in the documentation and/or other
21   materials provided with the distribution.
22 
23  * Neither the name of the ASSIMP team, nor the names of its
24   contributors may be used to endorse or promote products
25   derived from this software without specific prior
26   written permission of the ASSIMP Development Team.
27 
28 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 ---------------------------------------------------------------------------
40 */
41 
42 /**
43  * The data structures necessary to use Assimip with a custom IO system.
44  */
45 module assimp.fileIO;
46 
47 import assimp.types;
48 
49 extern ( C ) {
50    // aiFile callbacks
51    alias size_t function( aiFile*, char*, size_t, size_t ) aiFileWriteProc;
52    alias size_t function(  aiFile*, char*, size_t, size_t ) aiFileReadProc;
53    alias size_t function( aiFile* ) aiFileTellProc;
54    alias void function( aiFile* ) aiFileFlushProc;
55    alias aiReturn function( aiFile*, size_t, aiOrigin ) aiFileSeek;
56 
57    // aiFileIO callbacks
58    alias aiFile* function( aiFileIO*, char*, char* ) aiFileOpenProc;
59    alias void function( aiFileIO*,  aiFile* ) aiFileCloseProc;
60 
61    /**
62     * Represents user-defined data.
63     */
64    alias char* aiUserData;
65 
66    /**
67     * File system callbacks.
68     *
69     * Provided are functions to open and close files. Supply a custom structure
70     * to the import function. If you don't, a default implementation is used.
71     * Use custom file systems to enable reading from other sources, such as
72     * ZIPs or memory locations.
73     */
74    struct aiFileIO {
75       /**
76        * Function used to open a new file
77        */
78       aiFileOpenProc OpenProc;
79 
80       /**
81        * Function used to close an existing file
82        */
83       aiFileCloseProc CloseProc;
84 
85       /**
86        * User-defined, opaque data.
87        */
88       aiUserData UserData;
89    }
90 
91    /**
92     * File callbacks.
93     *
94     * Actually, it's a data structure to wrap a set of <code>fXXXX</code>
95     * (e.g <code>fopen()</code>) replacement functions.
96     *
97     * The default implementation of the functions utilizes the <code>fXXX</code>
98     * functions from the CRT. However, you can supply a custom implementation
99     * to Assimp by passing a custom <code>aiFileIO</code>. Use this to enable
100     * reading from other sources such as ZIP archives or memory locations.
101     */
102    struct aiFile {
103       /**
104        * Callback to read from a file.
105        */
106       aiFileReadProc ReadProc;
107 
108       /**
109        * Callback to write to a file.
110        */
111       aiFileWriteProc WriteProc;
112 
113       /**
114        * Callback to retrieve the current position of the file cursor
115        * (<code>ftell()</code>).
116        */
117       aiFileTellProc TellProc;
118 
119       /**
120        * Callback to retrieve the size of the file, in bytes.
121        */
122       aiFileTellProc FileSizeProc;
123 
124       /**
125        * Callback to set the current position of the file cursor
126        * (<code>fseek()</code>).
127        */
128       aiFileSeek SeekProc;
129 
130       /**
131        * Callback to flush the file contents.
132        */
133       aiFileFlushProc FlushProc;
134 
135       /**
136        * User-defined, opaque data.
137        */
138       aiUserData UserData;
139    }
140 }
141