ResourceObject.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
  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/Util/Xml.h>
  8. namespace anki {
  9. ResourceObject::ResourceObject(ResourceManager* manager)
  10. : m_manager(manager)
  11. , m_refcount(0)
  12. {
  13. }
  14. ResourceObject::~ResourceObject()
  15. {
  16. m_fname.destroy(getAllocator());
  17. }
  18. ResourceAllocator<U8> ResourceObject::getAllocator() const
  19. {
  20. return m_manager->getAllocator();
  21. }
  22. TempResourceAllocator<U8> ResourceObject::getTempAllocator() const
  23. {
  24. return m_manager->getTempAllocator();
  25. }
  26. Error ResourceObject::openFile(const CString& filename, ResourceFilePtr& file)
  27. {
  28. return m_manager->getFilesystem().openFile(filename, file);
  29. }
  30. Error ResourceObject::openFileReadAllText(const CString& filename, StringAuto& text)
  31. {
  32. // Load file
  33. ResourceFilePtr file;
  34. ANKI_CHECK(m_manager->getFilesystem().openFile(filename, file));
  35. // Read string
  36. text = StringAuto(getTempAllocator());
  37. ANKI_CHECK(file->readAllText(text));
  38. return Error::NONE;
  39. }
  40. Error ResourceObject::openFileParseXml(const CString& filename, XmlDocument& xml)
  41. {
  42. StringAuto txt(getTempAllocator());
  43. ANKI_CHECK(openFileReadAllText(filename, txt));
  44. ANKI_CHECK(xml.parse(txt.toCString(), getTempAllocator()));
  45. return Error::NONE;
  46. }
  47. } // end namespace anki