Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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 IOSystem.h
  35. * @brief File system wrapper for C++. Inherit this class to supply
  36. * custom file handling logic to the Import library.
  37. */
  38. #ifndef AI_IOSYSTEM_H_INC
  39. #define AI_IOSYSTEM_H_INC
  40. #ifndef __cplusplus
  41. # error This header requires C++ to be used. aiFileIO.h is the \
  42. corresponding C interface.
  43. #endif
  44. #include "types.h"
  45. namespace Assimp {
  46. class IOStream;
  47. // ---------------------------------------------------------------------------
  48. /** @brief CPP-API: Interface to the file system.
  49. *
  50. * Derive an own implementation from this interface to supply custom file handling
  51. * to the importer library. If you implement this interface, you also want to
  52. * supply a custom implementation for IOStream.
  53. *
  54. * @see Importer::SetIOHandler() */
  55. class ASSIMP_API IOSystem
  56. #ifndef SWIG
  57. : public Intern::AllocateFromAssimpHeap
  58. #endif
  59. {
  60. public:
  61. // -------------------------------------------------------------------
  62. /** @brief Default constructor.
  63. *
  64. * Create an instance of your derived class and assign it to an
  65. * #Assimp::Importer instance by calling Importer::SetIOHandler().
  66. */
  67. IOSystem();
  68. // -------------------------------------------------------------------
  69. /** @brief Virtual destructor.
  70. *
  71. * It is safe to be called from within DLL Assimp, we're constructed
  72. * on Assimp's heap.
  73. */
  74. virtual ~IOSystem();
  75. public:
  76. // -------------------------------------------------------------------
  77. /** @brief For backward compatibility
  78. * @see Exists(const char*)
  79. */
  80. AI_FORCE_INLINE bool Exists( const std::string& pFile) const;
  81. // -------------------------------------------------------------------
  82. /** @brief Tests for the existence of a file at the given path.
  83. *
  84. * @param pFile Path to the file
  85. * @return true if there is a file with this path, else false.
  86. */
  87. virtual bool Exists( const char* pFile) const = 0;
  88. // -------------------------------------------------------------------
  89. /** @brief Returns the system specific directory separator
  90. * @return System specific directory separator
  91. */
  92. virtual char getOsSeparator() const = 0;
  93. // -------------------------------------------------------------------
  94. /** @brief Open a new file with a given path.
  95. *
  96. * When the access to the file is finished, call Close() to release
  97. * all associated resources (or the virtual dtor of the IOStream).
  98. *
  99. * @param pFile Path to the file
  100. * @param pMode Desired file I/O mode. Required are: "wb", "w", "wt",
  101. * "rb", "r", "rt".
  102. *
  103. * @return New IOStream interface allowing the lib to access
  104. * the underlying file.
  105. * @note When implementing this class to provide custom IO handling,
  106. * you probably have to supply an own implementation of IOStream as well.
  107. */
  108. virtual IOStream* Open(const char* pFile,
  109. const char* pMode = "rb") = 0;
  110. // -------------------------------------------------------------------
  111. /** @brief For backward compatibility
  112. * @see Open(const char*, const char*)
  113. */
  114. inline IOStream* Open(const std::string& pFile,
  115. const std::string& pMode = std::string("rb"));
  116. // -------------------------------------------------------------------
  117. /** @brief Closes the given file and releases all resources
  118. * associated with it.
  119. * @param pFile The file instance previously created by Open().
  120. */
  121. virtual void Close( IOStream* pFile) = 0;
  122. // -------------------------------------------------------------------
  123. /** @brief Compares two paths and check whether the point to
  124. * identical files.
  125. *
  126. * The dummy implementation of this virtual member performs a
  127. * case-insensitive comparison of the given strings. The default IO
  128. * system implementation uses OS mechanisms to convert relative into
  129. * absolute paths, so the result can be trusted.
  130. * @param one First file
  131. * @param second Second file
  132. * @return true if the paths point to the same file. The file needn't
  133. * be existing, however.
  134. */
  135. virtual bool ComparePaths (const char* one,
  136. const char* second) const;
  137. // -------------------------------------------------------------------
  138. /** @brief For backward compatibility
  139. * @see ComparePaths(const char*, const char*)
  140. */
  141. inline bool ComparePaths (const std::string& one,
  142. const std::string& second) const;
  143. };
  144. // ----------------------------------------------------------------------------
  145. AI_FORCE_INLINE IOSystem::IOSystem()
  146. {
  147. // empty
  148. }
  149. // ----------------------------------------------------------------------------
  150. AI_FORCE_INLINE IOSystem::~IOSystem()
  151. {
  152. // empty
  153. }
  154. // ----------------------------------------------------------------------------
  155. // For compatibility, the interface of some functions taking a std::string was
  156. // changed to const char* to avoid crashes between binary incompatible STL
  157. // versions. This code her is inlined, so it shouldn't cause any problems.
  158. // ----------------------------------------------------------------------------
  159. // ----------------------------------------------------------------------------
  160. AI_FORCE_INLINE IOStream* IOSystem::Open(const std::string& pFile,
  161. const std::string& pMode)
  162. {
  163. // NOTE:
  164. // For compatibility, interface was changed to const char* to
  165. // avoid crashes between binary incompatible STL versions
  166. return Open(pFile.c_str(),pMode.c_str());
  167. }
  168. // ----------------------------------------------------------------------------
  169. AI_FORCE_INLINE bool IOSystem::Exists( const std::string& pFile) const
  170. {
  171. // NOTE:
  172. // For compatibility, interface was changed to const char* to
  173. // avoid crashes between binary incompatible STL versions
  174. return Exists(pFile.c_str());
  175. }
  176. // ----------------------------------------------------------------------------
  177. inline bool IOSystem::ComparePaths (const std::string& one,
  178. const std::string& second) const
  179. {
  180. // NOTE:
  181. // For compatibility, interface was changed to const char* to
  182. // avoid crashes between binary incompatible STL versions
  183. return ComparePaths(one.c_str(),second.c_str());
  184. }
  185. // ----------------------------------------------------------------------------
  186. } //!ns Assimp
  187. #endif //AI_IOSYSTEM_H_INC