vrshoot

view libs/assimp/assimp/IOSystem.hpp @ 0:b2f14e535253

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 01 Feb 2014 19:58:19 +0200
parents
children
line source
1 /*
2 ---------------------------------------------------------------------------
3 Open Asset Import Library (assimp)
4 ---------------------------------------------------------------------------
6 Copyright (c) 2006-2012, assimp team
8 All rights reserved.
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:
14 * Redistributions of source code must retain the above
15 copyright notice, this list of conditions and the
16 following disclaimer.
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.
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 team.
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 */
42 /** @file IOSystem.h
43 * @brief File system wrapper for C++. Inherit this class to supply
44 * custom file handling logic to the Import library.
45 */
47 #ifndef AI_IOSYSTEM_H_INC
48 #define AI_IOSYSTEM_H_INC
50 #ifndef __cplusplus
51 # error This header requires C++ to be used. aiFileIO.h is the \
52 corresponding C interface.
53 #endif
55 #include "types.h"
56 namespace Assimp {
57 class IOStream;
59 // ---------------------------------------------------------------------------
60 /** @brief CPP-API: Interface to the file system.
61 *
62 * Derive an own implementation from this interface to supply custom file handling
63 * to the importer library. If you implement this interface, you also want to
64 * supply a custom implementation for IOStream.
65 *
66 * @see Importer::SetIOHandler() */
67 class ASSIMP_API IOSystem : public Intern::AllocateFromAssimpHeap
68 {
69 public:
71 // -------------------------------------------------------------------
72 /** @brief Default constructor.
73 *
74 * Create an instance of your derived class and assign it to an
75 * #Assimp::Importer instance by calling Importer::SetIOHandler().
76 */
77 IOSystem();
79 // -------------------------------------------------------------------
80 /** @brief Virtual destructor.
81 *
82 * It is safe to be called from within DLL Assimp, we're constructed
83 * on Assimp's heap.
84 */
85 virtual ~IOSystem();
88 public:
90 // -------------------------------------------------------------------
91 /** @brief For backward compatibility
92 * @see Exists(const char*)
93 */
94 AI_FORCE_INLINE bool Exists( const std::string& pFile) const;
96 // -------------------------------------------------------------------
97 /** @brief Tests for the existence of a file at the given path.
98 *
99 * @param pFile Path to the file
100 * @return true if there is a file with this path, else false.
101 */
103 virtual bool Exists( const char* pFile) const = 0;
107 // -------------------------------------------------------------------
108 /** @brief Returns the system specific directory separator
109 * @return System specific directory separator
110 */
111 virtual char getOsSeparator() const = 0;
114 // -------------------------------------------------------------------
115 /** @brief Open a new file with a given path.
116 *
117 * When the access to the file is finished, call Close() to release
118 * all associated resources (or the virtual dtor of the IOStream).
119 *
120 * @param pFile Path to the file
121 * @param pMode Desired file I/O mode. Required are: "wb", "w", "wt",
122 * "rb", "r", "rt".
123 *
124 * @return New IOStream interface allowing the lib to access
125 * the underlying file.
126 * @note When implementing this class to provide custom IO handling,
127 * you probably have to supply an own implementation of IOStream as well.
128 */
129 virtual IOStream* Open(const char* pFile,
130 const char* pMode = "rb") = 0;
132 // -------------------------------------------------------------------
133 /** @brief For backward compatibility
134 * @see Open(const char*, const char*)
135 */
136 inline IOStream* Open(const std::string& pFile,
137 const std::string& pMode = std::string("rb"));
141 // -------------------------------------------------------------------
142 /** @brief Closes the given file and releases all resources
143 * associated with it.
144 * @param pFile The file instance previously created by Open().
145 */
146 virtual void Close( IOStream* pFile) = 0;
148 // -------------------------------------------------------------------
149 /** @brief Compares two paths and check whether the point to
150 * identical files.
151 *
152 * The dummy implementation of this virtual member performs a
153 * case-insensitive comparison of the given strings. The default IO
154 * system implementation uses OS mechanisms to convert relative into
155 * absolute paths, so the result can be trusted.
156 * @param one First file
157 * @param second Second file
158 * @return true if the paths point to the same file. The file needn't
159 * be existing, however.
160 */
161 virtual bool ComparePaths (const char* one,
162 const char* second) const;
164 // -------------------------------------------------------------------
165 /** @brief For backward compatibility
166 * @see ComparePaths(const char*, const char*)
167 */
168 inline bool ComparePaths (const std::string& one,
169 const std::string& second) const;
170 };
172 // ----------------------------------------------------------------------------
173 AI_FORCE_INLINE IOSystem::IOSystem()
174 {
175 // empty
176 }
178 // ----------------------------------------------------------------------------
179 AI_FORCE_INLINE IOSystem::~IOSystem()
180 {
181 // empty
182 }
184 // ----------------------------------------------------------------------------
185 // For compatibility, the interface of some functions taking a std::string was
186 // changed to const char* to avoid crashes between binary incompatible STL
187 // versions. This code her is inlined, so it shouldn't cause any problems.
188 // ----------------------------------------------------------------------------
190 // ----------------------------------------------------------------------------
191 AI_FORCE_INLINE IOStream* IOSystem::Open(const std::string& pFile,
192 const std::string& pMode)
193 {
194 // NOTE:
195 // For compatibility, interface was changed to const char* to
196 // avoid crashes between binary incompatible STL versions
197 return Open(pFile.c_str(),pMode.c_str());
198 }
200 // ----------------------------------------------------------------------------
201 AI_FORCE_INLINE bool IOSystem::Exists( const std::string& pFile) const
202 {
203 // NOTE:
204 // For compatibility, interface was changed to const char* to
205 // avoid crashes between binary incompatible STL versions
206 return Exists(pFile.c_str());
207 }
209 // ----------------------------------------------------------------------------
210 inline bool IOSystem::ComparePaths (const std::string& one,
211 const std::string& second) const
212 {
213 // NOTE:
214 // For compatibility, interface was changed to const char* to
215 // avoid crashes between binary incompatible STL versions
216 return ComparePaths(one.c_str(),second.c_str());
217 }
219 // ----------------------------------------------------------------------------
220 } //!ns Assimp
222 #endif //AI_IOSYSTEM_H_INC