CProperty.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include "CProperty.h"
  2. #include <utility>
  3. #include "CPropertyColor.h"
  4. namespace WallpaperEngine::Core::Projects
  5. {
  6. CProperty* CProperty::fromJSON (json data, const std::string& name)
  7. {
  8. json::const_iterator type = data.find ("type");
  9. json::const_iterator value = data.find ("value");
  10. json::const_iterator text = data.find ("text");
  11. if (value == data.end ())
  12. {
  13. throw std::runtime_error ("Project properties must have the value field");
  14. }
  15. if (type == data.end ())
  16. {
  17. throw std::runtime_error ("Project properties must have the type field");
  18. }
  19. if (*type == CPropertyColor::Type)
  20. {
  21. return CPropertyColor::fromJSON (data, name);
  22. }
  23. throw std::runtime_error ("Unexpected type for property");
  24. }
  25. CProperty::CProperty (std::string name, std::string type, std::string text) :
  26. m_name (std::move(name)),
  27. m_type (std::move(type)),
  28. m_text (std::move(text))
  29. {
  30. }
  31. std::string& CProperty::getName ()
  32. {
  33. return this->m_name;
  34. }
  35. std::string& CProperty::getType ()
  36. {
  37. return this->m_type;
  38. }
  39. std::string& CProperty::getText ()
  40. {
  41. return this->m_text;
  42. }
  43. };