0030773: Application Framework - To allow to inherit existing attributes to reuse...
[occt.git] / src / BinMDF / BinMDF_DerivedDriver.hxx
CommitLineData
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 _BinMDF_DerivedDriver_HeaderFile
15#define _BinMDF_DerivedDriver_HeaderFile
16
17#include <BinMDF_ADriver.hxx>
18
19//! A universal driver for the attribute that inherits another attribute with
20//! ready to used persistence mechanism implemented (already has a driver to store/retrieve).
21class BinMDF_DerivedDriver : public BinMDF_ADriver
22{
23 DEFINE_STANDARD_RTTIEXT(BinMDF_DerivedDriver, BinMDF_ADriver)
24public:
25
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 BinMDF_DerivedDriver (const Handle(TDF_Attribute)& theDerivative,
30 const Handle(BinMDF_ADriver)& theBaseDriver)
31 : BinMDF_ADriver(theBaseDriver->MessageDriver()), myDerivative(theDerivative), myBaseDirver(theBaseDriver) {}
32
33 //! Creates a new instance of the derivative attribute
34 virtual Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE { return myDerivative->NewEmpty(); }
35
36 //! Reuses the base driver to read the base fields
37 virtual Standard_Boolean Paste (const BinObjMgt_Persistent& theSource,
38 const Handle(TDF_Attribute)& theTarget,
39 BinObjMgt_RRelocationTable& theRelocTable) const Standard_OVERRIDE
40 {
41 Standard_Boolean aResult = myBaseDirver->Paste (theSource, theTarget, theRelocTable);
42 theTarget->AfterRetrieval(); // to allow synchronization of the derived attribute with the base content
43 return aResult;
44 }
45
46 //! Reuses the base driver to store the base fields
47 virtual void Paste (const Handle(TDF_Attribute)& theSource,
48 BinObjMgt_Persistent& theTarget,
49 BinObjMgt_SRelocationTable& theRelocTable) const Standard_OVERRIDE
50 {
51 myBaseDirver->Paste(theSource, theTarget, theRelocTable);
52 }
53
54protected:
55 Handle(TDF_Attribute) myDerivative; //!< the derivative attribute that inherits the base
56 Handle(BinMDF_ADriver) myBaseDirver; //!< the base attribute driver to be reused here
57};
58
59#endif