0024624: Lost word in license statement in source files
[occt.git] / src / BinMDataStd / BinMDataStd_RelationDriver.cxx
1 // Created on: 2001-09-12
2 // Created by: Julia DOROVSKIKH
3 // Copyright (c) 2001-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #include <BinMDataStd_RelationDriver.ixx>
17 #include <TDataStd_Relation.hxx>
18 #include <TDataStd_Variable.hxx>
19 #include <TDF_ListIteratorOfAttributeList.hxx>
20
21 //=======================================================================
22 //function : BinMDataStd_RelationDriver
23 //purpose  : Constructor
24 //=======================================================================
25 BinMDataStd_RelationDriver::BinMDataStd_RelationDriver
26                         (const Handle(CDM_MessageDriver)& theMsgDriver)
27       : BinMDF_ADriver (theMsgDriver, NULL)
28 {}
29
30 //=======================================================================
31 //function : NewEmpty
32 //purpose  : 
33 //=======================================================================
34 Handle(TDF_Attribute) BinMDataStd_RelationDriver::NewEmpty() const
35 {
36   return (new TDataStd_Relation());
37 }
38
39 //=======================================================================
40 //function : Paste
41 //purpose  : persistent -> transient (retrieve)
42 //=======================================================================
43 Standard_Boolean BinMDataStd_RelationDriver::Paste
44                         (const BinObjMgt_Persistent&  theSource,
45                          const Handle(TDF_Attribute)& theTarget,
46                          BinObjMgt_RRelocationTable&  theRelocTable) const
47 {
48   Handle(TDataStd_Relation) aC = 
49     Handle(TDataStd_Relation)::DownCast(theTarget);
50
51   // variables
52   Standard_Integer nbvar;
53   if (! (theSource >> nbvar) || nbvar < 0)
54     return Standard_False;
55   TDF_AttributeList& aList = aC->GetVariables();
56   for (; nbvar > 0; nbvar--)
57   {
58     Handle(TDF_Attribute) aV;
59     Standard_Integer aNb;
60     if (! (theSource >> aNb))
61       return Standard_False;
62     if (aNb > 0)
63     {
64       if (theRelocTable.IsBound(aNb))
65         aV = Handle(TDataStd_Variable)::DownCast(theRelocTable.Find(aNb));
66       else
67       {
68         aV = new TDataStd_Variable;
69         theRelocTable.Bind(aNb, aV);
70       }
71     }
72     aList.Append(aV);
73   }
74
75   // expression
76   TCollection_ExtendedString aString;
77   if (! (theSource >> aString))
78     return Standard_False;
79   aC->SetRelation(aString);
80
81   return Standard_True;
82 }
83
84 //=======================================================================
85 //function : Paste
86 //purpose  : transient -> persistent (store)
87 //=======================================================================
88 void BinMDataStd_RelationDriver::Paste
89                         (const Handle(TDF_Attribute)& theSource,
90                          BinObjMgt_Persistent&        theTarget,
91                          BinObjMgt_SRelocationTable&  theRelocTable) const
92 {
93   Handle(TDataStd_Relation) aC =
94     Handle(TDataStd_Relation)::DownCast(theSource);
95
96   // variables
97   const TDF_AttributeList& aList = aC->GetVariables();
98   Standard_Integer nbvar = aList.Extent();
99   theTarget << nbvar;
100   TDF_ListIteratorOfAttributeList it;
101   for (it.Initialize(aList); it.More(); it.Next())
102   {
103     const Handle(TDF_Attribute)& TV = it.Value();
104     Standard_Integer aNb;
105     if (!TV.IsNull())
106       aNb = theRelocTable.Add(TV);
107     else
108       aNb = -1;
109     theTarget << aNb;
110   }
111
112   // expression
113   TCollection_ExtendedString aName = aC->Name();
114   theTarget << aName;
115 }