use crate::misc::Ptr;
use crate::sys::*;
use std::mem::MaybeUninit;
use std::ops::Deref;
#[derive(Clone, Debug)]
pub struct CziReader(pub(crate) CziReaderObjectHandle);
#[derive(Clone, Debug)]
pub struct SubBlock(pub(crate) SubBlockObjectHandle);
#[derive(Clone, Debug)]
pub struct InputStream(pub(crate) InputStreamObjectHandle);
#[derive(Clone, Debug)]
pub struct OutputStream(pub(crate) OutputStreamObjectHandle);
#[derive(Clone, Debug)]
pub struct MemoryAllocation(pub(crate) MemoryAllocationObjectHandle);
#[derive(Clone, Debug)]
pub struct Bitmap(pub(crate) BitmapObjectHandle);
#[derive(Clone, Debug)]
pub struct MetadataSegment(pub(crate) MetadataSegmentObjectHandle);
#[derive(Clone, Debug)]
pub struct Attachment(pub(crate) AttachmentObjectHandle);
#[derive(Clone, Debug)]
pub struct CziWriter(pub(crate) CziWriterObjectHandle);
#[derive(Clone, Debug)]
pub struct SingleChannelScalingTileAccessor(
pub(crate) SingleChannelScalingTileAccessorObjectHandle,
);
#[derive(Clone, Debug)]
pub struct CziDocumentInfo(pub(crate) CziDocumentInfoHandle);
#[derive(Clone, Debug)]
pub struct DisplaySettings(pub(crate) DisplaySettingsHandle);
#[derive(Clone, Debug)]
pub struct ChannelDisplaySettings(pub(crate) ChannelDisplaySettingsHandle);
macro_rules! impl_struct {
($($n:ident: $t:ty: $s:ty $(,)?)*) => {
$(
impl $t {
#[allow(dead_code)]
pub (crate) fn handle(&self) -> ObjectHandle { self.0 }
}
impl Ptr for $t {
type Pointer = $s;
unsafe fn assume_init(ptr: MaybeUninit<Self::Pointer>) -> Self {
Self(unsafe { ptr.assume_init() })
}
fn as_mut_ptr(&self) -> *mut Self::Pointer {
&self.0 as *const _ as *mut _
}
fn as_ptr(&self) -> *const Self::Pointer {
&self.0 as *const _ as *const _
}
}
impl Deref for $t {
type Target = ObjectHandle;
fn deref(&self) -> &Self::Target {
&self.0
}
}
)*
};
}
impl_struct! {
CziReader: CziReader: CziReaderObjectHandle,
SubBlock: SubBlock: SubBlockObjectHandle,
InputStream: InputStream: InputStreamObjectHandle,
OutputStream: OutputStream: OutputStreamObjectHandle,
MemoryAllocation: MemoryAllocation: MemoryAllocationObjectHandle,
Bitmap: Bitmap: BitmapObjectHandle,
MetadataSegment: MetadataSegment: MetadataSegmentObjectHandle,
Attachment: Attachment: AttachmentObjectHandle,
CziWriter: CziWriter: CziWriterObjectHandle,
SingleChannelScalingTileAccessor: SingleChannelScalingTileAccessor: SingleChannelScalingTileAccessorObjectHandle,
CziDocumentInfo: CziDocumentInfo: CziDocumentInfoHandle,
DisplaySettings: DisplaySettings: DisplaySettingsHandle,
ChannelDisplaySettings: ChannelDisplaySettings: ChannelDisplaySettingsHandle,
}