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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
use snapshot::*;
use util;
use {Descriptive, PutsSnapshot};
pub struct PollingInstrument<P> {
pub name: String,
pub title: Option<String>,
pub description: Option<String>,
pub poll: P,
pub create_group_with_name: bool,
}
impl<P> PollingInstrument<P>
where
P: PutsSnapshot,
{
pub fn new_with_defaults<T: Into<String>>(name: T, poll: P) -> PollingInstrument<P> {
PollingInstrument {
name: name.into(),
title: None,
description: None,
poll,
create_group_with_name: false,
}
}
pub fn name(&self) -> &str {
&self.name
}
pub fn set_name<T: Into<String>>(&mut self, name: T) {
self.name = name.into();
}
pub fn create_group_with_name(&self) -> bool {
self.create_group_with_name
}
pub fn set_create_group_with_name(&mut self, create_group: bool) {
self.create_group_with_name = create_group;
}
pub fn set_title<T: Into<String>>(&mut self, title: T) {
self.title = Some(title.into())
}
pub fn set_description<T: Into<String>>(&mut self, description: T) {
self.description = Some(description.into())
}
fn put_values_into_snapshot(&self, into: &mut Snapshot, descriptive: bool) {
self.poll.put_snapshot(into, descriptive);
}
}
impl<P> Descriptive for PollingInstrument<P> {
fn title(&self) -> Option<&str> {
self.title.as_ref().map(|n| &**n)
}
fn description(&self) -> Option<&str> {
self.description.as_ref().map(|n| &**n)
}
}
impl<P> PutsSnapshot for PollingInstrument<P>
where
P: PutsSnapshot,
{
fn put_snapshot(&self, into: &mut Snapshot, descriptive: bool) {
util::put_postfixed_descriptives(self, &self.name, into, descriptive);
if self.create_group_with_name {
let mut new_level = Snapshot::default();
self.put_values_into_snapshot(&mut new_level, descriptive);
into.items
.push((self.name.clone(), ItemKind::Snapshot(new_level)));
} else {
self.put_values_into_snapshot(into, descriptive);
}
}
}