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

Method removeValue

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

Source from the content-addressed store, hash-verified

138 }
139}
140
141bool ViewNodeAttribute::removeValue(const AttributeOwner* owner) {
142 if (_hasSingleAttribute) {
143 auto& attributeValue = getSingleAttributeValue();
144 if (attributeValue.owner == owner) {
145 // Deconstruct our single attribute, which will make our ViewNodeAttribute empty
146 _hasSingleAttribute = false;
147 attributeValue.~AttributeValue();
148 return true;
149 } else {
150 return false;
151 }
152 } else if (_hasAttributeCollection) {
153 auto& attributeCollection = getAttributeValueCollection();
154 size_t i = 0;
155
156 for (auto& attributeValue : attributeCollection.values) {
157 if (attributeValue.owner == owner) {
158 // Owner found, erase it from the collection
159
160 attributeCollection.values.erase(attributeCollection.values.begin() + i);
161
162 if (i == attributeCollection.resolvedValueIndex) {
163 // If our owner was the resolved value, update the
164 attributeCollection.updateResolvedValueIndex(getAttributeId());
165 _appliedValueDirty = true;
166
167 return true;
168 } else if (i < attributeCollection.resolvedValueIndex) {
169 attributeCollection.resolvedValueIndex--;
170 }
171
172 return false;
173 }
174
175 i++;
176 }
177
178 // Owner was not found in the collection
179
180 return false;
181 } else {
182 return false;
183 }
184}
185
186void ViewNodeAttribute::replaceValue(const Value& value) {

Callers 2

setAttributeMethod · 0.80

Calls 3

eraseMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected