c99ad5d7 |
1 | // Copyright (c) 2020 OPEN CASCADE SAS |
2 | // |
3 | // This file is part of Open CASCADE Technology software library. |
4 | // |
5 | // This library is free software; you can redistribute it and/or modify it under |
6 | // the terms of the GNU Lesser General Public License version 2.1 as published |
7 | // by the Free Software Foundation, with special exception defined in the file |
8 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
9 | // distribution for complete text of the license and disclaimer of any warranty. |
10 | // |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
13 | |
14 | #ifndef _XmlMDF_DerivedDriver_HeaderFile |
15 | #define _XmlMDF_DerivedDriver_HeaderFile |
16 | |
17 | #include <XmlMDF_ADriver.hxx> |
18 | #include <TDF_DerivedAttribute.hxx> |
19 | |
20 | //! A universal driver for the attribute that inherits another attribute with |
21 | //! ready to used persistence mechanism implemented (already has a driver to store/retrieve). |
22 | class XmlMDF_DerivedDriver : public XmlMDF_ADriver |
23 | { |
24 | DEFINE_STANDARD_RTTIEXT(XmlMDF_DerivedDriver, XmlMDF_ADriver) |
25 | public: |
26 | //! Creates a derivative persistence driver for theDerivative attribute by reusage of theBaseDriver |
27 | //! @param theDerivative an instance of the attribute, just created, detached from any label |
28 | //! @param theBaseDriver a driver of the base attribute, called by Paste methods |
29 | XmlMDF_DerivedDriver (const Handle(TDF_Attribute)& theDerivative, |
30 | const Handle(XmlMDF_ADriver)& theBaseDriver) |
31 | : XmlMDF_ADriver (theBaseDriver->MessageDriver(), theBaseDriver->Namespace().ToCString()), |
32 | myDerivative (theDerivative), |
33 | myBaseDirver(theBaseDriver) {} |
34 | |
35 | //! Creates a new instance of the derivative attribute |
36 | virtual Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE { return myDerivative->NewEmpty(); } |
37 | |
38 | //! Returns the full XML tag name (including NS prefix) |
39 | const TCollection_AsciiString& TypeName() const |
40 | { |
41 | const TCollection_AsciiString& aRegistered = TDF_DerivedAttribute::TypeName (myDerivative->DynamicType()->Name()); |
42 | if (aRegistered.IsEmpty()) |
43 | { |
44 | return XmlMDF_ADriver::TypeName(); |
45 | } |
46 | return aRegistered; |
47 | } |
48 | |
49 | //! Reuses the base driver to read the base fields |
50 | virtual Standard_Boolean Paste (const XmlObjMgt_Persistent& theSource, |
51 | const Handle(TDF_Attribute)& theTarget, |
52 | XmlObjMgt_RRelocationTable& theRelocTable) const Standard_OVERRIDE |
53 | { |
54 | Standard_Boolean aResult = myBaseDirver->Paste (theSource, theTarget, theRelocTable); |
55 | theTarget->AfterRetrieval(); // to allow synchronization of the derived attribute with the base content |
56 | return aResult; |
57 | } |
58 | |
59 | //! Reuses the base driver to store the base fields |
60 | virtual void Paste (const Handle(TDF_Attribute)& theSource, |
61 | XmlObjMgt_Persistent& theTarget, |
62 | XmlObjMgt_SRelocationTable& theRelocTable) const Standard_OVERRIDE |
63 | { |
64 | myBaseDirver->Paste (theSource, theTarget, theRelocTable); |
65 | } |
66 | |
67 | protected: |
68 | Handle(TDF_Attribute) myDerivative; //!< the derivative attribute that inherits the base |
69 | Handle(XmlMDF_ADriver) myBaseDirver; //!< the base attribute driver to be reused here |
70 | }; |
71 | |
72 | #endif |