use {w};
use std::ops::{Deref, DerefMut};
pub struct ComPtr<T>(*mut T);
impl<T> ComPtr<T> {
pub unsafe fn new(ptr: *mut T) -> ComPtr<T> { ComPtr(ptr) }
pub fn up<U>(&self) -> ComPtr<U> where T: Deref<Target=U> {
unimplemented!()
}
pub unsafe fn as_mut(&self) -> &mut T {
&mut*self.0
}
fn as_unknown(&self) -> &mut w::IUnknown {
unsafe { &mut *(self.0 as *mut w::IUnknown) }
}
}
impl<T> Deref for ComPtr<T> {
type Target = T;
fn deref(&self) -> &T {
unsafe { &*self.0 }
}
}
impl<T> DerefMut for ComPtr<T> {
fn deref_mut(&mut self) -> &mut T {
unsafe { &mut*self.0 }
}
}
impl<T> Clone for ComPtr<T> {
fn clone(&self) -> Self {
unsafe {
self.as_unknown().AddRef();
ComPtr::new(self.0)
}
}
}
impl<T> Drop for ComPtr<T> {
fn drop(&mut self) {
unsafe { self.as_unknown().Release(); }
}
}
impl<T> PartialEq<ComPtr<T>> for ComPtr<T> {
fn eq(&self, other: &ComPtr<T>) -> bool {
self.0 == other.0
}
}