File.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /**
  2. * Copyright (c) 2006-2013 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 "filesystem/File.h"
  24. // PhysFS
  25. #ifdef LOVE_MACOSX // wacky Mac behavior means different #include syntax!
  26. #include <physfs/physfs.h>
  27. #else
  28. #include <physfs.h>
  29. #endif
  30. // STD
  31. #include <string>
  32. namespace love
  33. {
  34. namespace filesystem
  35. {
  36. namespace physfs
  37. {
  38. class File : public love::filesystem::File
  39. {
  40. public:
  41. /**
  42. * Constructs an File with the given source and filename.
  43. * @param source The source from which to load the file. (Archive or directory)
  44. * @param filename The relative filepath of the file to load from the source.
  45. **/
  46. File(const std::string &filename);
  47. virtual ~File();
  48. // Implements love::filesystem::File.
  49. bool open(Mode mode);
  50. bool close();
  51. bool isOpen() const;
  52. int64 getSize();
  53. FileData *read(int64 size = ALL);
  54. int64 read(void *dst, int64 size);
  55. bool write(const void *data, int64 size);
  56. bool write(const Data *data, int64 size = ALL);
  57. bool flush();
  58. bool eof();
  59. int64 tell();
  60. bool seek(uint64 pos);
  61. bool setBuffer(BufferMode bufmode, int64 size);
  62. BufferMode getBuffer(int64 &size) const;
  63. Mode getMode() const;
  64. std::string getFilename() const;
  65. std::string getExtension() const;
  66. private:
  67. // filename
  68. std::string filename;
  69. // PHYSFS File handle.
  70. PHYSFS_File *file;
  71. // The current mode of the file.
  72. Mode mode;
  73. BufferMode bufferMode;
  74. int64 bufferSize;
  75. }; // File
  76. } // physfs
  77. } // filesystem
  78. } // love
  79. #endif // LOVE_FILESYSTEM_PHYSFS_FILE_H