-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathlibprimes_interface_handle.rs
More file actions
93 lines (79 loc) · 2.76 KB
/
libprimes_interface_handle.rs
File metadata and controls
93 lines (79 loc) · 2.76 KB
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
/*++
Copyright (C) 2019 PrimeDevelopers
All rights reserved.
This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.0-develop.
Abstract: This is an autogenerated Rust implementation file in order to allow easy
development of Prime Numbers Library. The functions in this file need to be implemented. It needs to be generated only once.
Interface version: 1.2.0
*/
// Handle passed through interface define the casting maps needed to extract
use libprimes_interfaces::*;
#[allow(dead_code)]
impl HandleImpl {
pub fn as_base(&self) -> Option<&dyn Base> {
match self {
HandleImpl::TCalculator(_, ptr) => Some(ptr.as_ref()),
HandleImpl::TFactorizationCalculator(_, ptr) => Some(ptr.as_ref()),
HandleImpl::TSieveCalculator(_, ptr) => Some(ptr.as_ref()),
_ => None
}
}
pub fn as_mut_base(&mut self) -> Option<&mut dyn Base> {
match self {
HandleImpl::TCalculator(_, ptr) => Some(ptr.as_mut()),
HandleImpl::TFactorizationCalculator(_, ptr) => Some(ptr.as_mut()),
HandleImpl::TSieveCalculator(_, ptr) => Some(ptr.as_mut()),
_ => None
}
}
pub fn as_calculator(&self) -> Option<&dyn Calculator> {
match self {
HandleImpl::TFactorizationCalculator(_, ptr) => Some(ptr.as_ref()),
HandleImpl::TSieveCalculator(_, ptr) => Some(ptr.as_ref()),
_ => None
}
}
pub fn as_mut_calculator(&mut self) -> Option<&mut dyn Calculator> {
match self {
HandleImpl::TFactorizationCalculator(_, ptr) => Some(ptr.as_mut()),
HandleImpl::TSieveCalculator(_, ptr) => Some(ptr.as_mut()),
_ => None
}
}
pub fn as_factorization_calculator(&self) -> Option<&dyn FactorizationCalculator> {
match self {
_ => None
}
}
pub fn as_mut_factorization_calculator(&mut self) -> Option<&mut dyn FactorizationCalculator> {
match self {
_ => None
}
}
pub fn as_sieve_calculator(&self) -> Option<&dyn SieveCalculator> {
match self {
_ => None
}
}
pub fn as_mut_sieve_calculator(&mut self) -> Option<&mut dyn SieveCalculator> {
match self {
_ => None
}
}
pub fn inc_ref_count(&mut self) {
match self {
HandleImpl::TBase(count, _) => *count += 1,
HandleImpl::TCalculator(count, _) => *count += 1,
HandleImpl::TFactorizationCalculator(count, _) => *count += 1,
HandleImpl::TSieveCalculator(count, _) => *count += 1,
}
}
pub fn dec_ref_count(&mut self) -> bool {
match self {
HandleImpl::TBase(count, _) => {*count -= 1; *count == 0},
HandleImpl::TCalculator(count, _) => {*count -= 1; *count == 0},
HandleImpl::TFactorizationCalculator(count, _) => {*count -= 1; *count == 0},
HandleImpl::TSieveCalculator(count, _) => {*count -= 1; *count == 0},
}
}
}