| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package uk.me.parabola.imgfmt.app.net; |
| 18 |
|
| 19 |
import java.util.ArrayList; |
| 20 |
import java.util.List; |
| 21 |
|
| 22 |
import uk.me.parabola.imgfmt.FormatException; |
| 23 |
import uk.me.parabola.imgfmt.app.ImgFileWriter; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
public class TableC { |
| 29 |
|
| 30 |
private int size; |
| 31 |
|
| 32 |
private final TableA tabA; |
| 33 |
|
| 34 |
private final List<RouteRestriction> restrictions = new ArrayList<>(); |
| 35 |
|
| 36 |
public TableC(TableA tabA) { |
| 37 |
this.tabA = tabA; |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
public void write(ImgFileWriter writer, int tablesOffset) { |
| 44 |
if (!restrictions.isEmpty()) { |
| 45 |
if (size < 0x100) |
| 46 |
writer.put1u(size); |
| 47 |
else |
| 48 |
writer.put2u(size); |
| 49 |
for (RouteRestriction restr : restrictions) |
| 50 |
restr.write(writer, tablesOffset); |
| 51 |
} |
| 52 |
if(tabA.numRoundaboutArcs() > 0) |
| 53 |
writer.put1u(tabA.numRoundaboutArcs()); |
| 54 |
if(tabA.numUnpavedArcs() > 0) |
| 55 |
writer.put1u(tabA.numUnpavedArcs()); |
| 56 |
if(tabA.numFerryArcs() > 0) |
| 57 |
writer.put1u(tabA.numFerryArcs()); |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
public int addRestriction(RouteRestriction restr) { |
| 68 |
int offset = size; |
| 69 |
restrictions.add(restr); |
| 70 |
size += restr.getSize(); |
| 71 |
return offset; |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
private int getOffsetSize() { |
| 78 |
if (size < 0x80) |
| 79 |
return 1; |
| 80 |
else if (size < 0x8000) |
| 81 |
return 2; |
| 82 |
else |
| 83 |
|
| 84 |
throw new FormatException("too many restrictions"); |
| 85 |
} |
| 86 |
|
| 87 |
public void propagateSizeBytes() { |
| 88 |
int b = getOffsetSize(); |
| 89 |
for (RouteRestriction restr : restrictions) |
| 90 |
restr.setOffsetSize(b); |
| 91 |
} |
| 92 |
|
| 93 |
public int getFormat() { |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
int format = 0; |
| 100 |
if(size > 0) { |
| 101 |
++format; |
| 102 |
if(size > 0xff) |
| 103 |
++format; |
| 104 |
} |
| 105 |
if(tabA.numRoundaboutArcs() > 0) |
| 106 |
format |= 0x04; |
| 107 |
if(tabA.numUnpavedArcs() > 0) |
| 108 |
format |= 0x08; |
| 109 |
if(tabA.numFerryArcs() > 0) |
| 110 |
format |= 0x10; |
| 111 |
return format; |
| 112 |
} |
| 113 |
} |