ResourceObject.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // Copyright (C) 2009-2016, Panagiotis Christopoulos Charitos.
  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()
  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. anki_internal:
  44. void setFilename(const CString& fname)
  45. {
  46. ANKI_ASSERT(m_fname.isEmpty());
  47. m_fname.create(getAllocator(), fname);
  48. }
  49. 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.
  55. U64 getUuid() const
  56. {
  57. ANKI_ASSERT(m_uuid > 0);
  58. return m_uuid;
  59. }
  60. ANKI_USE_RESULT Error openFile(
  61. const ResourceFilename& filename, ResourceFilePtr& file);
  62. ANKI_USE_RESULT Error openFileReadAllText(
  63. const ResourceFilename& filename, StringAuto& file);
  64. ANKI_USE_RESULT Error openFileParseXml(
  65. const ResourceFilename& filename, XmlDocument& xml);
  66. private:
  67. ResourceManager* m_manager;
  68. Atomic<I32> m_refcount;
  69. String m_fname; ///< Unique resource name.
  70. U64 m_uuid = 0;
  71. };
  72. /// @}
  73. } // end namespace anki