| 224 | } |
| 225 | |
| 226 | void 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 | |
| 273 | LayoutBase::LayoutBase() : |
| 274 | initResult(Result::ok()) |
no test coverage detected