CObject.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #pragma once
  2. #include <string>
  3. #include "WallpaperEngine/Render/Helpers/ContextAware.h"
  4. #include "WallpaperEngine/Render/Wallpapers/CScene.h"
  5. namespace WallpaperEngine::Render::Wallpapers {
  6. class CScene;
  7. }
  8. namespace WallpaperEngine::Render {
  9. class CObject : public Helpers::ContextAware {
  10. public:
  11. template <class T> [[nodiscard]] const T* as () const {
  12. if (is<T> ()) {
  13. return static_cast<const T*> (this);
  14. }
  15. throw std::bad_cast ();
  16. }
  17. template <class T> [[nodiscard]] T* as () {
  18. if (is<T> ()) {
  19. return static_cast<T*> (this);
  20. }
  21. throw std::bad_cast ();
  22. }
  23. template <class T> [[nodiscard]] bool is () const { return typeid (*this) == typeid (T); }
  24. virtual void render () = 0;
  25. [[nodiscard]] Wallpapers::CScene& getScene () const;
  26. [[nodiscard]] const AssetLocator& getAssetLocator () const;
  27. [[nodiscard]] int getId () const;
  28. virtual ~CObject () override = default;
  29. protected:
  30. CObject (Wallpapers::CScene& scene, const Object& object);
  31. private:
  32. Wallpapers::CScene& m_scene;
  33. const Object& m_object;
  34. };
  35. } // namespace WallpaperEngine::Render