File.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /**
  2. * Copyright (c) 2006-2012 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. int64 getSize();
  59. Data *read(int64 size = ALL);
  60. int64 read(void *dst, int64 size);
  61. bool write(const void *data, int64 size);
  62. bool write(const Data *data, int64 size = ALL);
  63. bool eof();
  64. int64 tell();
  65. bool seek(uint64 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