File.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /**
  2. * Copyright (c) 2006-2015 LOVE Development Team
  3. *
  4. * This software is provided 'as-is', without any express or implied
  5. * warranty. In no event will the authors be held liable for any damages
  6. * arising from the use of this software.
  7. *
  8. * Permission is granted to anyone to use this software for any purpose,
  9. * including commercial applications, and to alter it and redistribute it
  10. * freely, subject to the following restrictions:
  11. *
  12. * 1. The origin of this software must not be misrepresented; you must not
  13. * claim that you wrote the original software. If you use this software
  14. * in a product, an acknowledgment in the product documentation would be
  15. * appreciated but is not required.
  16. * 2. Altered source versions must be plainly marked as such, and must not be
  17. * misrepresented as being the original software.
  18. * 3. This notice may not be removed or altered from any source distribution.
  19. **/
  20. #ifndef LOVE_FILESYSTEM_PHYSFS_FILE_H
  21. #define LOVE_FILESYSTEM_PHYSFS_FILE_H
  22. // LOVE
  23. #include "common/config.h"
  24. #include "filesystem/File.h"
  25. // PhysFS
  26. #ifdef LOVE_APPLE_USE_FRAMEWORKS
  27. #include <physfs/physfs.h>
  28. #else
  29. #include <physfs.h>
  30. #endif
  31. // STD
  32. #include <string>
  33. // These platforms always use PhysFS 2.1.
  34. #if (defined(LOVE_IOS) || defined(LOVE_ANDROID)) \
  35. && (PHYSFS_VER_MAJOR == 2 && PHYSFS_VER_MINOR >= 1)
  36. #define LOVE_USE_PHYSFS_2_1
  37. #endif
  38. namespace love
  39. {
  40. namespace filesystem
  41. {
  42. namespace physfs
  43. {
  44. class File : public love::filesystem::File
  45. {
  46. public:
  47. /**
  48. * Constructs an File with the given ilename.
  49. * @param filename The relative filepath of the file to load.
  50. **/
  51. File(const std::string &filename);
  52. virtual ~File();
  53. // Implements love::filesystem::File.
  54. using love::filesystem::File::read;
  55. using love::filesystem::File::write;
  56. bool open(Mode mode) override;
  57. bool close() override;
  58. bool isOpen() const override;
  59. int64 getSize() override;
  60. virtual int64 read(void *dst, int64 size) override;
  61. bool write(const void *data, int64 size) override;
  62. bool flush() override;
  63. bool isEOF() override;
  64. int64 tell() override;
  65. bool seek(uint64 pos) override;
  66. bool setBuffer(BufferMode bufmode, int64 size) override;
  67. BufferMode getBuffer(int64 &size) const override;
  68. Mode getMode() const override;
  69. const std::string &getFilename() const override;
  70. private:
  71. // filename
  72. std::string filename;
  73. // PHYSFS File handle.
  74. PHYSFS_File *file;
  75. // The current mode of the file.
  76. Mode mode;
  77. BufferMode bufferMode;
  78. int64 bufferSize;
  79. }; // File
  80. } // physfs
  81. } // filesystem
  82. } // love
  83. #endif // LOVE_FILESYSTEM_PHYSFS_FILE_H