FileData.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /**
  2. * Copyright (c) 2006-2016 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_FILE_DATA_H
  21. #define LOVE_FILESYSTEM_FILE_DATA_H
  22. // LOVE
  23. #include <string>
  24. #include "common/Data.h"
  25. #include "common/StringMap.h"
  26. #include "common/int.h"
  27. namespace love
  28. {
  29. namespace filesystem
  30. {
  31. class FileData : public Data
  32. {
  33. public:
  34. enum Decoder
  35. {
  36. FILE,
  37. BASE64,
  38. DECODE_MAX_ENUM
  39. }; // Decoder
  40. FileData(uint64 size, const std::string &filename);
  41. virtual ~FileData();
  42. // Implements Data.
  43. void *getData() const;
  44. size_t getSize() const;
  45. const std::string &getFilename() const;
  46. const std::string &getExtension() const;
  47. static bool getConstant(const char *in, Decoder &out);
  48. static bool getConstant(Decoder in, const char *&out);
  49. private:
  50. // The actual data.
  51. char *data;
  52. // Size of the data.
  53. uint64 size;
  54. // The filename used for error purposes.
  55. std::string filename;
  56. // The extension (without dot). Used to identify file type.
  57. std::string extension;
  58. static StringMap<Decoder, DECODE_MAX_ENUM>::Entry decoderEntries[];
  59. static StringMap<Decoder, DECODE_MAX_ENUM> decoders;
  60. }; // FileData
  61. } // filesystem
  62. } // love
  63. #endif // LOVE_FILESYSTEM_FILE_DATA_H