LOL it's factory time
This commit is contained in:
parent
6d22ad85f8
commit
31f6d30169
4 changed files with 50 additions and 0 deletions
1
Makefile
1
Makefile
|
@ -5,6 +5,7 @@ CAPNP_SOURCES=\
|
||||||
src/capnp/ListReader.java\
|
src/capnp/ListReader.java\
|
||||||
src/capnp/PointerReader.java\
|
src/capnp/PointerReader.java\
|
||||||
src/capnp/SegmentReader.java\
|
src/capnp/SegmentReader.java\
|
||||||
|
src/capnp/StructFactory.java\
|
||||||
src/capnp/StructReader.java\
|
src/capnp/StructReader.java\
|
||||||
src/capnp/StructList.java\
|
src/capnp/StructList.java\
|
||||||
src/capnp/Text.java\
|
src/capnp/Text.java\
|
||||||
|
|
|
@ -10,6 +10,34 @@ public class ListReader {
|
||||||
int nestingLimit;
|
int nestingLimit;
|
||||||
|
|
||||||
|
|
||||||
|
public ListReader () {
|
||||||
|
this.segment = null;
|
||||||
|
this.ptr = 0;
|
||||||
|
this.elementCount = 0;
|
||||||
|
this.step = 0;
|
||||||
|
this.structDataSize = 0;
|
||||||
|
this.structPointerCount = 0;
|
||||||
|
this.nestingLimit = 0x7fffffff;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ListReader(SegmentReader segment, int ptr,
|
||||||
|
int elementCount, int step,
|
||||||
|
int structDataSize, short structPointerCount,
|
||||||
|
int nestingLimit) {
|
||||||
|
this.segment = segment;
|
||||||
|
this.ptr = ptr;
|
||||||
|
this.elementCount = elementCount;
|
||||||
|
this.step = step;
|
||||||
|
this.structDataSize = structDataSize;
|
||||||
|
this.structPointerCount = structPointerCount;
|
||||||
|
this.nestingLimit = nestingLimit;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public int size() {
|
||||||
|
return this.elementCount;
|
||||||
|
}
|
||||||
|
|
||||||
public StructReader getStructElement(int index) {
|
public StructReader getStructElement(int index) {
|
||||||
// TODO check nesting limit
|
// TODO check nesting limit
|
||||||
|
|
||||||
|
|
5
src/capnp/StructFactory.java
Normal file
5
src/capnp/StructFactory.java
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
package capnp;
|
||||||
|
|
||||||
|
public interface StructFactory<T> {
|
||||||
|
public abstract T createFromStructReader(StructReader reader);
|
||||||
|
}
|
|
@ -4,5 +4,21 @@ package capnp;
|
||||||
public class StructList {
|
public class StructList {
|
||||||
public static class Reader<T> {
|
public static class Reader<T> {
|
||||||
public ListReader reader;
|
public ListReader reader;
|
||||||
|
public StructFactory<T> factory;
|
||||||
|
|
||||||
|
public Reader(ListReader reader, StructFactory<T> factory) {
|
||||||
|
this.reader = reader;
|
||||||
|
this.factory = factory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int size() {
|
||||||
|
return this.reader.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public T get(int index) {
|
||||||
|
StructReader sr = this.reader.getStructElement(index);
|
||||||
|
return this.factory.createFromStructReader(sr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue