TextList runtime
This commit is contained in:
parent
ff4b6fb5db
commit
fcda75e732
4 changed files with 103 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
||||||
package org.capnproto;
|
package org.capnproto;
|
||||||
|
|
||||||
final class Constants {
|
final class Constants {
|
||||||
|
public static final int BITS_PER_BYTE = 8;
|
||||||
public static final int BITS_PER_POINTER = 64;
|
public static final int BITS_PER_POINTER = 64;
|
||||||
public static final int BITS_PER_WORD = 64;
|
public static final int BITS_PER_WORD = 64;
|
||||||
public static final int BYTES_PER_WORD = 8;
|
public static final int BYTES_PER_WORD = 8;
|
||||||
|
|
|
@ -37,4 +37,10 @@ public final class ListBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public final PointerBuilder getPointerElement(int index) {
|
||||||
|
return new PointerBuilder(
|
||||||
|
this.segment,
|
||||||
|
(this.ptr + (index * this.step / Constants.BITS_PER_BYTE)) / Constants.BYTES_PER_WORD);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,4 +48,10 @@ public final class ListReader {
|
||||||
return new StructReader(this.segment, structData, structPointers / 8, this.structDataSize,
|
return new StructReader(this.segment, structData, structPointers / 8, this.structDataSize,
|
||||||
this.structPointerCount, (byte) (indexBit % 8), this.nestingLimit - 1);
|
this.structPointerCount, (byte) (indexBit % 8), this.nestingLimit - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PointerReader getPointerElement(int index) {
|
||||||
|
return new PointerReader(this.segment,
|
||||||
|
(this.ptr + (index * this.step / Constants.BITS_PER_BYTE)) / Constants.BYTES_PER_WORD,
|
||||||
|
this.nestingLimit);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
90
runtime/src/main/java/org/capnproto/TextList.java
Normal file
90
runtime/src/main/java/org/capnproto/TextList.java
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
package org.capnproto;
|
||||||
|
|
||||||
|
public final class TextList {
|
||||||
|
public static final class Reader implements Iterable<Text.Reader> {
|
||||||
|
public final ListReader reader;
|
||||||
|
|
||||||
|
public Reader(ListReader reader) {
|
||||||
|
this.reader = reader;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int size() {
|
||||||
|
return this.reader.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Text.Reader get(int index) {
|
||||||
|
return this.reader.getPointerElement(index).getText();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public final class Iterator implements java.util.Iterator<Text.Reader> {
|
||||||
|
public Reader list;
|
||||||
|
public int idx = 0;
|
||||||
|
public Iterator(Reader list) {
|
||||||
|
this.list = list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Text.Reader next() {
|
||||||
|
return this.list.reader.getPointerElement(idx++).getText();
|
||||||
|
}
|
||||||
|
public boolean hasNext() {
|
||||||
|
return idx < list.size();
|
||||||
|
}
|
||||||
|
public void remove() {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public java.util.Iterator<Text.Reader> iterator() {
|
||||||
|
return new Iterator(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class Builder implements Iterable<Text.Builder> {
|
||||||
|
public final ListBuilder builder;
|
||||||
|
|
||||||
|
public Builder(ListBuilder builder) {
|
||||||
|
this.builder = builder;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
// init
|
||||||
|
Builder(PointerBuilder builder, int size) {
|
||||||
|
this.builder = builder.initStructList(size, factory.structSize());
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
public int size() {
|
||||||
|
return this.builder.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public final Text.Builder get(int index) {
|
||||||
|
return this.builder.getPointerElement(index).getText();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public final class Iterator implements java.util.Iterator<Text.Builder> {
|
||||||
|
public Builder list;
|
||||||
|
public int idx = 0;
|
||||||
|
public Iterator(Builder list) {
|
||||||
|
this.list = list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Text.Builder next() {
|
||||||
|
return this.list.builder.getPointerElement(idx++).getText();
|
||||||
|
}
|
||||||
|
public boolean hasNext() {
|
||||||
|
return this.idx < this.list.size();
|
||||||
|
}
|
||||||
|
public void remove() {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public java.util.Iterator<Text.Builder> iterator() {
|
||||||
|
return new Iterator(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue