Integration of OCCT 6.5.0 from SVN
[occt.git] / src / BinMDataStd / BinMDataStd_RelationDriver.cxx
CommitLineData
7fd59977 1// File: BinMDataStd_RelationDriver.cxx
2// Created: Wed Sep 12 14:07:32 2001
3// Author: Julia DOROVSKIKH
4// Copyright: Open Cascade 2001
5// History:
6
7#include <BinMDataStd_RelationDriver.ixx>
8#include <TDataStd_Relation.hxx>
9#include <TDataStd_Variable.hxx>
10#include <TDF_ListIteratorOfAttributeList.hxx>
11
12//=======================================================================
13//function : BinMDataStd_RelationDriver
14//purpose : Constructor
15//=======================================================================
16BinMDataStd_RelationDriver::BinMDataStd_RelationDriver
17 (const Handle(CDM_MessageDriver)& theMsgDriver)
18 : BinMDF_ADriver (theMsgDriver, NULL)
19{}
20
21//=======================================================================
22//function : NewEmpty
23//purpose :
24//=======================================================================
25Handle(TDF_Attribute) BinMDataStd_RelationDriver::NewEmpty() const
26{
27 return (new TDataStd_Relation());
28}
29
30//=======================================================================
31//function : Paste
32//purpose : persistent -> transient (retrieve)
33//=======================================================================
34Standard_Boolean BinMDataStd_RelationDriver::Paste
35 (const BinObjMgt_Persistent& theSource,
36 const Handle(TDF_Attribute)& theTarget,
37 BinObjMgt_RRelocationTable& theRelocTable) const
38{
39 Handle(TDataStd_Relation) aC =
40 Handle(TDataStd_Relation)::DownCast(theTarget);
41
42 // variables
43 Standard_Integer nbvar;
44 if (! (theSource >> nbvar) || nbvar < 0)
45 return Standard_False;
46 TDF_AttributeList& aList = aC->GetVariables();
47 for (; nbvar > 0; nbvar--)
48 {
49 Handle(TDF_Attribute) aV;
50 Standard_Integer aNb;
51 if (! (theSource >> aNb))
52 return Standard_False;
53 if (aNb > 0)
54 {
55 if (theRelocTable.IsBound(aNb))
56 aV = Handle(TDataStd_Variable)::DownCast(theRelocTable.Find(aNb));
57 else
58 {
59 aV = new TDataStd_Variable;
60 theRelocTable.Bind(aNb, aV);
61 }
62 }
63 aList.Append(aV);
64 }
65
66 // expression
67 TCollection_ExtendedString aString;
68 if (! (theSource >> aString))
69 return Standard_False;
70 aC->SetRelation(aString);
71
72 return Standard_True;
73}
74
75//=======================================================================
76//function : Paste
77//purpose : transient -> persistent (store)
78//=======================================================================
79void BinMDataStd_RelationDriver::Paste
80 (const Handle(TDF_Attribute)& theSource,
81 BinObjMgt_Persistent& theTarget,
82 BinObjMgt_SRelocationTable& theRelocTable) const
83{
84 Handle(TDataStd_Relation) aC =
85 Handle(TDataStd_Relation)::DownCast(theSource);
86
87 // variables
88 const TDF_AttributeList& aList = aC->GetVariables();
89 Standard_Integer nbvar = aList.Extent();
90 theTarget << nbvar;
91 TDF_ListIteratorOfAttributeList it;
92 for (it.Initialize(aList); it.More(); it.Next())
93 {
94 const Handle(TDF_Attribute)& TV = it.Value();
95 Standard_Integer aNb;
96 if (!TV.IsNull())
97 aNb = theRelocTable.Add(TV);
98 else
99 aNb = -1;
100 theTarget << aNb;
101 }
102
103 // expression
104 TCollection_ExtendedString aName = aC->Name();
105 theTarget << aName;
106}