PropertyDictionary.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include "../../Include/RmlUi/Core/PropertyDictionary.h"
  2. #include "../../Include/RmlUi/Core/ID.h"
  3. namespace Rml {
  4. PropertyDictionary::PropertyDictionary() {}
  5. void PropertyDictionary::SetProperty(PropertyId id, const Property& property)
  6. {
  7. RMLUI_ASSERT(id != PropertyId::Invalid);
  8. properties[id] = property;
  9. }
  10. void PropertyDictionary::RemoveProperty(PropertyId id)
  11. {
  12. RMLUI_ASSERT(id != PropertyId::Invalid);
  13. properties.erase(id);
  14. }
  15. const Property* PropertyDictionary::GetProperty(PropertyId id) const
  16. {
  17. PropertyMap::const_iterator iterator = properties.find(id);
  18. if (iterator == properties.end())
  19. return nullptr;
  20. return &(*iterator).second;
  21. }
  22. int PropertyDictionary::GetNumProperties() const
  23. {
  24. return (int)properties.size();
  25. }
  26. const PropertyMap& PropertyDictionary::GetProperties() const
  27. {
  28. return properties;
  29. }
  30. void PropertyDictionary::Import(const PropertyDictionary& other, int property_specificity)
  31. {
  32. for (const auto& pair : other.properties)
  33. {
  34. const PropertyId id = pair.first;
  35. const Property& property = pair.second;
  36. SetProperty(id, property, property_specificity > 0 ? property_specificity : property.specificity);
  37. }
  38. }
  39. void PropertyDictionary::Merge(const PropertyDictionary& other, int specificity_offset)
  40. {
  41. for (const auto& pair : other.properties)
  42. {
  43. const PropertyId id = pair.first;
  44. const Property& property = pair.second;
  45. SetProperty(id, property, property.specificity + specificity_offset);
  46. }
  47. }
  48. void PropertyDictionary::SetSourceOfAllProperties(const SharedPtr<const PropertySource>& property_source)
  49. {
  50. for (auto& p : properties)
  51. p.second.source = property_source;
  52. }
  53. void PropertyDictionary::SetProperty(PropertyId id, const Property& property, int specificity)
  54. {
  55. PropertyMap::iterator iterator = properties.find(id);
  56. if (iterator != properties.end() && iterator->second.specificity > specificity)
  57. return;
  58. Property& new_property = (properties[id] = property);
  59. new_property.specificity = specificity;
  60. }
  61. } // namespace Rml