Debian Codegraph @

src/uk/me/parabola/imgfmt/app/mdr/Mdr8.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2011.
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 3 or
6 * version 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 */
13 package uk.me.parabola.imgfmt.app.mdr;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
18 import uk.me.parabola.imgfmt.app.ImgFileWriter;
19
20 /**
21 * This section is a simple index into the streets section (mdr7).
22 *
23 * @author Steve Ratcliffe
24 */
25 public class Mdr8 extends MdrSection implements HasHeaderFlags {
26 private static final int STRING_WIDTH = 4;
27
28 private List<Mdr8Record> index = new ArrayList<>();
29
30 public Mdr8(MdrConfig config) {
31 setConfig(config);
32 }
33
34 /**
35 * Write out the contents of this section.
36 *
37 * @param writer Where to write it.
38 */
39 public void writeSectData(ImgFileWriter writer) {
40 if (index.size() <= 1)
41 return;
42 int size = associatedSize();
43 for (Mdr8Record s : index) {
44 for (int i = 0; i< STRING_WIDTH; i++) {
45 writer.put1u(s.getPrefix()[i]);
46 }
47 writer.putNu(size, s.getRecordNumber());
48 }
49 }
50
51 protected int associatedSize() {
52 return getSizes().getStreetSize();
53 }
54
55 /**
56 * The number of records in this section.
57 *
58 * @return The number of items in the section.
59 */
60 protected int numberOfItems() {
61 return index.size() > 1 ? 0: index.size();
62 }
63
64 /**
65 * The size of a record in the section. This is not a constant and might vary
66 * on various factors, such as the file version, if we are preparing for a
67 * device, the number of maps etc.
68 *
69 * @return The size of a record in this section.
70 */
71 public int getItemSize() {
72 return STRING_WIDTH + associatedSize();
73 }
74
75 public void setIndex(List<Mdr8Record> index) {
76 this.index = index;
77 }
78
79 /**
80 * The header flags for the section.
81 * Possible values are not known.
82 *
83 * @return The correct value based on the contents of the section. Zero if
84 * nothing needs to be done.
85 */
86 public int getExtraValue() {
87 // this value is likely to depend on the size of the max record number.
88 return (STRING_WIDTH << 8) + 0x0a;
89 }
90 }