Skip to content

Commit

Permalink
RefDefault
Browse files Browse the repository at this point in the history
  • Loading branch information
dwrensha committed Oct 8, 2014
1 parent 7aead0c commit 2ede424
Show file tree
Hide file tree
Showing 16 changed files with 106 additions and 54 deletions.
2 changes: 1 addition & 1 deletion runtime/src/main/java/org/capnproto/AnyPointer.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public Reader(SegmentReader segment, int pointer, int nestingLimit) {
}

public final <T> T getAs(FromPointerReader<T> factory) {
return factory.fromPointerReader(this.segment, this.pointer, null, 0, this.nestingLimit);
return factory.fromPointerReader(this.segment, this.pointer, this.nestingLimit);
}
}

Expand Down
10 changes: 10 additions & 0 deletions runtime/src/main/java/org/capnproto/Data.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@

public final class Data {
public static final class Factory implements FromPointerReaderBlobDefault<Reader>,
FromPointerReader<Reader>,
FromPointerBuilderBlobDefault<Builder>,
FromPointerBuilder<Builder>,
SetPointerBuilder<Reader>,
InitSizedFromPointerBuilder<Builder> {
public final Reader fromPointerReaderBlobDefault(SegmentReader segment, int pointer, java.nio.ByteBuffer defaultBuffer,
int defaultOffset, int defaultSize) {
return WireHelpers.readDataPointer(segment, pointer, defaultBuffer, defaultOffset, defaultSize);
}
public final Reader fromPointerReader(SegmentReader segment, int pointer, int nestingLimit) {
return WireHelpers.readDataPointer(segment, pointer, null, 0, 0);
}
public final Builder fromPointerBuilderBlobDefault(SegmentBuilder segment, int pointer,
java.nio.ByteBuffer defaultBuffer, int defaultOffset, int defaultSize) {
return WireHelpers.getWritableDataPointer(pointer,
Expand All @@ -19,6 +24,11 @@ public final Builder fromPointerBuilderBlobDefault(SegmentBuilder segment, int p
defaultOffset,
defaultSize);
}
public final Builder fromPointerBuilder(SegmentBuilder segment, int pointer) {
return WireHelpers.getWritableDataPointer(pointer,
segment,
null, 0, 0);
}

public final Builder initSizedFromPointerBuilder(SegmentBuilder segment, int pointer, int size) {
return WireHelpers.initDataPointer(pointer, segment, size);
Expand Down
8 changes: 4 additions & 4 deletions runtime/src/main/java/org/capnproto/DataList.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public Reader(SegmentReader segment,
}

public Data.Reader get(int index) {
return _getPointerElement(Data.factory, index, null, 0, 0);
return _getPointerElement(Data.factory, index);
}

public final class Iterator implements java.util.Iterator<Data.Reader> {
Expand All @@ -41,7 +41,7 @@ public Iterator(Reader list) {
}

public Data.Reader next() {
return _getPointerElement(Data.factory, idx++, null, 0, 0);
return this.list._getPointerElement(Data.factory, idx++);
}
public boolean hasNext() {
return idx < list.size();
Expand All @@ -65,7 +65,7 @@ public Builder(SegmentBuilder segment, int ptr,
}

public final Data.Builder get(int index) {
return _getPointerElement(Data.factory, index, null, 0, 0);
return _getPointerElement(Data.factory, index);
}

public final void set(int index, Data.Reader value) {
Expand All @@ -80,7 +80,7 @@ public Iterator(Builder list) {
}

public Data.Builder next() {
return this.list._getPointerElement(Data.factory, idx++, null, 0, 0);
return this.list._getPointerElement(Data.factory, idx++);
}
public boolean hasNext() {
return this.idx < this.list.size();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package org.capnproto;

public interface FromPointerBuilder<T> {
T fromPointerBuilder(SegmentBuilder segment, int pointer, SegmentReader defaultSegment, int defaultOffset);
T fromPointerBuilder(SegmentBuilder segment, int pointer);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.capnproto;

public interface FromPointerBuilderRefDefault<T> {
T fromPointerBuilderRefDefault(SegmentBuilder segment, int pointer, SegmentReader defaultSegment, int defaultOffset);
}
2 changes: 1 addition & 1 deletion runtime/src/main/java/org/capnproto/FromPointerReader.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package org.capnproto;

public interface FromPointerReader<T> {
T fromPointerReader(SegmentReader segment, int pointer, SegmentReader defaultSegment, int defaultOffset, int nestingLimit);
T fromPointerReader(SegmentReader segment, int pointer, int nestingLimit);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.capnproto;

public interface FromPointerReaderRefDefault<T> {
T fromPointerReaderRefDefault(SegmentReader segment, int pointer, SegmentReader defaultSegment, int defaultOffset, int nestingLimit);
}
14 changes: 2 additions & 12 deletions runtime/src/main/java/org/capnproto/ListBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,12 @@ protected final <T> T _getStructElement(StructBuilder.Factory<T> factory, int in
(byte)(indexBit % 8));
}

protected final <T> T _getPointerElement(FromPointerBuilder<T> factory, int index, SegmentReader defaultSegment, int defaultOffset) {
protected final <T> T _getPointerElement(FromPointerBuilder<T> factory, int index) {
return factory.fromPointerBuilder(
this.segment,
(this.ptr + (index * this.step / Constants.BITS_PER_BYTE)) / Constants.BYTES_PER_WORD,
defaultSegment, defaultOffset);
}

protected final <T> T _getPointerElement(FromPointerBuilderBlobDefault<T> factory, int index,
java.nio.ByteBuffer defaultBuffer, int defaultOffset, int defaultSize) {
return factory.fromPointerBuilderBlobDefault(
this.segment,
(this.ptr + (index * this.step / Constants.BITS_PER_BYTE)) / Constants.BYTES_PER_WORD,
defaultBuffer, defaultOffset, defaultSize);
(this.ptr + (index * this.step / Constants.BITS_PER_BYTE)) / Constants.BYTES_PER_WORD);
}


protected final <T> T _initPointerElement(InitFromPointerBuilder<T> factory, int index) {
return factory.initFromPointerBuilder(
this.segment,
Expand Down
29 changes: 23 additions & 6 deletions runtime/src/main/java/org/capnproto/ListFactory.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
package org.capnproto;

public abstract class ListFactory<Builder, Reader extends ListReader>
implements ListBuilder.Factory<Builder>, FromPointerBuilder<Builder>,
implements ListBuilder.Factory<Builder>,
FromPointerBuilder<Builder>,
FromPointerBuilderRefDefault<Builder>,
InitSizedFromPointerBuilder<Builder>,
SetPointerBuilder<Reader>,
ListReader.Factory<Reader>, FromPointerReader<Reader> {
ListReader.Factory<Reader>,
FromPointerReader<Reader>,
FromPointerReaderRefDefault<Reader> {

final byte elementSize;
ListFactory(byte elementSize) {this.elementSize = elementSize;}

public final Reader fromPointerReader(SegmentReader segment, int pointer,
SegmentReader defaultSegment, int defaultOffset,
int nestingLimit) {
public final Reader fromPointerReaderRefDefault(SegmentReader segment, int pointer,
SegmentReader defaultSegment, int defaultOffset,
int nestingLimit) {
return WireHelpers.readListPointer(this,
segment,
pointer,
Expand All @@ -21,7 +25,12 @@ public final Reader fromPointerReader(SegmentReader segment, int pointer,
nestingLimit);
}

public Builder fromPointerBuilder(SegmentBuilder segment, int pointer, SegmentReader defaultSegment, int defaultOffset) {
public final Reader fromPointerReader(SegmentReader segment, int pointer, int nestingLimit) {
return fromPointerReaderRefDefault(segment, pointer, null, 0, nestingLimit);
}

public Builder fromPointerBuilderRefDefault(SegmentBuilder segment, int pointer,
SegmentReader defaultSegment, int defaultOffset) {
return WireHelpers.getWritableListPointer(this,
pointer,
segment,
Expand All @@ -30,6 +39,14 @@ public Builder fromPointerBuilder(SegmentBuilder segment, int pointer, SegmentRe
defaultOffset);
}

public Builder fromPointerBuilder(SegmentBuilder segment, int pointer) {
return WireHelpers.getWritableListPointer(this,
pointer,
segment,
this.elementSize,
null, 0);
}

public Builder initSizedFromPointerBuilder(SegmentBuilder segment, int pointer, int elementCount) {
return WireHelpers.initListPointer(this, pointer, segment, elementCount, this.elementSize);
}
Expand Down
4 changes: 2 additions & 2 deletions runtime/src/main/java/org/capnproto/ListList.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public Reader(FromPointerReader<T> factory,
}

public T get(int index) {
return _getPointerElement(this.factory, index, null, 0);
return _getPointerElement(this.factory, index);
}

}
Expand All @@ -62,7 +62,7 @@ public final T init(int index, int size) {
}

public final T get(int index) {
return _getPointerElement(this.factory, index, null, 0);
return _getPointerElement(this.factory, index);
}
}
}
4 changes: 1 addition & 3 deletions runtime/src/main/java/org/capnproto/ListReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,9 @@ protected <T> T _getStructElement(StructReader.Factory<T> factory, int index) {
this.structPointerCount, (byte) (indexBit % 8), this.nestingLimit - 1);
}

protected <T> T _getPointerElement(FromPointerReader<T> factory, int index, SegmentReader defaultSegment, int defaultOffset) {
protected <T> T _getPointerElement(FromPointerReader<T> factory, int index) {
return factory.fromPointerReader(this.segment,
(this.ptr + (index * this.step / Constants.BITS_PER_BYTE)) / Constants.BYTES_PER_WORD,
defaultSegment,
defaultOffset,
this.nestingLimit);
}

Expand Down
5 changes: 3 additions & 2 deletions runtime/src/main/java/org/capnproto/StructBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,9 @@ protected final void _clearPointerField(int ptrIndex) {
this.segment.buffer.putLong(pointer * 8, 0L);
}

protected final <T> T _getPointerField(FromPointerBuilder<T> factory, int index, SegmentReader defaultSegment, int defaultOffset) {
return factory.fromPointerBuilder(this.segment, this.pointers + index, defaultSegment, defaultOffset);
protected final <T> T _getPointerField(FromPointerBuilderRefDefault<T> factory, int index,
SegmentReader defaultSegment, int defaultOffset) {
return factory.fromPointerBuilderRefDefault(this.segment, this.pointers + index, defaultSegment, defaultOffset);
}

protected final <T> T _getPointerField(FromPointerBuilderBlobDefault<T> factory, int index,
Expand Down
24 changes: 18 additions & 6 deletions runtime/src/main/java/org/capnproto/StructFactory.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
package org.capnproto;

public abstract class StructFactory<Builder, Reader extends StructReader>
implements FromPointerBuilder<Builder>, StructBuilder.Factory<Builder>,
implements FromPointerBuilder<Builder>,
FromPointerBuilderRefDefault<Builder>,
StructBuilder.Factory<Builder>,
InitFromPointerBuilder<Builder>,
SetPointerBuilder<Reader>,
FromPointerReader<Reader>, StructReader.Factory<Reader> {
public final Reader fromPointerReader(SegmentReader segment, int pointer,
SegmentReader defaultSegment, int defaultOffset,
int nestingLimit) {
FromPointerReader<Reader>,
FromPointerReaderRefDefault<Reader>,
StructReader.Factory<Reader> {
public final Reader fromPointerReaderRefDefault(SegmentReader segment, int pointer,
SegmentReader defaultSegment, int defaultOffset,
int nestingLimit) {
return WireHelpers.readStructPointer(this,
segment,
pointer,
defaultSegment, defaultOffset,
nestingLimit);
}
public final Builder fromPointerBuilder(SegmentBuilder segment, int pointer, SegmentReader defaultSegment, int defaultOffset) {
public final Reader fromPointerReader(SegmentReader segment, int pointer, int nestingLimit) {
return fromPointerReaderRefDefault(segment, pointer, null, 0, nestingLimit);
}
public final Builder fromPointerBuilderRefDefault(SegmentBuilder segment, int pointer,
SegmentReader defaultSegment, int defaultOffset) {
return WireHelpers.getWritableStructPointer(this, pointer, segment, this.structSize(),
defaultSegment, defaultOffset);
}
public final Builder fromPointerBuilder(SegmentBuilder segment, int pointer) {
return WireHelpers.getWritableStructPointer(this, pointer, segment, this.structSize(),
null, 0);
}
public final Builder initFromPointerBuilder(SegmentBuilder segment, int pointer) {
return WireHelpers.initStructPointer(this, pointer, segment, this.structSize());
}
Expand Down
23 changes: 12 additions & 11 deletions runtime/src/main/java/org/capnproto/StructReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,20 @@ protected final boolean _pointerFieldIsNull(int ptrIndex) {
return this.segment.buffer.getLong((this.pointers + ptrIndex) * Constants.BYTES_PER_WORD) == 0;
}

protected final <T> T _getPointerField(FromPointerReader<T> factory, int ptrIndex, SegmentReader defaultSegment, int defaultOffset) {
protected final <T> T _getPointerField(FromPointerReaderRefDefault<T> factory, int ptrIndex,
SegmentReader defaultSegment, int defaultOffset) {
if (ptrIndex < this.pointerCount) {
return factory.fromPointerReader(this.segment,
this.pointers + ptrIndex,
defaultSegment,
defaultOffset,
this.nestingLimit);
return factory.fromPointerReaderRefDefault(this.segment,
this.pointers + ptrIndex,
defaultSegment,
defaultOffset,
this.nestingLimit);
} else {
return factory.fromPointerReader(SegmentReader.EMPTY,
0,
defaultSegment,
defaultOffset,
this.nestingLimit);
return factory.fromPointerReaderRefDefault(SegmentReader.EMPTY,
0,
defaultSegment,
defaultOffset,
this.nestingLimit);
}
}

Expand Down
15 changes: 14 additions & 1 deletion runtime/src/main/java/org/capnproto/Text.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,22 @@
import java.nio.ByteBuffer;

public final class Text {
public static final class Factory implements FromPointerReaderBlobDefault<Reader>,
public static final class Factory implements
FromPointerReaderBlobDefault<Reader>,
FromPointerReader<Reader>,
FromPointerBuilderBlobDefault<Builder>,
FromPointerBuilder<Builder>,
SetPointerBuilder<Reader>,
InitSizedFromPointerBuilder<Builder> {
public final Reader fromPointerReaderBlobDefault(SegmentReader segment, int pointer, java.nio.ByteBuffer defaultBuffer,
int defaultOffset, int defaultSize) {
return WireHelpers.readTextPointer(segment, pointer, defaultBuffer, defaultOffset, defaultSize);
}

public final Reader fromPointerReader(SegmentReader segment, int pointer, int nestingLimit) {
return WireHelpers.readTextPointer(segment, pointer, null, 0, 0);
}

public final Builder fromPointerBuilderBlobDefault(SegmentBuilder segment, int pointer,
java.nio.ByteBuffer defaultBuffer, int defaultOffset, int defaultSize) {
return WireHelpers.getWritableTextPointer(pointer,
Expand All @@ -21,6 +28,12 @@ public final Builder fromPointerBuilderBlobDefault(SegmentBuilder segment, int p
defaultSize);
}

public final Builder fromPointerBuilder(SegmentBuilder segment, int pointer) {
return WireHelpers.getWritableTextPointer(pointer,
segment,
null, 0, 0);
}

public final Builder initSizedFromPointerBuilder(SegmentBuilder segment, int pointer, int size) {
return WireHelpers.initTextPointer(pointer, segment, size);
}
Expand Down
8 changes: 4 additions & 4 deletions runtime/src/main/java/org/capnproto/TextList.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public Reader(SegmentReader segment,
}

public Text.Reader get(int index) {
return _getPointerElement(Text.factory, index, null, 0, 0);
return _getPointerElement(Text.factory, index);
}

public final class Iterator implements java.util.Iterator<Text.Reader> {
Expand All @@ -41,7 +41,7 @@ public Iterator(Reader list) {
}

public Text.Reader next() {
return _getPointerElement(Text.factory, idx++, null, 0, 0);
return this.list._getPointerElement(Text.factory, idx++);
}
public boolean hasNext() {
return idx < list.size();
Expand All @@ -65,7 +65,7 @@ public Builder(SegmentBuilder segment, int ptr,
}

public final Text.Builder get(int index) {
return _getPointerElement(Text.factory, index, null, 0, 0);
return _getPointerElement(Text.factory, index);
}

public final void set(int index, Text.Reader value) {
Expand All @@ -80,7 +80,7 @@ public Iterator(Builder list) {
}

public Text.Builder next() {
return this.list._getPointerElement(Text.factory, idx++, null, 0, 0);
return this.list._getPointerElement(Text.factory, idx++);
}
public boolean hasNext() {
return this.idx < this.list.size();
Expand Down

0 comments on commit 2ede424

Please sign in to comment.