Debian Codegraph @

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

raw symbols SCIP
1 /*
2 * Copyright (C) 2009.
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 uk.me.parabola.imgfmt.Utils;
16 import uk.me.parabola.imgfmt.app.ImgFileWriter;
17
18 /**
19 * Super class of all sections that contain items that belong to a particular
20 * map.
21 *
22 * @author Steve Ratcliffe
23 */
24 public abstract class MdrMapSection extends MdrSection implements HasHeaderFlags {
25 private Mdr1 index;
26
27 public void setMapIndex(Mdr1 index) {
28 this.index = index;
29 }
30
31 /**
32 * This is called before the sections are written out, but after all the
33 * data is read into them.
34 * @param sectionNumber The one-based section number.
35 */
36 public final void initIndex(int sectionNumber) {
37 // Set the size required to store the record numbers for this section.
38 // There are no flags or minimums required here, unlike in setPointerSize()
39 // which does a similar thing.
40 int n = getNumberOfItems();
41 index.setPointerSize(sectionNumber, Utils.numberToPointerSize(n));
42 }
43
44 /**
45 * Add a pointer to the reverse index for this section.
46 * @param recordNumber A record number in this section, belonging to the
47 * given map.
48 */
49 public void addIndexPointer(int mapNumber, int recordNumber) {
50 if (!isForDevice())
51 index.addPointer(mapNumber, recordNumber);
52 }
53
54 protected void putCityIndex(ImgFileWriter writer, int cityIndex) {
55 int flag = cityIndex > 0 ? getSizes().getCityFlag() : 0;
56 writer.putNu(getSizes().getCitySizeFlagged(), cityIndex | flag);
57 }
58
59 protected void putRegionIndex(ImgFileWriter writer, int region) {
60 // This is only called when putCityIndex might also be called and so has to be
61 // the same size (probably ;)
62 writer.putNu(getSizes().getCitySizeFlagged(), region);
63 }
64
65 protected void putPoiIndex(ImgFileWriter writer, int poiIndex, boolean isNew) {
66 int flag = isNew? getSizes().getPoiFlag(): 0;
67 writer.putNu(getSizes().getPoiSizeFlagged(), poiIndex | flag);
68 }
69
70 protected boolean hasFlag(int val) {
71 return (getExtraValue() & val) != 0;
72 }
73 }