|
|
@@ -1,4 +1,4 @@
|
|
1
|
|
-//! `HeaderBlock`, `PrimitiveBlock` and `Group`s
|
|
|
1
|
+//! `HeaderBlock`, `PrimitiveBlock` and `PrimitiveGroup`s
|
|
2
|
2
|
|
|
3
|
3
|
use dense::DenseNodeIter;
|
|
4
|
4
|
use elements::{Node, Way, Relation};
|
|
|
@@ -7,6 +7,7 @@ use proto::osmformat;
|
|
7
|
7
|
use std;
|
|
8
|
8
|
|
|
9
|
9
|
|
|
|
10
|
+/// A `HeaderBlock`. It contains metadata about following `PrimitiveBlock`s.
|
|
10
|
11
|
pub struct HeaderBlock {
|
|
11
|
12
|
header: osmformat::HeaderBlock,
|
|
12
|
13
|
}
|
|
|
@@ -16,29 +17,35 @@ impl HeaderBlock {
|
|
16
|
17
|
HeaderBlock { header: header }
|
|
17
|
18
|
}
|
|
18
|
19
|
|
|
|
20
|
+ /// Returns a list of required features that a parser needs to implement to parse the following
|
|
|
21
|
+ /// `PrimitiveBlock`s.
|
|
19
|
22
|
pub fn required_features(&self) -> &[String] {
|
|
20
|
23
|
self.header.get_required_features()
|
|
21
|
24
|
}
|
|
22
|
25
|
|
|
|
26
|
+ /// Returns a list of optional features that a parser can choose to ignore.
|
|
23
|
27
|
pub fn optional_features(&self) -> &[String] {
|
|
24
|
28
|
self.header.get_optional_features()
|
|
25
|
29
|
}
|
|
26
|
30
|
}
|
|
27
|
31
|
|
|
|
32
|
+/// A `PrimitiveBlock`. It contains a sequence of groups.
|
|
28
|
33
|
pub struct PrimitiveBlock {
|
|
29
|
34
|
block: osmformat::PrimitiveBlock,
|
|
30
|
35
|
}
|
|
31
|
36
|
|
|
32
|
37
|
impl PrimitiveBlock {
|
|
33
|
|
- pub fn new(block: osmformat::PrimitiveBlock) -> PrimitiveBlock {
|
|
|
38
|
+ pub(crate) fn new(block: osmformat::PrimitiveBlock) -> PrimitiveBlock {
|
|
34
|
39
|
PrimitiveBlock { block: block }
|
|
35
|
40
|
}
|
|
36
|
41
|
|
|
|
42
|
+ /// Returns an iterator over the groups in this `PrimitiveBlock`.
|
|
37
|
43
|
pub fn groups(&self) -> GroupIter {
|
|
38
|
44
|
GroupIter::new(&self.block)
|
|
39
|
45
|
}
|
|
40
|
46
|
}
|
|
41
|
47
|
|
|
|
48
|
+/// A `PrimitiveGroup` contains a sequence of elements of one type.
|
|
42
|
49
|
pub struct PrimitiveGroup<'a> {
|
|
43
|
50
|
block: &'a osmformat::PrimitiveBlock,
|
|
44
|
51
|
group: &'a osmformat::PrimitiveGroup,
|
|
|
@@ -54,23 +61,28 @@ impl<'a> PrimitiveGroup<'a> {
|
|
54
|
61
|
}
|
|
55
|
62
|
}
|
|
56
|
63
|
|
|
|
64
|
+ /// Returns an iterator over the nodes in this group.
|
|
57
|
65
|
pub fn nodes(&self) -> GroupNodeIter<'a> {
|
|
58
|
66
|
GroupNodeIter::new(self.block, self.group)
|
|
59
|
67
|
}
|
|
60
|
68
|
|
|
|
69
|
+ /// Returns an iterator over the dense nodes in this group.
|
|
61
|
70
|
pub fn dense_nodes(&self) -> DenseNodeIter<'a> {
|
|
62
|
71
|
DenseNodeIter::new(self.block, self.group.get_dense())
|
|
63
|
72
|
}
|
|
64
|
73
|
|
|
|
74
|
+ /// Returns an iterator over the ways in this group.
|
|
65
|
75
|
pub fn ways(&self) -> GroupWayIter<'a> {
|
|
66
|
76
|
GroupWayIter::new(self.block, self.group)
|
|
67
|
77
|
}
|
|
68
|
78
|
|
|
|
79
|
+ /// Returns an iterator over the relations in this group.
|
|
69
|
80
|
pub fn relations(&self) -> GroupRelationIter<'a> {
|
|
70
|
81
|
GroupRelationIter::new(self.block, self.group)
|
|
71
|
82
|
}
|
|
72
|
83
|
}
|
|
73
|
84
|
|
|
|
85
|
+/// An iterator over the groups in a `PrimitiveBlock`.
|
|
74
|
86
|
pub struct GroupIter<'a> {
|
|
75
|
87
|
block: &'a osmformat::PrimitiveBlock,
|
|
76
|
88
|
groups: std::slice::Iter<'a, osmformat::PrimitiveGroup>,
|
|
|
@@ -102,6 +114,7 @@ impl<'a> Iterator for GroupIter<'a> {
|
|
102
|
114
|
|
|
103
|
115
|
impl<'a> ExactSizeIterator for GroupIter<'a> {}
|
|
104
|
116
|
|
|
|
117
|
+/// An iterator over the nodes in a `Group`.
|
|
105
|
118
|
pub struct GroupNodeIter<'a> {
|
|
106
|
119
|
block: &'a osmformat::PrimitiveBlock,
|
|
107
|
120
|
nodes: std::slice::Iter<'a, osmformat::Node>,
|
|
|
@@ -135,6 +148,7 @@ impl<'a> Iterator for GroupNodeIter<'a> {
|
|
135
|
148
|
|
|
136
|
149
|
impl<'a> ExactSizeIterator for GroupNodeIter<'a> {}
|
|
137
|
150
|
|
|
|
151
|
+/// An iterator over the ways in a `Group`.
|
|
138
|
152
|
pub struct GroupWayIter<'a> {
|
|
139
|
153
|
block: &'a osmformat::PrimitiveBlock,
|
|
140
|
154
|
ways: std::slice::Iter<'a, osmformat::Way>,
|
|
|
@@ -168,6 +182,7 @@ impl<'a> Iterator for GroupWayIter<'a> {
|
|
168
|
182
|
|
|
169
|
183
|
impl<'a> ExactSizeIterator for GroupWayIter<'a> {}
|
|
170
|
184
|
|
|
|
185
|
+/// An iterator over the relations in a `Group`.
|
|
171
|
186
|
pub struct GroupRelationIter<'a> {
|
|
172
|
187
|
block: &'a osmformat::PrimitiveBlock,
|
|
173
|
188
|
rels: std::slice::Iter<'a, osmformat::Relation>,
|