IOSystem.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /** @file Filesystem wrapper for C++. Inherit this class to supply custom file handling
  2. * logic to the Import library.
  3. */
  4. #ifndef AI_IOSYSTEM_H_INC
  5. #define AI_IOSYSTEM_H_INC
  6. #ifndef __cplusplus
  7. #error This header requires C++ to be used.
  8. #endif
  9. #include <string>
  10. #include "aiDefines.h"
  11. namespace Assimp
  12. {
  13. class IOStream;
  14. // ---------------------------------------------------------------------------
  15. /** Interface to the file system.
  16. *
  17. * Derive an own implementation from this interface to supply custom file handling
  18. * to the importer library. If you implement this interface, you also want to
  19. * supply a custom implementation for IOStream.
  20. */
  21. class ASSIMP_API IOSystem
  22. {
  23. public:
  24. /** Constructor. Create an instance of your derived class and assign it to
  25. * the #Importer instance by calling Importer::SetIOHandler().
  26. */
  27. IOSystem();
  28. /** Destructor. */
  29. virtual ~IOSystem();
  30. // -------------------------------------------------------------------
  31. /** Tests for the existence of a file at the given path.
  32. *
  33. * @param pFile Path to the file
  34. * @return true if there is a file with this path, else false.
  35. */
  36. virtual bool Exists( const std::string& pFile) const = 0;
  37. // -------------------------------------------------------------------
  38. /** Returns the system specific directory separator
  39. * @return System specific directory separator
  40. */
  41. virtual std::string getOsSeparator() const = 0;
  42. // -------------------------------------------------------------------
  43. /** Open a new file with a given path. When the access to the file
  44. * is finished, call Close() to release all associated resources.
  45. *
  46. * @param pFile Path to the file
  47. * @param pMode Desired file I/O mode. Required are: "wb", "w", "wt",
  48. * "rb", "r", "rt".
  49. *
  50. * @return New IOStream interface allowing the lib to access
  51. * the underlying file.
  52. * @note When implementing this class to provide custom IO handling,
  53. * you propably have to supply an own implementation of IOStream as well.
  54. */
  55. virtual IOStream* Open(
  56. const std::string& pFile,
  57. const std::string& pMode = std::string("rb")) = 0;
  58. // -------------------------------------------------------------------
  59. /** Closes the given file and releases all resources associated with it.
  60. * @param pFile The file instance previously created by Open().
  61. */
  62. virtual void Close( IOStream* pFile) = 0;
  63. // -------------------------------------------------------------------
  64. /** Compares two paths and check whether the point to identical files.
  65. *
  66. * The dummy implementation of this virtual performs a
  67. * case-insensitive comparison of the absolute path strings.
  68. * @param one First file
  69. * @param second Second file
  70. * @return true if the paths point to the same file. The file needn't
  71. * be existing, however.
  72. */
  73. virtual bool ComparePaths (const std::string& one,
  74. const std::string& second);
  75. };
  76. // ----------------------------------------------------------------------------
  77. inline IOSystem::IOSystem()
  78. {
  79. // empty
  80. }
  81. // ----------------------------------------------------------------------------
  82. inline IOSystem::~IOSystem()
  83. {
  84. // empty
  85. }
  86. // ----------------------------------------------------------------------------
  87. } //!ns Assimp
  88. #endif //AI_IOSYSTEM_H_INC