rev |
line source |
nuclear@0
|
1 /*
|
nuclear@0
|
2 ---------------------------------------------------------------------------
|
nuclear@0
|
3 Open Asset Import Library (assimp)
|
nuclear@0
|
4 ---------------------------------------------------------------------------
|
nuclear@0
|
5
|
nuclear@0
|
6 Copyright (c) 2006-2012, assimp team
|
nuclear@0
|
7
|
nuclear@0
|
8 All rights reserved.
|
nuclear@0
|
9
|
nuclear@0
|
10 Redistribution and use of this software in source and binary forms,
|
nuclear@0
|
11 with or without modification, are permitted provided that the following
|
nuclear@0
|
12 conditions are met:
|
nuclear@0
|
13
|
nuclear@0
|
14 * Redistributions of source code must retain the above
|
nuclear@0
|
15 copyright notice, this list of conditions and the
|
nuclear@0
|
16 following disclaimer.
|
nuclear@0
|
17
|
nuclear@0
|
18 * Redistributions in binary form must reproduce the above
|
nuclear@0
|
19 copyright notice, this list of conditions and the
|
nuclear@0
|
20 following disclaimer in the documentation and/or other
|
nuclear@0
|
21 materials provided with the distribution.
|
nuclear@0
|
22
|
nuclear@0
|
23 * Neither the name of the assimp team, nor the names of its
|
nuclear@0
|
24 contributors may be used to endorse or promote products
|
nuclear@0
|
25 derived from this software without specific prior
|
nuclear@0
|
26 written permission of the assimp team.
|
nuclear@0
|
27
|
nuclear@0
|
28 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
nuclear@0
|
29 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
nuclear@0
|
30 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
nuclear@0
|
31 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
nuclear@0
|
32 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
nuclear@0
|
33 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
nuclear@0
|
34 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
nuclear@0
|
35 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
nuclear@0
|
36 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
nuclear@0
|
37 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
nuclear@0
|
38 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
nuclear@0
|
39 ---------------------------------------------------------------------------
|
nuclear@0
|
40 */
|
nuclear@0
|
41
|
nuclear@0
|
42 /** @file IOSystem.h
|
nuclear@0
|
43 * @brief File system wrapper for C++. Inherit this class to supply
|
nuclear@0
|
44 * custom file handling logic to the Import library.
|
nuclear@0
|
45 */
|
nuclear@0
|
46
|
nuclear@0
|
47 #ifndef AI_IOSYSTEM_H_INC
|
nuclear@0
|
48 #define AI_IOSYSTEM_H_INC
|
nuclear@0
|
49
|
nuclear@0
|
50 #ifndef __cplusplus
|
nuclear@0
|
51 # error This header requires C++ to be used. aiFileIO.h is the \
|
nuclear@0
|
52 corresponding C interface.
|
nuclear@0
|
53 #endif
|
nuclear@0
|
54
|
nuclear@0
|
55 #include "types.h"
|
nuclear@0
|
56 namespace Assimp {
|
nuclear@0
|
57 class IOStream;
|
nuclear@0
|
58
|
nuclear@0
|
59 // ---------------------------------------------------------------------------
|
nuclear@0
|
60 /** @brief CPP-API: Interface to the file system.
|
nuclear@0
|
61 *
|
nuclear@0
|
62 * Derive an own implementation from this interface to supply custom file handling
|
nuclear@0
|
63 * to the importer library. If you implement this interface, you also want to
|
nuclear@0
|
64 * supply a custom implementation for IOStream.
|
nuclear@0
|
65 *
|
nuclear@0
|
66 * @see Importer::SetIOHandler() */
|
nuclear@0
|
67 class ASSIMP_API IOSystem : public Intern::AllocateFromAssimpHeap
|
nuclear@0
|
68 {
|
nuclear@0
|
69 public:
|
nuclear@0
|
70
|
nuclear@0
|
71 // -------------------------------------------------------------------
|
nuclear@0
|
72 /** @brief Default constructor.
|
nuclear@0
|
73 *
|
nuclear@0
|
74 * Create an instance of your derived class and assign it to an
|
nuclear@0
|
75 * #Assimp::Importer instance by calling Importer::SetIOHandler().
|
nuclear@0
|
76 */
|
nuclear@0
|
77 IOSystem();
|
nuclear@0
|
78
|
nuclear@0
|
79 // -------------------------------------------------------------------
|
nuclear@0
|
80 /** @brief Virtual destructor.
|
nuclear@0
|
81 *
|
nuclear@0
|
82 * It is safe to be called from within DLL Assimp, we're constructed
|
nuclear@0
|
83 * on Assimp's heap.
|
nuclear@0
|
84 */
|
nuclear@0
|
85 virtual ~IOSystem();
|
nuclear@0
|
86
|
nuclear@0
|
87
|
nuclear@0
|
88 public:
|
nuclear@0
|
89
|
nuclear@0
|
90 // -------------------------------------------------------------------
|
nuclear@0
|
91 /** @brief For backward compatibility
|
nuclear@0
|
92 * @see Exists(const char*)
|
nuclear@0
|
93 */
|
nuclear@0
|
94 AI_FORCE_INLINE bool Exists( const std::string& pFile) const;
|
nuclear@0
|
95
|
nuclear@0
|
96 // -------------------------------------------------------------------
|
nuclear@0
|
97 /** @brief Tests for the existence of a file at the given path.
|
nuclear@0
|
98 *
|
nuclear@0
|
99 * @param pFile Path to the file
|
nuclear@0
|
100 * @return true if there is a file with this path, else false.
|
nuclear@0
|
101 */
|
nuclear@0
|
102
|
nuclear@0
|
103 virtual bool Exists( const char* pFile) const = 0;
|
nuclear@0
|
104
|
nuclear@0
|
105
|
nuclear@0
|
106
|
nuclear@0
|
107 // -------------------------------------------------------------------
|
nuclear@0
|
108 /** @brief Returns the system specific directory separator
|
nuclear@0
|
109 * @return System specific directory separator
|
nuclear@0
|
110 */
|
nuclear@0
|
111 virtual char getOsSeparator() const = 0;
|
nuclear@0
|
112
|
nuclear@0
|
113
|
nuclear@0
|
114 // -------------------------------------------------------------------
|
nuclear@0
|
115 /** @brief Open a new file with a given path.
|
nuclear@0
|
116 *
|
nuclear@0
|
117 * When the access to the file is finished, call Close() to release
|
nuclear@0
|
118 * all associated resources (or the virtual dtor of the IOStream).
|
nuclear@0
|
119 *
|
nuclear@0
|
120 * @param pFile Path to the file
|
nuclear@0
|
121 * @param pMode Desired file I/O mode. Required are: "wb", "w", "wt",
|
nuclear@0
|
122 * "rb", "r", "rt".
|
nuclear@0
|
123 *
|
nuclear@0
|
124 * @return New IOStream interface allowing the lib to access
|
nuclear@0
|
125 * the underlying file.
|
nuclear@0
|
126 * @note When implementing this class to provide custom IO handling,
|
nuclear@0
|
127 * you probably have to supply an own implementation of IOStream as well.
|
nuclear@0
|
128 */
|
nuclear@0
|
129 virtual IOStream* Open(const char* pFile,
|
nuclear@0
|
130 const char* pMode = "rb") = 0;
|
nuclear@0
|
131
|
nuclear@0
|
132 // -------------------------------------------------------------------
|
nuclear@0
|
133 /** @brief For backward compatibility
|
nuclear@0
|
134 * @see Open(const char*, const char*)
|
nuclear@0
|
135 */
|
nuclear@0
|
136 inline IOStream* Open(const std::string& pFile,
|
nuclear@0
|
137 const std::string& pMode = std::string("rb"));
|
nuclear@0
|
138
|
nuclear@0
|
139
|
nuclear@0
|
140
|
nuclear@0
|
141 // -------------------------------------------------------------------
|
nuclear@0
|
142 /** @brief Closes the given file and releases all resources
|
nuclear@0
|
143 * associated with it.
|
nuclear@0
|
144 * @param pFile The file instance previously created by Open().
|
nuclear@0
|
145 */
|
nuclear@0
|
146 virtual void Close( IOStream* pFile) = 0;
|
nuclear@0
|
147
|
nuclear@0
|
148 // -------------------------------------------------------------------
|
nuclear@0
|
149 /** @brief Compares two paths and check whether the point to
|
nuclear@0
|
150 * identical files.
|
nuclear@0
|
151 *
|
nuclear@0
|
152 * The dummy implementation of this virtual member performs a
|
nuclear@0
|
153 * case-insensitive comparison of the given strings. The default IO
|
nuclear@0
|
154 * system implementation uses OS mechanisms to convert relative into
|
nuclear@0
|
155 * absolute paths, so the result can be trusted.
|
nuclear@0
|
156 * @param one First file
|
nuclear@0
|
157 * @param second Second file
|
nuclear@0
|
158 * @return true if the paths point to the same file. The file needn't
|
nuclear@0
|
159 * be existing, however.
|
nuclear@0
|
160 */
|
nuclear@0
|
161 virtual bool ComparePaths (const char* one,
|
nuclear@0
|
162 const char* second) const;
|
nuclear@0
|
163
|
nuclear@0
|
164 // -------------------------------------------------------------------
|
nuclear@0
|
165 /** @brief For backward compatibility
|
nuclear@0
|
166 * @see ComparePaths(const char*, const char*)
|
nuclear@0
|
167 */
|
nuclear@0
|
168 inline bool ComparePaths (const std::string& one,
|
nuclear@0
|
169 const std::string& second) const;
|
nuclear@0
|
170 };
|
nuclear@0
|
171
|
nuclear@0
|
172 // ----------------------------------------------------------------------------
|
nuclear@0
|
173 AI_FORCE_INLINE IOSystem::IOSystem()
|
nuclear@0
|
174 {
|
nuclear@0
|
175 // empty
|
nuclear@0
|
176 }
|
nuclear@0
|
177
|
nuclear@0
|
178 // ----------------------------------------------------------------------------
|
nuclear@0
|
179 AI_FORCE_INLINE IOSystem::~IOSystem()
|
nuclear@0
|
180 {
|
nuclear@0
|
181 // empty
|
nuclear@0
|
182 }
|
nuclear@0
|
183
|
nuclear@0
|
184 // ----------------------------------------------------------------------------
|
nuclear@0
|
185 // For compatibility, the interface of some functions taking a std::string was
|
nuclear@0
|
186 // changed to const char* to avoid crashes between binary incompatible STL
|
nuclear@0
|
187 // versions. This code her is inlined, so it shouldn't cause any problems.
|
nuclear@0
|
188 // ----------------------------------------------------------------------------
|
nuclear@0
|
189
|
nuclear@0
|
190 // ----------------------------------------------------------------------------
|
nuclear@0
|
191 AI_FORCE_INLINE IOStream* IOSystem::Open(const std::string& pFile,
|
nuclear@0
|
192 const std::string& pMode)
|
nuclear@0
|
193 {
|
nuclear@0
|
194 // NOTE:
|
nuclear@0
|
195 // For compatibility, interface was changed to const char* to
|
nuclear@0
|
196 // avoid crashes between binary incompatible STL versions
|
nuclear@0
|
197 return Open(pFile.c_str(),pMode.c_str());
|
nuclear@0
|
198 }
|
nuclear@0
|
199
|
nuclear@0
|
200 // ----------------------------------------------------------------------------
|
nuclear@0
|
201 AI_FORCE_INLINE bool IOSystem::Exists( const std::string& pFile) const
|
nuclear@0
|
202 {
|
nuclear@0
|
203 // NOTE:
|
nuclear@0
|
204 // For compatibility, interface was changed to const char* to
|
nuclear@0
|
205 // avoid crashes between binary incompatible STL versions
|
nuclear@0
|
206 return Exists(pFile.c_str());
|
nuclear@0
|
207 }
|
nuclear@0
|
208
|
nuclear@0
|
209 // ----------------------------------------------------------------------------
|
nuclear@0
|
210 inline bool IOSystem::ComparePaths (const std::string& one,
|
nuclear@0
|
211 const std::string& second) const
|
nuclear@0
|
212 {
|
nuclear@0
|
213 // NOTE:
|
nuclear@0
|
214 // For compatibility, interface was changed to const char* to
|
nuclear@0
|
215 // avoid crashes between binary incompatible STL versions
|
nuclear@0
|
216 return ComparePaths(one.c_str(),second.c_str());
|
nuclear@0
|
217 }
|
nuclear@0
|
218
|
nuclear@0
|
219 // ----------------------------------------------------------------------------
|
nuclear@0
|
220 } //!ns Assimp
|
nuclear@0
|
221
|
nuclear@0
|
222 #endif //AI_IOSYSTEM_H_INC
|