Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // Copyright (c) 2020 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 _XmlMDF_DerivedDriver_HeaderFile
0015 #define _XmlMDF_DerivedDriver_HeaderFile
0016 
0017 #include <XmlMDF_ADriver.hxx>
0018 #include <TDF_DerivedAttribute.hxx>
0019 
0020 //! A universal driver for the attribute that inherits another attribute with
0021 //! ready to used persistence mechanism implemented (already has a driver to store/retrieve).
0022 class XmlMDF_DerivedDriver : public XmlMDF_ADriver
0023 {
0024   DEFINE_STANDARD_RTTIEXT(XmlMDF_DerivedDriver, XmlMDF_ADriver)
0025 public:
0026   //! Creates a derivative persistence driver for theDerivative attribute by reusage of theBaseDriver
0027   //! @param theDerivative an instance of the attribute, just created, detached from any label
0028   //! @param theBaseDriver a driver of the base attribute, called by Paste methods
0029   XmlMDF_DerivedDriver (const Handle(TDF_Attribute)&  theDerivative,
0030                         const Handle(XmlMDF_ADriver)& theBaseDriver)
0031   : XmlMDF_ADriver (theBaseDriver->MessageDriver(), theBaseDriver->Namespace().ToCString()),
0032     myDerivative (theDerivative),
0033     myBaseDirver(theBaseDriver) {}
0034 
0035   //! Creates a new instance of the derivative attribute
0036   virtual Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE { return myDerivative->NewEmpty(); }
0037 
0038   //! Returns the full XML tag name (including NS prefix)
0039   const TCollection_AsciiString& TypeName() const
0040   {
0041     const TCollection_AsciiString& aRegistered = TDF_DerivedAttribute::TypeName (myDerivative->DynamicType()->Name());
0042     if (aRegistered.IsEmpty())
0043     {
0044       return XmlMDF_ADriver::TypeName();
0045     }
0046     return aRegistered;
0047   }
0048 
0049   //! Reuses the base driver to read the base fields
0050   virtual Standard_Boolean Paste (const XmlObjMgt_Persistent&  theSource,
0051                                   const Handle(TDF_Attribute)& theTarget,
0052                                   XmlObjMgt_RRelocationTable&  theRelocTable) const Standard_OVERRIDE
0053   {
0054     Standard_Boolean aResult = myBaseDirver->Paste (theSource, theTarget, theRelocTable);
0055     theTarget->AfterRetrieval(); // to allow synchronization of the derived attribute with the base content
0056     return aResult;
0057   }
0058 
0059   //! Reuses the base driver to store the base fields
0060   virtual void Paste (const Handle(TDF_Attribute)& theSource,
0061                       XmlObjMgt_Persistent& theTarget,
0062                       XmlObjMgt_SRelocationTable& theRelocTable) const Standard_OVERRIDE
0063   {
0064     myBaseDirver->Paste (theSource, theTarget, theRelocTable);
0065   }
0066 
0067 protected:
0068   Handle(TDF_Attribute)  myDerivative; //!< the derivative attribute that inherits the base
0069   Handle(XmlMDF_ADriver) myBaseDirver; //!< the base attribute driver to be reused here
0070 };
0071 
0072 #endif