ResourceObject.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. {
  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. ResourceAllocator<U8> ResourceObject::getAllocator() const
  20. {
  21. return m_manager->getAllocator();
  22. }
  23. TempResourceAllocator<U8> ResourceObject::getTempAllocator() const
  24. {
  25. return m_manager->getTempAllocator();
  26. }
  27. Error ResourceObject::openFile(const CString& filename, ResourceFilePtr& file)
  28. {
  29. return m_manager->getFilesystem().openFile(filename, file);
  30. }
  31. Error ResourceObject::openFileReadAllText(const CString& filename, StringAuto& text)
  32. {
  33. // Load file
  34. ResourceFilePtr file;
  35. ANKI_CHECK(m_manager->getFilesystem().openFile(filename, file));
  36. // Read string
  37. text = StringAuto(getTempAllocator());
  38. ANKI_CHECK(file->readAllText(text));
  39. return Error::NONE;
  40. }
  41. Error ResourceObject::openFileParseXml(const CString& filename, XmlDocument& xml)
  42. {
  43. StringAuto txt(getTempAllocator());
  44. ANKI_CHECK(openFileReadAllText(filename, txt));
  45. ANKI_CHECK(xml.parse(txt.toCString(), getTempAllocator()));
  46. return Error::NONE;
  47. }
  48. } // end namespace anki