1 // Created on: 2008-05-11
2 // Created by: Vlad Romashko
3 // Copyright (c) 2008-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
17 #include <BinMDF_ADriver.hxx>
18 #include <BinMFunction_GraphNodeDriver.hxx>
19 #include <BinObjMgt_Persistent.hxx>
20 #include <BinObjMgt_RRelocationTable.hxx>
21 #include <BinObjMgt_SRelocationTable.hxx>
22 #include <CDM_MessageDriver.hxx>
23 #include <Standard_Type.hxx>
24 #include <TColStd_Array1OfInteger.hxx>
25 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
26 #include <TDF_Attribute.hxx>
27 #include <TFunction_GraphNode.hxx>
29 IMPLEMENT_STANDARD_RTTIEXT(BinMFunction_GraphNodeDriver,BinMDF_ADriver)
31 //=======================================================================
32 //function : BinMFunction_GraphNodeDriver
34 //=======================================================================
35 BinMFunction_GraphNodeDriver::BinMFunction_GraphNodeDriver(const Handle(CDM_MessageDriver)& theMsgDriver)
36 : BinMDF_ADriver (theMsgDriver, STANDARD_TYPE(TFunction_GraphNode)->Name())
40 //=======================================================================
43 //=======================================================================
45 Handle(TDF_Attribute) BinMFunction_GraphNodeDriver::NewEmpty() const
47 return new TFunction_GraphNode();
50 //=======================================================================
52 //purpose : persistent -> transient (retrieve)
53 //=======================================================================
55 Standard_Boolean BinMFunction_GraphNodeDriver::Paste(const BinObjMgt_Persistent& theSource,
56 const Handle(TDF_Attribute)& theTarget,
57 BinObjMgt_RRelocationTable& ) const
59 Handle(TFunction_GraphNode) GN = Handle(TFunction_GraphNode)::DownCast(theTarget);
61 Standard_Integer intStatus, nb_previous, nb_next;
62 if (! (theSource >> intStatus >> nb_previous >> nb_next))
63 return Standard_False;
66 GN->SetStatus((TFunction_ExecutionStatus) intStatus);
71 TColStd_Array1OfInteger aTargetArray(1, nb_previous);
72 theSource.GetIntArray (&aTargetArray(1), nb_previous);
74 for (Standard_Integer i = 1; i <= nb_previous; i++)
76 GN->AddPrevious(aTargetArray.Value(i));
83 TColStd_Array1OfInteger aTargetArray(1, nb_next);
84 theSource.GetIntArray (&aTargetArray(1), nb_next);
86 for (Standard_Integer i = 1; i <= nb_next; i++)
88 GN->AddNext(aTargetArray.Value(i));
95 //=======================================================================
97 //purpose : transient -> persistent (store)
98 //=======================================================================
100 void BinMFunction_GraphNodeDriver::Paste (const Handle(TDF_Attribute)& theSource,
101 BinObjMgt_Persistent& theTarget,
102 BinObjMgt_SRelocationTable& ) const
104 Handle(TFunction_GraphNode) GN = Handle(TFunction_GraphNode)::DownCast(theSource);
107 theTarget << (Standard_Integer) GN->GetStatus();
108 // Number of previous functions
109 theTarget << GN->GetPrevious().Extent();
110 // Number of next functions
111 theTarget << GN->GetNext().Extent();
113 // Previous functions
114 Standard_Integer nb = GN->GetPrevious().Extent();
117 TColStd_Array1OfInteger aSourceArray(1, nb);
118 TColStd_MapIteratorOfMapOfInteger itr(GN->GetPrevious());
119 for (Standard_Integer i = 1; itr.More(); itr.Next(), i++)
121 aSourceArray.SetValue(i, itr.Key());
123 Standard_Integer *aPtr = (Standard_Integer *) &aSourceArray(1);
124 theTarget.PutIntArray(aPtr, nb);
128 nb = GN->GetNext().Extent();
131 TColStd_Array1OfInteger aSourceArray(1, nb);
132 TColStd_MapIteratorOfMapOfInteger itr(GN->GetNext());
133 for (Standard_Integer i = 1; itr.More(); itr.Next(), i++)
135 aSourceArray.SetValue(i, itr.Key());
137 Standard_Integer *aPtr = (Standard_Integer *) &aSourceArray(1);
138 theTarget.PutIntArray(aPtr, nb);