00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef TORC_GENERIC_OM_SELFREFERENCING_HPP
00017 #define TORC_GENERIC_OM_SELFREFERENCING_HPP
00018
00019 #include "torc/generic/om/DumpRestoreConfig.hpp"
00020
00021
00022 #include <boost/shared_ptr.hpp>
00023 #include <boost/weak_ptr.hpp>
00024
00025 #ifdef GENOM_SERIALIZATION
00026 #include <boost/serialization/access.hpp>
00027 #include <boost/serialization/weak_ptr.hpp>
00028 #endif //GENOM_SERIALIZATION
00029
00030 namespace torc {
00031 namespace generic {
00032
00033 template <typename _Tp>
00034 class SelfReferencing
00035 {
00036 #ifdef GENOM_SERIALIZATION
00037 friend class boost::serialization::access;
00038 #endif //GENOM_SERIALIZATION
00039
00040 public:
00041 typedef _Tp Type;
00042 typedef boost::shared_ptr<Type> Pointer;
00043 typedef boost::weak_ptr<Type> WeakPointer;
00044
00045
00046
00047
00048
00049
00050 inline void
00051 setWeakThis(const WeakPointer & inWeakThis) throw();
00052
00053
00054
00055
00056
00057
00058 inline Pointer
00059 getSharedThis() const throw();
00060
00061 protected:
00062 SelfReferencing();
00063
00064 public:
00065 ~SelfReferencing() throw();
00066
00067 private:
00068 #ifdef GENOM_SERIALIZATION
00069 template<class Archive> void
00070 serialize( Archive &ar, unsigned int );
00071 #endif //GENOM_SERIALIZATION
00072
00073 WeakPointer mWeakThis;
00074 };
00075
00076 template<typename _Type>
00077 SelfReferencing<_Type>::SelfReferencing()
00078 :mWeakThis() {
00079 }
00080
00081 template<typename _Type>
00082 SelfReferencing<_Type>::~SelfReferencing() throw() {
00083 }
00084
00085
00086
00087
00088
00089
00090 template<typename _Type>
00091 inline void
00092 SelfReferencing<_Type>::setWeakThis(
00093 const SelfReferencing<_Type>::WeakPointer &inWeakThis) throw() {
00094 mWeakThis = inWeakThis;
00095 }
00096
00097
00098
00099
00100
00101
00102 template<typename _Type>
00103 inline typename SelfReferencing<_Type>::Pointer
00104 SelfReferencing<_Type>::getSharedThis() const throw() {
00105 return mWeakThis.lock();
00106 }
00107
00108 #ifdef GENOM_SERIALIZATION
00109 template<typename _Type>
00110 template<class Archive> void
00111 SelfReferencing<_Type>::serialize( Archive &ar, unsigned int ) {
00112 ar & mWeakThis;
00113 }
00114 #endif //GENOM_SERIALIZATION
00115
00116 }
00117 }
00118
00119 #endif // TORC_GENERIC_OM_SELFREFERENCING_HPP