IOSystem.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. namespace Assimp
  11. {
  12. class IOStream;
  13. // ---------------------------------------------------------------------------
  14. /** Interface to the file system.
  15. *
  16. * Derive an own implementation from this interface to supply custom file handling
  17. * to the importer library. If you implement this interface, you also want to
  18. * supply a custom implementation for IOStream.
  19. */
  20. class IOSystem
  21. {
  22. public:
  23. /** Constructor. Create an instance of your derived class and assign it to
  24. * the #Importer instance by calling Importer::SetIOHandler().
  25. */
  26. IOSystem();
  27. /** Destructor. */
  28. virtual ~IOSystem();
  29. // -------------------------------------------------------------------
  30. /** Tests for the existence of a file at the given path.
  31. *
  32. * @param pFile Path to the file
  33. * @return true if there is a file with this path, else false.
  34. */
  35. virtual bool Exists( const std::string& pFile) const = 0;
  36. // -------------------------------------------------------------------
  37. /** Returns the system specific directory separator
  38. * @return System specific directory separator
  39. */
  40. virtual std::string getOsSeparator() const = 0;
  41. // -------------------------------------------------------------------
  42. /** Open a new file with a given path. When the access to the file is finished,
  43. * call Close() to release all associated resources.
  44. *
  45. * @param pFile Path to the file
  46. * @param pMode Desired file I/O mode. Required are: "wb", "w", "wt",
  47. * "rb", "r", "rt".
  48. *
  49. * @return New IOStream interface allowing the lib to access
  50. * the underlying file.
  51. * @note When implementing this class to provide custom IO handling, you propably
  52. * have to supply an own implementation of IOStream as well.
  53. */
  54. virtual IOStream* Open(
  55. const std::string& pFile,
  56. const std::string& pMode = std::string("rb")) = 0;
  57. // -------------------------------------------------------------------
  58. /** Closes the given file and releases all resources associated with it.
  59. * @param pFile The file instance previously created by Open().
  60. */
  61. virtual void Close( IOStream* pFile) = 0;
  62. };
  63. // ----------------------------------------------------------------------------
  64. inline IOSystem::IOSystem()
  65. {
  66. // empty
  67. }
  68. // ----------------------------------------------------------------------------
  69. inline IOSystem::~IOSystem()
  70. {
  71. // empty
  72. }
  73. // ----------------------------------------------------------------------------
  74. } //!ns Assimp
  75. #endif //AI_IOSYSTEM_H_INC