Reads the fields of the struct from native memory
()
| 585 | * Reads the fields of the struct from native memory |
| 586 | */ |
| 587 | public void read() { |
| 588 | // Avoid reading from a null pointer |
| 589 | if (memory == PLACEHOLDER_MEMORY) { |
| 590 | return; |
| 591 | } |
| 592 | readCalled = true; |
| 593 | |
| 594 | // convenience: allocate memory and/or calculate size if it hasn't |
| 595 | // been already; this allows structures to do field-based |
| 596 | // initialization of arrays and not have to explicitly call |
| 597 | // allocateMemory in a ctor |
| 598 | ensureAllocated(); |
| 599 | |
| 600 | // Avoid redundant reads |
| 601 | if (!busy().add(this)) { |
| 602 | return; |
| 603 | } |
| 604 | if (this instanceof Structure.ByReference) { |
| 605 | reading().put(getPointer(), this); |
| 606 | } |
| 607 | try { |
| 608 | for (StructField structField : fields().values()) { |
| 609 | readField(structField); |
| 610 | } |
| 611 | } |
| 612 | finally { |
| 613 | busy().remove(this); |
| 614 | if (this instanceof Structure.ByReference && reading().get(getPointer()) == this) { |
| 615 | reading().remove(getPointer()); |
| 616 | } |
| 617 | } |
| 618 | } |
| 619 | |
| 620 | /** Returns the calculated offset of the given field. |
| 621 | * @param name field to examine |
no test coverage detected