Debian Codegraph @

src/uk/me/parabola/imgfmt/app/net/NETHeader.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2007 Steve Ratcliffe
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 *
14 * Author: Steve Ratcliffe
15 * Create date: Jan 5, 2008
16 */
17 package uk.me.parabola.imgfmt.app.net;
18
19 import uk.me.parabola.imgfmt.app.CommonHeader;
20 import uk.me.parabola.imgfmt.app.ImgFileReader;
21 import uk.me.parabola.imgfmt.app.ImgFileWriter;
22 import uk.me.parabola.imgfmt.app.Section;
23 import uk.me.parabola.imgfmt.app.SectionWriter;
24
25 /**
26 * The header of the NET file.
27 *
28 * @author Steve Ratcliffe
29 */
30 public class NETHeader extends CommonHeader {
31 public static final int HEADER_LEN = 55; // Other lengths are possible
32
33 private static final char SORTED_ROAD_RECSIZE = 3;
34
35 private final Section roadDefinitions = new Section();
36 private final Section segmentedRoads = new Section(roadDefinitions);
37 private final Section sortedRoads = new Section(segmentedRoads, SORTED_ROAD_RECSIZE);
38
39 private int roadShift;
40 private int segmentShift;
41
42 public NETHeader() {
43 super(HEADER_LEN, "GARMIN NET");
44 }
45
46 /**
47 * Read the rest of the header. Specific to the given file. It is guaranteed
48 * that the file position will be set to the correct place before this is
49 * called.
50 *
51 * @param reader The header is read from here.
52 */
53 protected void readFileHeader(ImgFileReader reader) {
54 roadDefinitions.readSectionInfo(reader, false);
55 roadShift = reader.get1u();
56
57 segmentedRoads.readSectionInfo(reader, false);
58 segmentShift = reader.get1u();
59
60 sortedRoads.readSectionInfo(reader, true);
61
62 reader.get4();
63 reader.get();
64 reader.get();
65 }
66
67 /**
68 * Write the rest of the header. It is guaranteed that the writer will be set
69 * to the correct position before calling.
70 *
71 * @param writer The header is written here.
72 */
73 protected void writeFileHeader(ImgFileWriter writer) {
74 roadDefinitions.writeSectionInfo(writer);
75
76 writer.put1u(roadShift); // offset multiplier
77
78 segmentedRoads.writeSectionInfo(writer);
79
80 writer.put1u(segmentShift); // offset multiplier
81
82 sortedRoads.writeSectionInfo(writer);
83
84 writer.put4(0);
85 writer.put1u(1);
86 writer.put1u(0);
87 }
88
89 ImgFileWriter makeRoadWriter(ImgFileWriter writer) {
90 roadDefinitions.setPosition(writer.position());
91 return new SectionWriter(writer, roadDefinitions);
92 }
93
94 ImgFileWriter makeSortedRoadWriter(ImgFileWriter writer) {
95 sortedRoads.setPosition(writer.position());
96 return new SectionWriter(writer, sortedRoads);
97 }
98
99 public int getRoadDefinitionsStart() {
100 return roadDefinitions.getPosition();
101 }
102
103 public int getSortedRoadsStart() {
104 return sortedRoads.getPosition();
105 }
106
107 public int getSortedRoadsEnd() {
108 return sortedRoads.getEndPos();
109 }
110
111 public int getRoadShift() {
112 return roadShift;
113 }
114 }