ResourceObject.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright (C) 2009-2015, Panagiotis Christopoulos Charitos.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #include "anki/resource/ResourceObject.h"
  6. #include "anki/resource/ResourceManager.h"
  7. #include "anki/misc/Xml.h"
  8. namespace anki {
  9. //==============================================================================
  10. ResourceObject::ResourceObject(ResourceManager* manager)
  11. : m_manager(manager)
  12. , m_refcount(0)
  13. {}
  14. //==============================================================================
  15. ResourceObject::~ResourceObject()
  16. {
  17. m_fname.destroy(getAllocator());
  18. }
  19. //==============================================================================
  20. ResourceAllocator<U8> ResourceObject::getAllocator() const
  21. {
  22. return m_manager->getAllocator();
  23. }
  24. //==============================================================================
  25. TempResourceAllocator<U8> ResourceObject::getTempAllocator() const
  26. {
  27. return m_manager->getTempAllocator();
  28. }
  29. //==============================================================================
  30. Error ResourceObject::openFile(const CString& filename, ResourceFilePtr& file)
  31. {
  32. return m_manager->getFilesystem().openFile(filename, file);
  33. }
  34. //==============================================================================
  35. Error ResourceObject::openFileReadAllText(
  36. const CString& filename,
  37. StringAuto& text)
  38. {
  39. // Load file
  40. ResourceFilePtr file;
  41. ANKI_CHECK(m_manager->getFilesystem().openFile(filename, file));
  42. // Read string
  43. text = std::move(StringAuto(getTempAllocator()));
  44. ANKI_CHECK(file->readAllText(getTempAllocator(), text));
  45. return ErrorCode::NONE;
  46. }
  47. //==============================================================================
  48. Error ResourceObject::openFileParseXml(
  49. const CString& filename,
  50. XmlDocument& xml)
  51. {
  52. StringAuto txt(getTempAllocator());
  53. ANKI_CHECK(openFileReadAllText(filename, txt));
  54. ANKI_CHECK(xml.parse(txt.toCString(), getTempAllocator()));
  55. return ErrorCode::NONE;
  56. }
  57. } // end namespace anki