CShaderConstant.h 998 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #pragma once
  2. #include <cassert>
  3. #include <string>
  4. #include "WallpaperEngine/Core/DynamicValues/CDynamicValue.h"
  5. namespace WallpaperEngine::Core::Objects::Effects::Constants {
  6. /**
  7. * Shader constants base class
  8. */
  9. class CShaderConstant : public DynamicValues::CDynamicValue {
  10. public:
  11. virtual ~CShaderConstant () = default;
  12. template <class T> [[nodiscard]] const T* as () const {
  13. if (is <T> ()) {
  14. return static_cast <const T*> (this);
  15. }
  16. throw std::bad_cast ();
  17. }
  18. template <class T> [[nodiscard]] T* as () {
  19. if (is <T> ()) {
  20. return static_cast <T*> (this);
  21. }
  22. throw std::bad_cast ();
  23. }
  24. template <class T> [[nodiscard]] bool is () const {
  25. return typeid (*this) == typeid(T);
  26. }
  27. /**
  28. * @return String representation of the constant's value
  29. */
  30. [[nodiscard]] virtual std::string toString () const = 0;
  31. };
  32. } // namespace WallpaperEngine::Core::Objects::Effects::Constants