File indexing completed on 2025-01-18 10:05:00
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef _StdObjMgt_SharedObject_HeaderFile
0016 #define _StdObjMgt_SharedObject_HeaderFile
0017
0018 #include <Standard_NoSuchObject.hxx>
0019 #include <StdObjMgt_Persistent.hxx>
0020
0021 class StdObjMgt_SharedObject
0022 {
0023 public:
0024 template <class Transient>
0025 class AbstractPersistentBase : public Standard_Transient
0026 {
0027 public:
0028 virtual Handle(Transient) Import() const = 0;
0029 };
0030
0031 template <class TransientT, class Base = StdObjMgt_Persistent>
0032 class SharedBase : public Base
0033 {
0034 public:
0035
0036 inline void Transient(const Handle(TransientT)& theTransient)
0037 { myTransient = theTransient; }
0038
0039
0040 inline const Handle(TransientT)& Import() { return myTransient; }
0041
0042 protected:
0043 Handle(TransientT) myTransient;
0044 };
0045
0046 template <class Base,
0047 class Transient,
0048 class Persistent = AbstractPersistentBase<Transient> >
0049 class DelayedBase : public Base
0050 {
0051 public:
0052 typedef Transient TransientBase;
0053 typedef Persistent PersistentBase;
0054
0055
0056 virtual Handle(Transient) Import()
0057 { return myTransient; }
0058
0059 public:
0060 Handle(Transient) myTransient;
0061 };
0062
0063 template <class Base,
0064 class PersistentData,
0065 class Transient = typename Base::TransientBase>
0066 class IgnoreData : public Base
0067 {
0068 public:
0069
0070 virtual void Read (StdObjMgt_ReadData& theReadData)
0071 { PersistentData().Read (theReadData); }
0072
0073 virtual void Write (StdObjMgt_WriteData& theWriteData) const
0074 { PersistentData().Write (theWriteData); }
0075
0076 virtual void PChildren(StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const
0077 { PersistentData().PChildren(theChildren); }
0078
0079 virtual Standard_CString PName() const
0080 { return PersistentData().PName(); }
0081
0082
0083 virtual Handle(Transient) Import()
0084 { return NULL; }
0085 };
0086
0087 private:
0088 template <class Base>
0089 class delayedSubBase : public Base
0090 {
0091 public:
0092
0093 virtual Handle(typename Base::TransientBase) Import()
0094 {
0095 if (Base::myTransient.IsNull() && !myPersistent.IsNull())
0096 {
0097 Base::myTransient = myPersistent->Import();
0098 myPersistent.Nullify();
0099 }
0100
0101 return Base::myTransient;
0102 }
0103
0104 public:
0105 Handle(typename Base::PersistentBase) myPersistent;
0106 };
0107
0108 public:
0109 template <class Base, class Persistent = typename Base::PersistentBase>
0110 class Delayed : public delayedSubBase<Base>
0111 {
0112 private:
0113 template <class T1, class T2>
0114 struct DownCast {
0115 static Handle(T1) make(const Handle(T2)& theT2)
0116 { return Handle(T1)::DownCast(theT2); }
0117 };
0118
0119 template <class T>
0120 struct DownCast<T, T> {
0121 static Handle(T) make(const Handle(T)& theT)
0122 { return theT; }
0123 };
0124
0125 public:
0126
0127 virtual void Read (StdObjMgt_ReadData& theReadData)
0128 {
0129 Handle(Persistent) aPersistent = new Persistent;
0130 aPersistent->Read (theReadData);
0131 this->myPersistent = aPersistent;
0132 }
0133
0134 virtual void Write(StdObjMgt_WriteData& theWriteData) const
0135 {
0136 Handle(Persistent) aPersistent =
0137 DownCast<Persistent, typename Base::PersistentBase>::make(this->myPersistent);
0138 Standard_NoSuchObject_Raise_if(aPersistent.IsNull(),
0139 "StdObjMgt_SharedObject::Delayed::Write - persistent object wasn't set for writing!");
0140 aPersistent->Write(theWriteData);
0141 }
0142
0143 virtual void PChildren(StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const
0144 {
0145 Handle(Persistent) aPersistent =
0146 DownCast<Persistent, typename Base::PersistentBase>::make(this->myPersistent);
0147 Standard_NoSuchObject_Raise_if(aPersistent.IsNull(),
0148 "StdObjMgt_SharedObject::Delayed::PChildren - persistent object wasn't set for writing!");
0149 aPersistent->PChildren(theChildren);
0150 }
0151
0152 virtual Standard_CString PName() const
0153 {
0154 Handle(Persistent) aPersistent =
0155 DownCast<Persistent, typename Base::PersistentBase>::make(this->myPersistent);
0156 Standard_NoSuchObject_Raise_if(aPersistent.IsNull(),
0157 "StdObjMgt_SharedObject::Delayed::PName - persistent object wasn't set for writing!");
0158 return aPersistent->PName();
0159 }
0160 };
0161 };
0162
0163 #endif