Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

97 lines
1.7 KiB

//-----------------------------------------------------------------------------
//
// File: SmartRef.h
// Copyright (C) 1994-1997 Microsoft Corporation
// All rights reserved.
//
//
//
//-----------------------------------------------------------------------------
#ifndef ESPUTIL_SmartRef_H
#define ESPUTIL_SmartRef_H
template<class T>
class SmartRef
{
private:
T *m_pInterface;
public:
NOTHROW SmartRef()
{
m_pInterface = NULL;
}
// Compiler bug, must be inline!
NOTHROW SmartRef(T *pI) {m_pInterface = pI;};
NOTHROW SmartRef(const SmartRef<T> &);
NOTHROW T * operator->(void)
{
LTASSERT(m_pInterface != NULL);
return m_pInterface;
}
NOTHROW const T * operator->(void) const
{
LTASSERT(m_pInterface != NULL);
return m_pInterface;
}
NOTHROW T & operator*(void)
{
LTASSERT(m_pInterface != NULL);
return *m_pInterface;
}
NOTHROW T * Extract(void)
{
return ExtractImpl();
};
NOTHROW T * GetInterface(BOOL fAddRef = FALSE)
{
return GetInterfaceImpl(fAddRef);
};
NOTHROW const T * GetInterface(void) const
{
return m_pInterface;
}
NOTHROW BOOL IsNull(void) const
{
return m_pInterface == NULL;
}
NOTHROW ~SmartRef()
{
if (m_pInterface != NULL)
{
m_pInterface->Release();
}
}
void operator=(T* pOther)
{
opEqImpl(pOther);
}
void operator=(const SmartRef<T> &other);
T ** operator&(void);
operator T* &(void) {return opTpRef();};
private:
void operator delete(void *);
NOTHROW T * ExtractImpl(void);
NOTHROW T * GetInterfaceImpl(BOOL fAddRef);
NOTHROW T * & opTpRef(void);
void opEqImpl(T* pOther);
};
#include "SmartRef.inl"
#endif