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

📄 ncbiobj.hpp

📁 ncbi源码
💻 HPP
📖 第 1 页 / 共 4 页
字号:
    inline    CConstRef(ENull /*null*/) THROWS_NONE        : m_Ptr(0)        {        }    /// Constructor for explicit type conversion from pointer to object.    explicit CConstRef(TObjectType* ptr)        {            if ( ptr )                CRefBase<C>::AddReference(ptr);            m_Ptr = ptr;        }    /// Constructor from an existing CRef object,     CConstRef(const CConstRef<C>& ref)        {            TObjectType* ptr = ref.m_Ptr;            if ( ptr )                CRefBase<C>::AddReference(ptr);            m_Ptr = ptr;        }    /// Constructor from an existing CRef object,     CConstRef(const CRef<C>& ref)        {            TObjectType* ptr = ref.GetPointerOrNull();            if ( ptr )                CRefBase<C>::AddReference(ptr);            m_Ptr = ptr;        }    /// Destructor.    ~CConstRef(void)        {            TObjectType* ptr = m_Ptr;            if ( ptr )                CRefBase<C>::RemoveReference(ptr);        }        /// Check if CConstRef is empty -- not pointing to any object which means    /// having a null value.     ///    /// @sa    ///   IsNull()    bool Empty(void) const THROWS_NONE        {            return m_Ptr == 0;        }    /// Check if CConstRef is not empty -- pointing to an object and has    /// a non-null value.     bool NotEmpty(void) const THROWS_NONE        {            return m_Ptr != 0;        }    /// Check if pointer is null -- same affect as Empty().    ///    /// @sa    ///   Empty()    bool IsNull(void) const THROWS_NONE        {            return m_Ptr == 0;        }    /// Operator to test object.    ///    /// @return    ///   TRUE if there is a pointer to object; FALSE, otherwise.    operator bool(void) THROWS_NONE        {            return NotEmpty();        }    /// Operator to test object.    ///    /// @return    ///   TRUE if there is a pointer to object; FALSE, otherwise.    operator bool(void) const THROWS_NONE        {            return NotEmpty();        }    /// Operator to test object -- const version.    ///    /// @return    ///   TRUE if there is a null pointer to object; FALSE, otherwise.    bool operator!(void) const THROWS_NONE        {            return Empty();        }    /// Reset reference object.    ///    /// This sets the pointer to object to null, and removes reference    /// count to object and deletes the object if this is the last reference    /// to the object.    /// @sa    ///   Reset(TObjectType*)    inline    void Reset(void)        {            TObjectType* ptr = m_Ptr;            if ( ptr ) {                m_Ptr = 0;                CRefBase<C>::RemoveReference(ptr);            }        }    /// Reset reference object to new pointer.    ///    /// This sets the pointer to object to the new pointer, and removes    /// reference count to old object and deletes the old object if this is    /// the last reference to the old object.    /// @sa    ///   Reset()    inline    void Reset(TObjectType* newPtr)        {            TObjectType* oldPtr = m_Ptr;            if ( newPtr != oldPtr ) {                if ( newPtr )                    CRefBase<C>::AddReference(newPtr);                m_Ptr = newPtr;                if ( oldPtr )                    CRefBase<C>::RemoveReference(oldPtr);            }        }    /// Release a reference to the object and return a pointer to the object.    ///    /// Releasing a reference means decreasing the reference count by "1". A    /// pointer to the existing object is returned, unless this pointer is    /// already null(0), in which case a null(0) is returned.    ///    /// Similar to Release(), except that this method returns a null,    /// whereas Release() throws a null pointer exception.    ///    /// @sa    ///   Release()    inline    TObjectType* ReleaseOrNull(void)        {            TObjectType* ptr = m_Ptr;            if ( !ptr )                return 0;            m_Ptr = 0;            CRefBase<C>::ReleaseReference(ptr);            return ptr;        }    /// Release a reference to the object and return a pointer to the object.    ///    /// Releasing a reference means decreasing the reference count by "1". A    /// pointer to the existing object is returned, unless this pointer is    /// already null(0), in which the null pointer exception (eNullPtr) is    /// thrown.    ///    /// Similar to ReleaseOrNull(), except that this method throws an exception    /// whereas ReleaseOrNull() does not.    ///    /// @sa    ///   ReleaseOrNull()    inline    TObjectType* Release(void)        {            TObjectType* ptr = m_Ptr;            if ( !ptr ) {                CObject::ThrowNullPointerException();            }            m_Ptr = 0;            CRefBase<C>::ReleaseReference(ptr);            return ptr;        }    /// Reset reference object to new pointer.    ///    /// This sets the pointer to object to the new pointer, and removes    /// reference count to old object and deletes the old object if this is    /// the last reference to the old object.    /// The new pointer is got from ref argument.    /// Operation is atomic on this object, so that AtomicResetFrom() and    /// AtomicReleaseTo() called from different threads will work properly.    /// Operation is not atomic on ref argument.    /// @sa    ///   AtomicReleaseTo(CConstRef& ref);    inline    void AtomicResetFrom(const CConstRef& ref)        {            TObjectType* ptr = ref.m_Ptr;            if ( ptr )                CRefBase<C>::AddReference(ptr); // for this            TObjectType* old_ptr = AtomicSwap(ptr);            if ( old_ptr )                CRefBase<C>::RemoveReference(old_ptr);        }    /// Release referenced object to another CConstRef<> object.    ///    /// This copies the pointer to object to the argument ref,    /// and release reference from this object.    /// Old reference object held by argument ref is released and deleted if    /// necessary.    /// Operation is atomic on this object, so that AtomicResetFrom() and    /// AtomicReleaseTo() called from different threads will work properly.    /// Operation is not atomic on ref argument.    /// @sa    ///   AtomicResetFrom(const CConstRef& ref);    inline    void AtomicReleaseTo(CConstRef& ref)        {            TObjectType* old_ptr = AtomicSwap(0);            if ( old_ptr ) {                ref.Reset(old_ptr);                CRefBase<C>::RemoveReference(old_ptr);            }            else {                ref.Reset();            }        }    /// Assignment operator for const references.    CConstRef<C>& operator=(const CConstRef<C>& ref)        {            Reset(ref.m_Ptr);            return *this;        }    /// Assignment operator for assigning a reference to a const reference.    CConstRef<C>& operator=(const CRef<C>& ref)        {            Reset(ref.GetPointerOrNull());            return *this;        }    /// Assignment operator for const references with right hand side set to    /// a pointer.    CConstRef<C>& operator=(TObjectType* ptr)        {            Reset(ptr);            return *this;        }    /// Assignment operator with right hand side set to ENull.    CConstRef<C>& operator=(ENull /*null*/)        {            Reset(0);            return *this;        }    /// Get pointer value and throw a null pointer exception if pointer    /// is null.    ///    /// Similar to GetPointerOrNull() except that this method throws a null    /// pointer exception if pointer is null, whereas GetPointerOrNull()    /// returns a null value.    ///    /// @sa    ///   GetPointerOrNull(), GetPointer(), GetObject()    inline    TObjectType* GetNonNullPointer(void) const        {            TObjectType* ptr = m_Ptr;            if ( !ptr ) {                CObject::ThrowNullPointerException();            }            return ptr;        }    /// Get pointer value.    ///    /// Similar to GetNonNullPointer() except that this method returns a null    /// if the pointer is null, whereas GetNonNullPointer() throws a null    /// pointer exception.    ///    /// @sa    ///   GetNonNullPointer()    inline    TObjectType* GetPointerOrNull(void) const THROWS_NONE        {            return m_Ptr;        }    /// Get pointer,    ///    /// Same as GetPointerOrNull().    ///    /// @sa    ///   GetPointerOrNull()    inline    TObjectType* GetPointer(void) const THROWS_NONE        {            return GetPointerOrNull();        }    /// Get object.    ///    /// Similar to GetNonNullPointer(), except that this method returns the    /// object whereas GetNonNullPointer() returns a pointer to the object.    ///     /// @sa    ///   GetNonNullPointer()    inline    TObjectType& GetObject(void) const        {            return *GetNonNullPointer();        }    /// Dereference operator returning object.    ///    /// @sa    ///   GetObject()    inline    TObjectType& operator*(void) const        {            return *GetNonNullPointer();        }    /// Reference operator.    ///    /// @sa    ///   GetPointer()    inline    TObjectType* operator->(void) const        {            return GetNonNullPointer();        }    /// Dereference operator returning pointer.    ///    /// @sa    ///   GetPointer()    inline    operator TObjectType*(void) const        {            return GetPointerOrNull();        }private:    TObjectType* AtomicSwap(TObjectType* ptr)        {            // MIPSpro won't accept static_cast for some reason.            return reinterpret_cast<TObjectType*>                (SwapPointers(const_cast<void*volatile*>(                                  const_cast<void**>(                                      reinterpret_cast<const void**>(&m_Ptr))),                              const_cast<C*>(ptr)));        }    TObjectType* m_Ptr;             ///< Pointer to object};/// Template operator < function for CRef objects.template<class T>inlinebool operator< (const CRef<T>& r1, const CRef<T>& r2){    return r1.GetPointerOrNull() < r2.GetPointerOrNull();}/// Template operator > function for CRef objects.template<class T>inlinebool operator> (const CRef<T>& r1, const CRef<T>& r2){    return r1.GetPointerOrNull() > r2.GetPointerOrNull();}/// Template operator == function for CRef objects -- rhs is null.template<class T>inlinebool operator== (const CRef<T>& r1, ENull /*null*/){    return r1.IsNull();}/// Template operator == function for CRef objects -- lhs is null.template<class T>inlinebool operator== (ENull /*null*/, const CRef<T>& r1){    return r1.IsNull();}/// Template operator != function for CRef objects -- rhs is null.template<class T>inlinebool operator!= (const CRef<T>& r1, ENull /*null*/){    return !r1.IsNull();}/// Template operator != function for CRef objects -- lhs is null.template<class T>inlinebool operator!= (ENull /*null*/, const CRef<T>& r1){    return !r1.IsNull();}/// Template operator < function for CConstRef objects.

⌨️ 快捷键说明

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