Skip to main content

libczirw_sys/
handle.rs

1use crate::misc::Ptr;
2use crate::sys::*;
3use std::mem::MaybeUninit;
4use std::ops::Deref;
5
6/// CZI-reader object.
7#[derive(Clone, Debug)]
8pub struct CziReader(pub(crate) CziReaderObjectHandle);
9
10/// sub-block object.
11#[derive(Clone, Debug)]
12pub struct SubBlock(pub(crate) SubBlockObjectHandle);
13
14/// input stream object.
15#[derive(Clone, Debug)]
16pub struct InputStream(pub(crate) InputStreamObjectHandle);
17
18/// output stream object.
19#[derive(Clone, Debug)]
20pub struct OutputStream(pub(crate) OutputStreamObjectHandle);
21
22/// memory allocation object - which is a pointer to a memory block, which must be
23/// freed with 'libCZI_Free'.
24/// TODO(JBL): this is not really used so far, should be removed I guess.
25#[derive(Clone, Debug)]
26pub struct MemoryAllocation(pub(crate) MemoryAllocationObjectHandle);
27
28/// bitmap object.
29#[derive(Clone, Debug)]
30pub struct Bitmap(pub(crate) BitmapObjectHandle);
31
32/// metadata segment object.
33#[derive(Clone, Debug)]
34pub struct MetadataSegment(pub(crate) MetadataSegmentObjectHandle);
35
36/// attachment object.
37#[derive(Clone, Debug)]
38pub struct Attachment(pub(crate) AttachmentObjectHandle);
39
40/// writer object.
41#[derive(Clone, Debug)]
42pub struct CziWriter(pub(crate) CziWriterObjectHandle);
43
44/// single-channel-scaling-tile-accessor.
45#[derive(Clone, Debug)]
46pub struct SingleChannelScalingTileAccessor(
47    pub(crate) SingleChannelScalingTileAccessorObjectHandle,
48);
49
50/// document info object.
51#[derive(Clone, Debug)]
52pub struct CziDocumentInfo(pub(crate) CziDocumentInfoHandle);
53
54/// display settings object.
55#[derive(Clone, Debug)]
56pub struct DisplaySettings(pub(crate) DisplaySettingsHandle);
57
58/// channel display settings object.
59#[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}