Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-19 09:29:56

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
0027   //! theBaseDriver
0028   //! @param theDerivative an instance of the attribute, just created, detached from any label
0029   //! @param theBaseDriver a driver of the base attribute, called by Paste methods
0030   XmlMDF_DerivedDriver(const occ::handle<TDF_Attribute>&  theDerivative,
0031                        const occ::handle<XmlMDF_ADriver>& theBaseDriver)
0032       : XmlMDF_ADriver(theBaseDriver->MessageDriver(), theBaseDriver->Namespace().ToCString()),
0033         myDerivative(theDerivative),
0034         myBaseDirver(theBaseDriver)
0035   {
0036   }
0037 
0038   //! Creates a new instance of the derivative attribute
0039   occ::handle<TDF_Attribute> NewEmpty() const override { return myDerivative->NewEmpty(); }
0040 
0041   //! Returns the full XML tag name (including NS prefix)
0042   const TCollection_AsciiString& TypeName() const
0043   {
0044     const TCollection_AsciiString& aRegistered =
0045       TDF_DerivedAttribute::TypeName(myDerivative->DynamicType()->Name());
0046     if (aRegistered.IsEmpty())
0047     {
0048       return XmlMDF_ADriver::TypeName();
0049     }
0050     return aRegistered;
0051   }
0052 
0053   //! Reuses the base driver to read the base fields
0054   bool Paste(const XmlObjMgt_Persistent&       theSource,
0055              const occ::handle<TDF_Attribute>& theTarget,
0056              XmlObjMgt_RRelocationTable&       theRelocTable) const override
0057   {
0058     bool aResult = myBaseDirver->Paste(theSource, theTarget, theRelocTable);
0059     // clang-format off
0060     theTarget->AfterRetrieval(); // to allow synchronization of the derived attribute with the base content
0061     // clang-format on
0062     return aResult;
0063   }
0064 
0065   //! Reuses the base driver to store the base fields
0066   void Paste(const occ::handle<TDF_Attribute>& theSource,
0067              XmlObjMgt_Persistent&             theTarget,
0068              XmlObjMgt_SRelocationTable&       theRelocTable) const override
0069   {
0070     myBaseDirver->Paste(theSource, theTarget, theRelocTable);
0071   }
0072 
0073 protected:
0074   occ::handle<TDF_Attribute>  myDerivative; //!< the derivative attribute that inherits the base
0075   occ::handle<XmlMDF_ADriver> myBaseDirver; //!< the base attribute driver to be reused here
0076 };
0077 
0078 #endif