📄 ncbiobj.hpp
字号:
template<class T>inlinebool operator< (const CConstRef<T>& r1, const CConstRef<T>& r2){ return r1.GetPointerOrNull() < r2.GetPointerOrNull();}/// Template operator > function for CConstRef objects.template<class T>inlinebool operator> (const CConstRef<T>& r1, const CConstRef<T>& r2){ return r1.GetPointerOrNull() > r2.GetPointerOrNull();}/// Template operator == function for CConstRef objects -- rhs is null.template<class T>inlinebool operator== (const CConstRef<T>& r1, ENull /*null*/){ return r1.IsNull();}/// Template operator == function for CConstRef objects -- lhs is null.template<class T>inlinebool operator== (ENull /*null*/, const CConstRef<T>& r1){ return r1.IsNull();}/// Template operator != function for CConstRef objects -- rhs is null.template<class T>inlinebool operator!= (const CConstRef<T>& r1, ENull /*null*/){ return !r1.IsNull();}/// Template operator != function for CConstRef objects -- lhs is null.template<class T>inlinebool operator!= (ENull /*null*/, const CConstRef<T>& r1){ return !r1.IsNull();}/// 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 CConstRef objects.template<class T>inlinebool operator== (const CConstRef<T>& r1, const CConstRef<T>& r2){ return r1.GetPointerOrNull() == r2.GetPointerOrNull();}/// Template operator == function for CConstRef and CRef objects.template<class T>inlinebool operator== (const CConstRef<T>& r1, const CRef<T>& r2){ return r1.GetPointerOrNull() == r2.GetPointerOrNull();}/// Template operator == function for CRef and CConstRef objects.template<class T>inlinebool operator== (const CRef<T>& r1, const CConstRef<T>& r2){ return r1.GetPointerOrNull() == r2.GetPointerOrNull();}/// Template operator == function for CRef and CRef objects.template<class T>inlinebool operator!= (const CRef<T>& r1, const CRef<T>& r2){ return r1.GetPointerOrNull() != r2.GetPointerOrNull();}/// Template operator != function for CConstRef objects.template<class T>inlinebool operator!= (const CConstRef<T>& r1, const CConstRef<T>& r2){ return r1.GetPointerOrNull() != r2.GetPointerOrNull();}/// Template operator != function for CConstRef and CRef objects.template<class T>inlinebool operator!= (const CConstRef<T>& r1, const CRef<T>& r2){ return r1.GetPointerOrNull() != r2.GetPointerOrNull();}/// Template operator != function for CRef and CConstRef objects.template<class T>inlinebool operator!= (const CRef<T>& r1, const CConstRef<T>& r2){ return r1.GetPointerOrNull() != r2.GetPointerOrNull();}/// Template function for conversion of object pointer to CReftemplate<class C>inlineCRef<C> Ref(C* object){ return CRef<C>(object);}/// Template function for conversion of const object pointer to CConstReftemplate<class C>inlineCConstRef<C> ConstRef(const C* object){ return CConstRef<C>(object);}/////////////////////////////////////////////////////////////////////////////////// CObjectFor --////// Define a template class whose template parameter is a standard data type /// that will be pointed to.////// The template class defines a private data member of the same type as the/// template parameter, and accessor methods GetData() to retrieve the value/// of this private data member. The class is derived from CObject and/// therefore inherits the reference counter defined in that class. In essence,/// this class serves as a "wrapper" class for standard data types allowing/// reference counted smart pointers to be used for standard data types. template<typename T>class CObjectFor : public CObject{public: typedef T TObjectType; ///< Define alias for template parameter /// Get data as a reference. T& GetData(void) { return m_Data; } /// Get data as a reference -- const version. const T& GetData(void) const { return m_Data; } /// Operator () to get data -- same as GetData(). /// /// @sa /// GetData() operator T& (void) { return GetData(); } /// Operator () to get data -- const version, same as GetData(). /// /// @sa /// GetData() operator const T& (void) const { return GetData(); } /// Assignment operator. T& operator=(const T& data) { m_Data = data; return *this; }private: T m_Data; ///< Data member of template parameter type};/* @} */#include <corelib/ncbiobj.inl>END_NCBI_SCOPE/* * =========================================================================== * $Log: ncbiobj.hpp,v $ * Revision 1000.1 2004/04/13 19:57:54 gouriano * PRODUCTION: UPGRADED [CATCHUP_003] Dev-tree R1.56 * * Revision 1.56 2004/04/06 20:34:23 grichenk * Added atomic release and reset to CRef. * * Revision 1.55 2004/03/10 18:40:21 gorelenk * Added/Removed NCBI_XNCBI_EXPORT prefixes. * * Revision 1.54 2004/03/10 17:34:05 gorelenk * Removed NCBI_XNCBI_EXPORT prefix for classes members-functions * that are implemented as a inline functions. * * Revision 1.53 2003/10/20 20:07:10 siyan * Added CORELIB___ prefix in conditional includes. * * Revision 1.52 2003/10/01 00:24:02 ucko * CConstRef::AtomicSwap: use reinterpret_cast rather than static_cast to * placate MIPSpro. * * Revision 1.51 2003/09/17 17:57:38 vasilche * Added Ref() and ConstRef() templated functions for getting CRef<> objects. * * Revision 1.50 2003/09/17 15:20:45 vasilche * Moved atomic counter swap functions to separate file. * Added CRef<>::AtomicResetFrom(), CRef<>::AtomicReleaseTo() methods. * * Revision 1.49 2003/08/12 13:35:50 siyan * Minor comment changes. * * Revision 1.48 2003/08/12 12:03:48 siyan * Added documentation. Change private method name from AddReferenceOverflow() * to a more meaningful name of its purpose, CheckReferenceOverflow(). * * Revision 1.47 2003/07/17 23:00:50 vasilche * Added matching operator delete. * * Revision 1.46 2003/07/17 20:01:06 vasilche * Added inplace operator new(). * * Revision 1.45 2003/05/18 04:47:09 vakatov * Rollback to R1.43, as R1.44 created another, more problematic warning -- * that "operator T*()" would be chosen over "operator bool()" for non-const * * Revision 1.43 2003/04/01 14:19:58 siyan * Added doxygen support * * Revision 1.42 2002/12/18 22:53:21 dicuccio * Added export specifier for building DLLs in windows. Added global list of * all such specifiers in mswin_exports.hpp, included through ncbistl.hpp * * Revision 1.41 2002/11/27 12:53:14 dicuccio * Added CObject::ThrowNullPointerException to get around some inlining issues. * Fixed a few returns (m_Ptr -> ptr). * * Revision 1.40 2002/11/26 14:25:34 dicuccio * Added more explicit error reporting for thrown exceptions. * * Revision 1.39 2002/11/08 19:43:29 grichenk * CConstRef<> constructor made explicit * * Revision 1.38 2002/11/04 21:30:53 grichenk * Made CRef<> constructor explicit, const CRef<> getters * return const references/pointers. * * Revision 1.37 2002/09/19 20:05:41 vasilche * Safe initialization of static mutexes * * Revision 1.36 2002/08/28 17:05:50 vasilche * Remove virtual inheritance, fixed heap detection * * Revision 1.35 2002/07/15 18:17:51 gouriano * renamed CNcbiException and its descendents * * Revision 1.34 2002/07/11 14:17:55 gouriano * exceptions replaced by CNcbiException-type ones * * Revision 1.33 2002/05/31 15:16:51 gouriano * more unsigned ints in EObjectState flags * * Revision 1.32 2002/05/30 18:32:14 gouriano * changed eStateBitsValid to "unsigned int" to make some compilers happy * * Revision 1.31 2002/05/23 22:24:21 ucko * Use low-level atomic operations for reference counts * * Revision 1.30 2002/05/17 14:25:40 gouriano * added DebugDump base class and function to CObject * * Revision 1.29 2002/05/14 21:12:59 gouriano * DebugDump moved into a separate class * * Revision 1.28 2002/05/14 14:42:13 gouriano * added DebugDump function to CObject * * Revision 1.27 2002/04/11 20:39:18 ivanov * CVS log moved to end of the file * * Revision 1.26 2001/10/10 04:03:22 vakatov * Added operator> for C(Const)Ref -- for ICC and MIPSpro * * Revision 1.25 2001/06/21 15:17:42 kholodov * Added: null special value, support for null in CRef classes, equality * operators. * * Revision 1.24 2001/06/13 14:19:54 grichenk * Added operators == and != for C(Const)Ref * * Revision 1.23 2001/05/17 14:53:56 lavr * Typos corrected * * Revision 1.22 2001/03/26 21:22:51 vakatov * Minor cosmetics * * Revision 1.21 2001/03/13 22:43:48 vakatov * Made "CObject" MT-safe * + CObject::DoDeleteThisObject() * * Revision 1.20 2001/03/05 22:14:18 vakatov * Added "operator<" for CRef:: and CConstRef:: to make them usable * as keys in the stnadard C++ associative containers (set, map, ...) * * Revision 1.19 2001/02/21 21:16:08 grichenk * CRef:: Release, Reset -- reset m_Ptr BEFORE removing the reference * * Revision 1.18 2000/12/26 17:25:38 vasilche * CRef<> returns non const object. * * Revision 1.17 2000/12/15 19:18:36 vakatov * Added assignment operator for CRef<> and CConstRef<> * * Revision 1.16 2000/12/15 15:36:29 vasilche * Added header corelib/ncbistr.hpp for all string utility functions. * Optimized string utility functions. * Added assignment operator to CRef<> and CConstRef<>. * Add Upcase() and Locase() methods for automatic conversion. * * Revision 1.15 2000/12/12 14:20:14 vasilche * Added operator bool to CArgValue. * Added standard typedef element_type to CRef<> and CConstRef<>. * Macro iterate() now calls method end() only once and uses temporary variabl. * Various NStr::Compare() methods made faster. * Added class Upcase for printing strings to ostream with automatic conversion * * Revision 1.14 2000/11/01 20:35:01 vasilche * Fixed detection of heap objects. * Removed ECanDelete enum and related constructors. * * Revision 1.13 2000/10/13 16:25:43 vasilche * Added heuristic for detection of CObject allocation in heap. * * Revision 1.12 2000/09/01 13:14:25 vasilche * Fixed throw() declaration in CRef/CConstRef * * Revision 1.11 2000/08/15 19:42:06 vasilche * Changed reference counter to allow detection of more errors. * * Revision 1.10 2000/06/16 16:29:42 vasilche * Added SetCanDelete() method to allow to change CObject 'in heap' status * immediately after creation. * * Revision 1.9 2000/06/07 19:44:16 vasilche * Removed unneeded THROWS declaration - they lead to encreased code size. * * Revision 1.8 2000/05/09 16:36:54 vasilche * CObject::GetTypeInfo now moved to CObjectGetTypeInfo::GetTypeInfo to reduce * possible errors. * * Revision 1.7 2000/04/28 16:56:13 vasilche * Fixed implementation of CRef<> and CConstRef<> * * Revision 1.6 2000/03/31 17:08:07 kans * moved ECanDelete to public area of CObject * * Revision 1.5 2000/03/29 15:50:27 vasilche * Added const version of CRef - CConstRef. * CRef and CConstRef now accept classes inherited from CObject. * * Revision 1.4 2000/03/10 14:18:37 vasilche * Added CRef<>::GetPointerOrNull() method similar to std::auto_ptr<>.get() * * Revision 1.3 2000/03/08 14:18:19 vasilche * Fixed throws instructions. * * Revision 1.2 2000/03/07 15:25:42 vasilche * Fixed implementation of CRef::-> * * Revision 1.1 2000/03/07 14:03:11 vasilche * Added CObject class as base for reference counted objects. * Added CRef templace for reference to CObject descendant. * * ========================================================================== */#endif /* NCBIOBJ__HPP */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -