1use crate::misc::Ptr;
2use crate::sys::*;
3use std::mem::MaybeUninit;
4use std::ops::Deref;
5
6#[derive(Clone, Debug)]
8pub struct CziReader(pub(crate) CziReaderObjectHandle);
9
10#[derive(Clone, Debug)]
12pub struct SubBlock(pub(crate) SubBlockObjectHandle);
13
14#[derive(Clone, Debug)]
16pub struct InputStream(pub(crate) InputStreamObjectHandle);
17
18#[derive(Clone, Debug)]
20pub struct OutputStream(pub(crate) OutputStreamObjectHandle);
21
22#[derive(Clone, Debug)]
26pub struct MemoryAllocation(pub(crate) MemoryAllocationObjectHandle);
27
28#[derive(Clone, Debug)]
30pub struct Bitmap(pub(crate) BitmapObjectHandle);
31
32#[derive(Clone, Debug)]
34pub struct MetadataSegment(pub(crate) MetadataSegmentObjectHandle);
35
36#[derive(Clone, Debug)]
38pub struct Attachment(pub(crate) AttachmentObjectHandle);
39
40#[derive(Clone, Debug)]
42pub struct CziWriter(pub(crate) CziWriterObjectHandle);
43
44#[derive(Clone, Debug)]
46pub struct SingleChannelScalingTileAccessor(
47 pub(crate) SingleChannelScalingTileAccessorObjectHandle,
48);
49
50#[derive(Clone, Debug)]
52pub struct CziDocumentInfo(pub(crate) CziDocumentInfoHandle);
53
54#[derive(Clone, Debug)]
56pub struct DisplaySettings(pub(crate) DisplaySettingsHandle);
57
58#[derive(Clone, Debug)]
60pub struct ChannelDisplaySettings(pub(crate) ChannelDisplaySettingsHandle);
61
62macro_rules! impl_struct {
63 ($($n:ident: $t:ty: $s:ty $(,)?)*) => {
64 $(
65 impl $t {
66 #[allow(dead_code)]
67 pub (crate) fn handle(&self) -> ObjectHandle { self.0 }
68 }
69
70 impl Ptr for $t {
71 type Pointer = $s;
72
73 unsafe fn assume_init(ptr: MaybeUninit<Self::Pointer>) -> Self {
74 Self(unsafe { ptr.assume_init() })
75 }
76
77 fn as_mut_ptr(&self) -> *mut Self::Pointer {
78 &self.0 as *const _ as *mut _
79 }
80
81 fn as_ptr(&self) -> *const Self::Pointer {
82 &self.0 as *const _ as *const _
83 }
84 }
85
86 impl Deref for $t {
87 type Target = ObjectHandle;
88
89 fn deref(&self) -> &Self::Target {
90 &self.0
91 }
92 }
93 )*
94 };
95}
96
97impl_struct! {
98 CziReader: CziReader: CziReaderObjectHandle,
99 SubBlock: SubBlock: SubBlockObjectHandle,
100 InputStream: InputStream: InputStreamObjectHandle,
101 OutputStream: OutputStream: OutputStreamObjectHandle,
102 MemoryAllocation: MemoryAllocation: MemoryAllocationObjectHandle,
103 Bitmap: Bitmap: BitmapObjectHandle,
104 MetadataSegment: MetadataSegment: MetadataSegmentObjectHandle,
105 Attachment: Attachment: AttachmentObjectHandle,
106 CziWriter: CziWriter: CziWriterObjectHandle,
107 SingleChannelScalingTileAccessor: SingleChannelScalingTileAccessor: SingleChannelScalingTileAccessorObjectHandle,
108 CziDocumentInfo: CziDocumentInfo: CziDocumentInfoHandle,
109 DisplaySettings: DisplaySettings: DisplaySettingsHandle,
110 ChannelDisplaySettings: ChannelDisplaySettings: ChannelDisplaySettingsHandle,
111}