MCPcopy Create free account
hub / github.com/christophhart/HISE / write

Method write

hi_scripting/scripting/api/FixLayoutObjects.cpp:226–271  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

224}
225
226void LayoutBase::MemoryLayoutItem::write(uint8* dataStart, const var& newValue, Result* r)
227{
228 if (elementSize == 1)
229 {
230 if (newValue.isArray())
231 {
232 if (r != nullptr)
233 *r = Result::fail("Can't write array to single element");
234
235 return;
236 }
237
238 auto ptr = dataStart + offset;
239 jassert(allocator->validMemoryAccess(ptr));
240 Helpers::writeElement(type, ptr, newValue);
241 }
242 else
243 {
244 if (auto ar = newValue.getArray())
245 {
246 auto numElementsToRead = ar->size();
247
248 if (elementSize != numElementsToRead)
249 {
250 if (r != nullptr)
251 *r = Result::fail("array size mismatch. Expected " + String(elementSize));
252
253 return;
254 }
255
256 auto ts = Helpers::getTypeSize(type);
257
258 for (int i = 0; i < numElementsToRead; i++)
259 {
260 auto d = dataStart + offset + i * ts;
261 jassert(allocator->validMemoryAccess(d));
262 Helpers::writeElement(type, d, ar->getUnchecked(i));
263 }
264 }
265 else
266 {
267 if (r != nullptr)
268 *r = Result::fail("This data type requires an array.");
269 }
270 }
271}
272
273LayoutBase::LayoutBase() :
274 initResult(Result::ok())

Callers 1

getBase64DataLayoutMethod · 0.45

Calls 7

getTypeSizeFunction · 0.85
validMemoryAccessMethod · 0.80
StringClass · 0.50
isArrayMethod · 0.45
getArrayMethod · 0.45
sizeMethod · 0.45
getUncheckedMethod · 0.45

Tested by

no test coverage detected