1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use std::collections::BTreeMap;
use super::{Object, ObjectId, Dictionary};
pub struct Document {
pub version: String,
pub trailer: Dictionary,
pub reference_table: BTreeMap<u32, (u16, u64)>,
pub objects: BTreeMap<ObjectId, Object>,
pub max_id: u32,
}
impl Document {
pub fn new() -> Document {
Document {
version: "1.4".to_string(),
trailer: Dictionary::new(),
reference_table: BTreeMap::new(),
objects: BTreeMap::new(),
max_id: 0,
}
}
pub fn get_object(&self, id: ObjectId) -> Option<&Object> {
if let Some(object) = self.objects.get(&id) {
if let Some(id) = object.as_reference() {
self.get_object(id)
} else {
Some(object)
}
} else {
None
}
}
}