File.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /**
  2. * Copyright (c) 2006-2022 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. #include "libraries/physfs/physfs.h"
  27. // STD
  28. #include <string>
  29. namespace love
  30. {
  31. namespace filesystem
  32. {
  33. namespace physfs
  34. {
  35. class File : public love::filesystem::File
  36. {
  37. public:
  38. /**
  39. * Constructs an File with the given ilename.
  40. * @param filename The relative filepath of the file to load.
  41. **/
  42. File(const std::string &filename, Mode mode);
  43. virtual ~File();
  44. // Implements Stream.
  45. File *clone() override;
  46. int64 read(void* dst, int64 size) override;
  47. bool write(const void* data, int64 size) override;
  48. bool flush() override;
  49. int64 getSize() override;
  50. bool seek(int64 pos, SeekOrigin origin) override;
  51. int64 tell() override;
  52. // Implements love::filesystem::File.
  53. using love::filesystem::File::read;
  54. using love::filesystem::File::write;
  55. bool open(Mode mode) override;
  56. bool close() override;
  57. bool isOpen() const override;
  58. bool isEOF() override;
  59. bool setBuffer(BufferMode bufmode, int64 size) override;
  60. BufferMode getBuffer(int64 &size) const override;
  61. Mode getMode() const override;
  62. const std::string &getFilename() const override;
  63. private:
  64. File(const File &other);
  65. // filename
  66. std::string filename;
  67. // PHYSFS File handle.
  68. PHYSFS_File *file;
  69. // The current mode of the file.
  70. Mode mode;
  71. BufferMode bufferMode;
  72. int64 bufferSize;
  73. }; // File
  74. } // physfs
  75. } // filesystem
  76. } // love
  77. #endif // LOVE_FILESYSTEM_PHYSFS_FILE_H