CProperty.cpp 1.2 KB

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