FileData.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /**
  2. * Copyright (c) 2006-2015 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. #include "FileData.h"
  21. // C++
  22. #include <iostream>
  23. #include <limits>
  24. namespace love
  25. {
  26. namespace filesystem
  27. {
  28. FileData::FileData(uint64 size, const std::string &filename)
  29. : data(new char[(size_t) size])
  30. , size((size_t) size)
  31. , filename(filename)
  32. {
  33. if (filename.rfind('.') != std::string::npos)
  34. extension = filename.substr(filename.rfind('.')+1);
  35. }
  36. FileData::~FileData()
  37. {
  38. delete [] data;
  39. }
  40. void *FileData::getData() const
  41. {
  42. return (void *)data;
  43. }
  44. size_t FileData::getSize() const
  45. {
  46. size_t sizemax = std::numeric_limits<size_t>::max();
  47. return size > sizemax ? sizemax : (size_t) size;
  48. }
  49. const std::string &FileData::getFilename() const
  50. {
  51. return filename;
  52. }
  53. const std::string &FileData::getExtension() const
  54. {
  55. return extension;
  56. }
  57. bool FileData::getConstant(const char *in, Decoder &out)
  58. {
  59. return decoders.find(in, out);
  60. }
  61. bool FileData::getConstant(Decoder in, const char *&out)
  62. {
  63. return decoders.find(in, out);
  64. }
  65. StringMap<FileData::Decoder, FileData::DECODE_MAX_ENUM>::Entry FileData::decoderEntries[] =
  66. {
  67. {"file", FileData::FILE},
  68. {"base64", FileData::BASE64},
  69. };
  70. StringMap<FileData::Decoder, FileData::DECODE_MAX_ENUM> FileData::decoders(FileData::decoderEntries, sizeof(FileData::decoderEntries));
  71. } // filesystem
  72. } // love