File indexing completed on 2025-01-18 10:05:00
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef _StdObjMgt_Attribute_HeaderFile
0015 #define _StdObjMgt_Attribute_HeaderFile
0016
0017 #include <StdObjMgt_Persistent.hxx>
0018 #include <StdObjMgt_ReadData.hxx>
0019 #include <StdObjMgt_WriteData.hxx>
0020
0021
0022
0023 template <class Transient>
0024 class StdObjMgt_Attribute : public Standard_Transient
0025 {
0026 class base : public StdObjMgt_Persistent
0027 {
0028 public:
0029
0030 virtual Handle(TDF_Attribute) CreateAttribute()
0031 { return myTransient = new Transient; }
0032
0033
0034 virtual Handle(TDF_Attribute) GetAttribute() const
0035 { return Handle(TDF_Attribute)(myTransient); }
0036
0037 protected:
0038 Handle(Transient) myTransient;
0039 };
0040
0041 public:
0042 class Static : public base {};
0043
0044 template <class DataType>
0045 class Simple : public Static
0046 {
0047 public:
0048
0049 virtual void Read (StdObjMgt_ReadData& theReadData)
0050 { theReadData >> myData; }
0051
0052 virtual void Write (StdObjMgt_WriteData& theWriteData) const
0053 { theWriteData << myData; }
0054 virtual void PChildren(StdObjMgt_Persistent::SequenceOfPersistent&) const { }
0055 virtual Standard_CString PName() const { return "StdObjMgt_Attribute::undefined"; }
0056
0057 protected:
0058 DataType myData;
0059 };
0060
0061 struct SingleInt : Simple<Standard_Integer> {};
0062 struct SingleRef : Simple<Handle(StdObjMgt_Persistent)> {};
0063
0064 private:
0065 template <class Persistent>
0066 class container : public base
0067 {
0068 public:
0069
0070 virtual void Read (StdObjMgt_ReadData& theReadData)
0071 {
0072 myPersistent = new Persistent;
0073 myPersistent->Read (theReadData);
0074 }
0075
0076 virtual void Write(StdObjMgt_WriteData& theWriteData) const
0077 { myPersistent->Write(theWriteData); }
0078 virtual void PChildren(StdObjMgt_Persistent::SequenceOfPersistent&) const { }
0079 virtual Standard_CString PName() const
0080 { return myPersistent->PName(); }
0081
0082
0083 virtual void ImportAttribute()
0084 {
0085 if (myPersistent && this->myTransient)
0086 {
0087 myPersistent->Import (this->myTransient);
0088 myPersistent.Nullify();
0089 }
0090 }
0091
0092 private:
0093 Handle(Persistent) myPersistent;
0094 };
0095
0096 public:
0097 template <class Persistent>
0098 static Handle(StdObjMgt_Persistent) Instantiate()
0099 { return new container<Persistent>; }
0100 };
0101
0102 #endif