// Copyright (c) 2015 OPEN CASCADE SAS // // This file is part of Open CASCADE Technology software library. // // This library is free software; you can redistribute it and/or modify it under // the terms of the GNU Lesser General Public License version 2.1 as published // by the Free Software Foundation, with special exception defined in the file // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT // distribution for complete text of the license and disclaimer of any warranty. // // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. #ifndef _StdObjMgt_Attribute_HeaderFile #define _StdObjMgt_Attribute_HeaderFile #include "StdObjMgt_Persistent.hxx" #include "StdObjMgt_ReadData.hxx" #include "StdObjMgt_WriteData.hxx" //! Root class for a temporary persistent object corresponding to an attribute. template class StdObjMgt_Attribute : public Standard_Transient { class base : public StdObjMgt_Persistent { public: //! Create an empty transient attribute occ::handle CreateAttribute() override { return myTransient = new Transient; } //! Get transient attribute for the persistent data occ::handle GetAttribute() const override { return occ::handle(myTransient); } protected: occ::handle myTransient; }; public: class Static : public base { }; template class Simple : public Static { public: //! Read persistent data from a file. void Read(StdObjMgt_ReadData& theReadData) override { theReadData >> myData; } //! Write persistent data to a file. void Write(StdObjMgt_WriteData& theWriteData) const override { theWriteData << myData; } void PChildren(StdObjMgt_Persistent::SequenceOfPersistent&) const override {} const char* PName() const override { return "StdObjMgt_Attribute::undefined"; } protected: DataType myData; }; struct SingleInt : Simple { }; struct SingleRef : Simple> { }; private: template class container : public base { public: //! Read persistent data from a file. void Read(StdObjMgt_ReadData& theReadData) override { myPersistent = new Persistent; myPersistent->Read(theReadData); } //! Write persistent data to a file. void Write(StdObjMgt_WriteData& theWriteData) const override { myPersistent->Write(theWriteData); } void PChildren(StdObjMgt_Persistent::SequenceOfPersistent&) const override {} const char* PName() const override { return myPersistent->PName(); } //! Import transient attribute from the persistent data void ImportAttribute() override { if (myPersistent && this->myTransient) { myPersistent->Import(this->myTransient); myPersistent.Nullify(); } } private: occ::handle myPersistent; }; public: template static occ::handle Instantiate() { return new container; } }; #endif // _StdObjMgt_Attribute_HeaderFile