MCPcopy Create free account
hub / github.com/Snapchat/Valdi / setValue

Method setValue

valdi/src/valdi/runtime/Attributes/ViewNodeAttribute.cpp:54–138  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52 }
53}
54
55bool ViewNodeAttribute::setValue(const AttributeOwner* owner, const Value& value) {
56 if (_hasSingleAttribute) {
57 auto& attributeValue = getSingleAttributeValue();
58
59 if (attributeValue.owner == owner) {
60 // We have a single attribute matching the given owner
61
62 if (attributeValue.value == value) {
63 // Value is the same, nothing has changed
64 return false;
65 } else {
66 // Value has changed
67 attributeValue.value = value;
68 attributeValue.preprocessedValue = Result<PreprocessedValue>();
69
70 _appliedValueDirty = true;
71 return true;
72 }
73 } else {
74 // Our single attribute's owner doesn't match the given owner
75 // We need to turn our single attribute into attribute collection
76 // to fit the new owner
77
78 auto attributeValueCopy = attributeValue;
79 attributeValue.~AttributeValue();
80
81 _hasSingleAttribute = false;
82
83 *reinterpret_cast<AttributeValueCollection**>(&_valuesUnion) = new AttributeValueCollection();
84 _hasAttributeCollection = true;
85
86 auto& attributeCollection = getAttributeValueCollection();
87 auto& inserted =
88 attributeCollection.values.emplace_back(attributeValueCopy.owner, Value(attributeValueCopy.value));
89 inserted.preprocessedValue = std::move(attributeValueCopy.preprocessedValue);
90
91 // Try again now that we have an attribute collection
92 return setValue(owner, value);
93 }
94 } else if (_hasAttributeCollection) {
95 auto& attributeCollection = getAttributeValueCollection();
96
97 size_t i = 0;
98 for (auto& attributeValue : attributeCollection.values) {
99 if (attributeValue.owner == owner) {
100 // Found existing value for owner
101
102 if (attributeValue.value == value) {
103 // Value is the same, nothing has changed
104 return false;
105 } else {
106 attributeValue.value = value;
107 attributeValue.preprocessedValue = Result<PreprocessedValue>();
108
109 if (attributeCollection.resolvedValueIndex == i) {
110 // Value has changed and is currently being used
111 _appliedValueDirty = true;

Callers 5

setAttributeMethod · 0.45
setContentMethod · 0.45

Calls 3

setValueFunction · 0.85
ValueClass · 0.50

Tested by

no test coverage detected