lean cpp library
A lean C++ library providing efficient utility classes for high-performance C++ applications.
|
00001 /*****************************************************/ 00002 /* lean Tags (c) Tobias Zirr 2011 */ 00003 /*****************************************************/ 00004 00005 #ifndef LEAN_TAGS_TRANSITIVE_PTR 00006 #define LEAN_TAGS_TRANSITIVE_PTR 00007 00008 #include "../lean.h" 00009 #include "../meta/conditional.h" 00010 00011 namespace lean 00012 { 00013 namespace tags 00014 { 00015 00017 template <class Type, bool Immutable = false> 00018 class transitive_ptr 00019 { 00020 private: 00021 typename lean::conditional_type<Immutable, Type *const, Type*>::type m_object; 00022 00023 public: 00025 typedef Type object_type; 00027 typedef object_type* value_type; 00029 typedef const object_type* const_value_type; 00030 00032 LEAN_INLINE transitive_ptr(object_type *object = nullptr) 00033 : m_object( object ) { }; 00035 template <class Type2> 00036 LEAN_INLINE transitive_ptr(Type2 *object) 00037 : m_object( object ) { }; 00039 template <class Type2> 00040 LEAN_INLINE transitive_ptr(const transitive_ptr<Type2> &right) 00041 : m_object( right.get() ) { }; 00042 00044 transitive_ptr& operator =(object_type *object) 00045 { 00046 m_object = object; 00047 return *this; 00048 } 00050 template <class Type2> 00051 transitive_ptr& operator =(const transitive_ptr<Type2> &right) 00052 { 00053 return (*this = right.get()); 00054 } 00055 00057 LEAN_INLINE const value_type& get() { return m_object; } 00059 LEAN_INLINE const const_value_type& get() const { return m_object; } 00060 00062 LEAN_INLINE object_type& operator *() { return *get(); } 00064 LEAN_INLINE const object_type& operator *() const { return *get(); } 00065 00067 LEAN_INLINE object_type* operator ->() { return get(); } 00069 LEAN_INLINE const object_type* operator ->() const { return get(); } 00070 00072 LEAN_INLINE operator value_type() { return get(); } 00074 LEAN_INLINE operator const_value_type() const { return get(); } 00075 }; 00076 00077 } // namespace 00078 00079 using tags::transitive_ptr; 00080 00081 } // namespace 00082 00083 #endif