0022627: Change OCCT memory management defaults
[occt.git] / src / BinMFunction / BinMFunction_GraphNodeDriver.cxx
CommitLineData
7fd59977 1// File: BinMFunction_GraphNodeDriver.cxx
2// Created: Thu May 11 11:26:02 2008
3// Author: Vlad Romashko <vladislav.romashko@opencascade.com>
4// Copyright: Open CasCade S.A. 2008
5
6
7#include <BinMFunction_GraphNodeDriver.ixx>
8#include <CDM_MessageDriver.hxx>
9#include <TDF_Attribute.hxx>
10#include <TFunction_GraphNode.hxx>
11#include <BinMDF_ADriver.hxx>
12#include <BinObjMgt_Persistent.hxx>
13#include <BinObjMgt_RRelocationTable.hxx>
14#include <BinObjMgt_SRelocationTable.hxx>
15#include <TColStd_Array1OfInteger.hxx>
16#include <TColStd_MapIteratorOfMapOfInteger.hxx>
17
18//=======================================================================
19//function : BinMFunction_GraphNodeDriver
20//purpose :
21//=======================================================================
22
23BinMFunction_GraphNodeDriver::BinMFunction_GraphNodeDriver(const Handle(CDM_MessageDriver)& theMsgDriver)
24: BinMDF_ADriver (theMsgDriver, STANDARD_TYPE(TFunction_GraphNode)->Name())
25{
26}
27
28//=======================================================================
29//function : NewEmpty
30//purpose :
31//=======================================================================
32
33Handle(TDF_Attribute) BinMFunction_GraphNodeDriver::NewEmpty() const
34{
35 return new TFunction_GraphNode();
36}
37
38//=======================================================================
39//function : Paste
40//purpose : persistent -> transient (retrieve)
41//=======================================================================
42
43Standard_Boolean BinMFunction_GraphNodeDriver::Paste(const BinObjMgt_Persistent& theSource,
44 const Handle(TDF_Attribute)& theTarget,
45 BinObjMgt_RRelocationTable& ) const
46{
47 Handle(TFunction_GraphNode) GN = Handle(TFunction_GraphNode)::DownCast(theTarget);
48
49 Standard_Integer intStatus, nb_previous, nb_next;
50 if (! (theSource >> intStatus >> nb_previous >> nb_next))
51 return Standard_False;
52
53 // Execution status
54 GN->SetStatus((TFunction_ExecutionStatus) intStatus);
55
56 // Previous functions
57 if (nb_previous)
58 {
59 TColStd_Array1OfInteger aTargetArray(1, nb_previous);
60 theSource.GetIntArray (&aTargetArray(1), nb_previous);
61
62 for (Standard_Integer i = 1; i <= nb_previous; i++)
63 {
64 GN->AddPrevious(aTargetArray.Value(i));
65 }
66 }
67
68 // Next functions
69 if (nb_next)
70 {
71 TColStd_Array1OfInteger aTargetArray(1, nb_next);
72 theSource.GetIntArray (&aTargetArray(1), nb_next);
73
74 for (Standard_Integer i = 1; i <= nb_next; i++)
75 {
76 GN->AddNext(aTargetArray.Value(i));
77 }
78 }
79
80 return Standard_True;
81}
82
83//=======================================================================
84//function : Paste
85//purpose : transient -> persistent (store)
86//=======================================================================
87
88void BinMFunction_GraphNodeDriver::Paste (const Handle(TDF_Attribute)& theSource,
89 BinObjMgt_Persistent& theTarget,
90 BinObjMgt_SRelocationTable& ) const
91{
92 Handle(TFunction_GraphNode) GN = Handle(TFunction_GraphNode)::DownCast(theSource);
93
94 // Execution status
95 theTarget << (Standard_Integer) GN->GetStatus();
96 // Number of previous functions
97 theTarget << GN->GetPrevious().Extent();
98 // Number of next functions
99 theTarget << GN->GetNext().Extent();
100
101 // Previous functions
102 Standard_Integer nb = GN->GetPrevious().Extent();
103 if (nb)
104 {
105 TColStd_Array1OfInteger aSourceArray(1, nb);
106 TColStd_MapIteratorOfMapOfInteger itr(GN->GetPrevious());
107 for (Standard_Integer i = 1; itr.More(); itr.Next(), i++)
108 {
109 aSourceArray.SetValue(i, itr.Key());
110 }
111 Standard_Integer *aPtr = (Standard_Integer *) &aSourceArray(1);
112 theTarget.PutIntArray(aPtr, nb);
113 }
114
115 // Next functions
116 nb = GN->GetNext().Extent();
117 if (nb)
118 {
119 TColStd_Array1OfInteger aSourceArray(1, nb);
120 TColStd_MapIteratorOfMapOfInteger itr(GN->GetNext());
121 for (Standard_Integer i = 1; itr.More(); itr.Next(), i++)
122 {
123 aSourceArray.SetValue(i, itr.Key());
124 }
125 Standard_Integer *aPtr = (Standard_Integer *) &aSourceArray(1);
126 theTarget.PutIntArray(aPtr, nb);
127 }
128}
129