2
0

ResourceObject.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. #pragma once
  6. #include <AnKi/Resource/Common.h>
  7. #include <AnKi/Resource/ResourceFilesystem.h>
  8. #include <AnKi/Util/Atomic.h>
  9. #include <AnKi/Util/String.h>
  10. namespace anki
  11. {
  12. // Forward
  13. class XmlDocument;
  14. /// @addtogroup resource
  15. /// @{
  16. /// The base of all resource objects.
  17. class ResourceObject
  18. {
  19. friend class ResourceManager;
  20. public:
  21. ResourceObject(ResourceManager* manager);
  22. virtual ~ResourceObject();
  23. /// @privatesection
  24. ResourceManager& getManager() const
  25. {
  26. return *m_manager;
  27. }
  28. ResourceAllocator<U8> getAllocator() const;
  29. TempResourceAllocator<U8> getTempAllocator() const;
  30. Atomic<I32>& getRefcount()
  31. {
  32. return m_refcount;
  33. }
  34. const Atomic<I32>& getRefcount() const
  35. {
  36. return m_refcount;
  37. }
  38. CString getFilename() const
  39. {
  40. ANKI_ASSERT(!m_fname.isEmpty());
  41. return m_fname.toCString();
  42. }
  43. // Internals:
  44. ANKI_INTERNAL void setFilename(const CString& fname)
  45. {
  46. ANKI_ASSERT(m_fname.isEmpty());
  47. m_fname.create(getAllocator(), fname);
  48. }
  49. ANKI_INTERNAL void setUuid(U64 uuid)
  50. {
  51. ANKI_ASSERT(uuid > 0);
  52. m_uuid = uuid;
  53. }
  54. /// To check if 2 resource pointers are actually the same resource.
  55. ANKI_INTERNAL U64 getUuid() const
  56. {
  57. ANKI_ASSERT(m_uuid > 0);
  58. return m_uuid;
  59. }
  60. ANKI_INTERNAL ANKI_USE_RESULT Error openFile(const ResourceFilename& filename, ResourceFilePtr& file);
  61. ANKI_INTERNAL ANKI_USE_RESULT Error openFileReadAllText(const ResourceFilename& filename, StringAuto& file);
  62. ANKI_INTERNAL ANKI_USE_RESULT Error openFileParseXml(const ResourceFilename& filename, XmlDocument& xml);
  63. private:
  64. ResourceManager* m_manager;
  65. Atomic<I32> m_refcount;
  66. String m_fname; ///< Unique resource name.
  67. U64 m_uuid = 0;
  68. };
  69. /// @}
  70. } // end namespace anki