Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:05:00

0001 // Copyright (c) 2015 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
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 //! Root class for a temporary persistent object corresponding to an attribute.
0023 template <class Transient>
0024 class StdObjMgt_Attribute : public Standard_Transient
0025 {
0026   class base : public StdObjMgt_Persistent
0027   {
0028   public:
0029     //! Create an empty transient attribute
0030     virtual Handle(TDF_Attribute) CreateAttribute()
0031       { return myTransient = new Transient; }
0032 
0033     //! Get transient attribute for the persistent data
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     //! Read persistent data from a file.
0049     virtual void Read (StdObjMgt_ReadData& theReadData)
0050       { theReadData >> myData; }
0051     //! Write persistent data to a file.
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     //! Read persistent data from a file.
0070     virtual void Read (StdObjMgt_ReadData& theReadData)
0071     {
0072       myPersistent = new Persistent;
0073       myPersistent->Read (theReadData);
0074     }
0075     //! Write persistent data to a file.
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     //! Import transient attribute from the persistent data
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 // _StdObjMgt_Attribute_HeaderFile