IOStream.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /** @file File I/O wrappers for C++. Use interfaces instead of function
  2. * pointers to be sure even the silliest men on earth can work with this
  3. */
  4. #ifndef AI_IOSTREAM_H_INC
  5. #define AI_IOSTREAM_H_INC
  6. #include <string>
  7. #include <stddef.h>
  8. #include "aiTypes.h"
  9. #include "aiFileIO.h"
  10. #ifndef __cplusplus
  11. #error This header requires C++ to be used.
  12. #endif
  13. namespace Assimp
  14. {
  15. // ---------------------------------------------------------------------------
  16. /** Class to handle file I/O for C++
  17. *
  18. * Derive an own implementation from this interface to provide custom IO handling
  19. * to the Importer. If you implement this interface, be sure to also provide an
  20. * implementation for IOSystem that creates instances of your custom IO class.
  21. */
  22. // ---------------------------------------------------------------------------
  23. class IOStream
  24. {
  25. protected:
  26. /** Constructor protected, use IOSystem::Open() to create an instance. */
  27. IOStream(void);
  28. public:
  29. // -------------------------------------------------------------------
  30. /** Destructor. Deleting the object closes the underlying file,
  31. * alternatively you may use IOSystem::Close() to release the file.
  32. */
  33. virtual ~IOStream(void);
  34. // -------------------------------------------------------------------
  35. /** Read from the file
  36. *
  37. * See fread() for more details
  38. * This fails for write-only files
  39. */
  40. // -------------------------------------------------------------------
  41. virtual size_t Read(
  42. void* pvBuffer,
  43. size_t pSize,
  44. size_t pCount) = 0;
  45. // -------------------------------------------------------------------
  46. /** Write to the file
  47. *
  48. * See fwrite() for more details
  49. * This fails for read-only files
  50. */
  51. // -------------------------------------------------------------------
  52. virtual size_t Write(
  53. const void* pvBuffer,
  54. size_t pSize,
  55. size_t pCount) = 0;
  56. // -------------------------------------------------------------------
  57. /** Set the read/write cursor of the file
  58. *
  59. * See fseek() for more details
  60. */
  61. // -------------------------------------------------------------------
  62. virtual aiReturn Seek(
  63. size_t pOffset,
  64. aiOrigin pOrigin) = 0;
  65. // -------------------------------------------------------------------
  66. /** Get the current position of the read/write cursor
  67. *
  68. * See ftell() for more details
  69. */
  70. // -------------------------------------------------------------------
  71. virtual size_t Tell(void) const = 0;
  72. // -------------------------------------------------------------------
  73. /** Returns filesize
  74. *
  75. * Returns the filesize
  76. */
  77. // -------------------------------------------------------------------
  78. virtual size_t FileSize() const = 0;
  79. };
  80. // ----------------------------------------------------------------------------
  81. inline IOStream::IOStream()
  82. {
  83. // empty
  84. }
  85. // ----------------------------------------------------------------------------
  86. inline IOStream::~IOStream()
  87. {
  88. // empty
  89. }
  90. // ----------------------------------------------------------------------------
  91. } //!ns Assimp
  92. #endif //!!AI_IOSTREAM_H_INC