File.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /**
  2. * Copyright (c) 2006-2009 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. private:
  41. // filename
  42. std::string filename;
  43. // PHYSFS File handle.
  44. PHYSFS_file * file;
  45. // The current mode of the file.
  46. Mode mode;
  47. public:
  48. /**
  49. * Constructs an File with the given source and filename.
  50. * @param source The source from which to load the file. (Archive or directory)
  51. * @param filename The relative filepath of the file to load from the source.
  52. **/
  53. File(std::string filename);
  54. virtual ~File();
  55. // Implements love::filesystem::File.
  56. bool open(Mode mode);
  57. bool close();
  58. unsigned int getSize();
  59. Data * read(int size = ALL);
  60. int read(void * dst, int size);
  61. bool write(const void * data, int size);
  62. bool write(const Data * data, int size = ALL);
  63. bool eof();
  64. int tell();
  65. bool seek(int pos);
  66. Mode getMode();
  67. std::string getFilename() const;
  68. std::string getExtension() const;
  69. }; // File
  70. } // physfs
  71. } // filesystem
  72. } // love
  73. #endif // LOVE_FILESYSTEM_PHYSFS_FILE_H