⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 warptrwrapper.h

📁 ftpserver very good sample
💻 H
字号:
/** General STL wrapper for \Ref{WarSmartPointer} pointers.    The wrapper takes care of the reference count, so that the  {\itpointer} object is destroyed when the {\bfWarPtrWrapper}  node is destroyed, unless {\bfAttach()} is performed on the  pointer.  This wrapper is designed to be used by STL lists/sets. It  is therefore not optimal for use as a general container  for pointers.   Usage:  \begin{verbatim}   typedef std::list<WarPtrWrapper < MyWarSmartPointer> > MY_LIST;   MY_LIST List;  List.push_back(new MyWarSmartPointer(Args));    ...   MyWarSmartPointer *p = &List.back()->Data();  p->Attach(); // Make sure that the smart pointer stays around  ...  p->Detach(); // We are done with the smart pointer.   \end{verbatim}   @see WarSmartPointer  */#ifndef WAR_PTR_WRAPPER_H#define WAR_PTR_WRAPPER_H/* SYSTEM INCLUDES *//* PROJECT INCLUDES */#ifndef WAR_EXCEPTION_H#   include "WarException.h"#endif/* LOCAL INCLUDES *//* FORWARD REFERENCES */#ifdef __cplusplusextern "C" {#endif/****************** BEGIN OLD STYLE C spesific ********//****************** END OLD STYLE C spesific **********/#ifdef __cplusplus }#endif/****************** BEGIN C++ spesific ****************/#ifdef __cplusplustemplate <class T> class WarPtrWrapper {public:    // LIFECYCLE        /** @param Ptr Pointer to the wrapped object        @param bDoAttach True if you want the wrapper to Attach        the pointer. The wrapper is normally given a fresh pointrer,        with the initial reference counter set to 0.      */    WarPtrWrapper(T *Ptr = NULL, bool bDoAttach = true)            : mPtr(Ptr)    {        if (mPtr && bDoAttach)            mPtr->Attach();    }        /**    * Copy constructor.    *    * @param from The value to copy to this object.    */     ///    WarPtrWrapper(const WarPtrWrapper& from)            : mPtr(NULL)    {        operator = (from);    }        /**    * Destructor.    */    ~WarPtrWrapper()    {        if (mPtr)            mPtr->Detach();    }        // OPERATORS    ///    WarPtrWrapper<T> & operator =         (const WarPtrWrapper<T>& V)    {        if (mPtr != V.mPtr)        {            if (mPtr)                mPtr->Detach();            mPtr = V.mPtr;            if (mPtr)                mPtr->Attach();        }        return *this;    }        ///    bool operator < (const WarPtrWrapper<T> & from) const    {        return *mPtr < *from.mPtr;    }    ///    bool operator <= (const WarPtrWrapper<T> & from) const    {        return *mPtr <= *from.mPtr;    }    ///    bool operator > (const WarPtrWrapper<T> & from) const    {        return *mPtr > *from.mPtr;    }    ///    bool operator >= (const WarPtrWrapper<T> & from) const    {        return *mPtr >= *from.mPtr;    }    ///    bool operator == (const WarPtrWrapper<T> & from) const    {        return *mPtr == *from.mPtr;    }    ///    bool operator != (const WarPtrWrapper<T> & from) const    {        return *mPtr != *from.mPtr;    }    ///    inline T * operator -> () const    {        if (mPtr== NULL)            WarThrow(WarError(WAR_ERR_INTERNAL_DATA_NOT_INITIALIZED), "NULL");        return mPtr;    }    ///    inline T & operator * () const    {        if (mPtr== NULL)            WarThrow(WarError(WAR_ERR_INTERNAL_DATA_NOT_INITIALIZED), "NULL");        return *mPtr;    }    operator bool () const    {        return IsEmpty() == false;    }    // OPERATIONS                           // ACCESS        // If you need GetData(), include the definition    // below in war_custom.h    // #define WAR_USE_GET_DATA_METHOD 1#if WAR_USE_GET_DATA_METHOD    inline T& GetData() const    {        if (mPtr== NULL)            WarThrow(WarError(WAR_ERR_INTERNAL_DATA_NOT_INITIALIZED), "NULL");        return *mPtr;    }#endif    // INQUIRY    inline bool IsEmpty() const    {        return mPtr == NULL;    }    inline bool IsSameObject(const WarPtrWrapper<T>& other) const    {        return mPtr == other.mPtr;    }    inline bool IsSameObject(const T *ptr)    {        return mPtr == ptr;    }    protected:private:    T *mPtr;};/* INLINE METHODS *//* EXTERNAL REFERENCES */#endif /* __cplusplus *//****************** END C++ spesific ******************/#endif  /* _WAR_PTR_WRAPPER_H_ */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -