0025394: Make it possible to store/retrieve the list-based attributes containing...
[occt.git] / src / BinMDataStd / BinMDataStd_ReferenceListDriver.cxx
1 // Created on: 2007-05-29
2 // Created by: Vlad Romashko
3 // Copyright (c) 2007-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_ReferenceListDriver.ixx>
17 #include <TDataStd_ReferenceList.hxx>
18 #include <TDF_ListIteratorOfLabelList.hxx>
19 #include <TDF_Label.hxx>
20 #include <TDF_Tool.hxx>
21
22 //=======================================================================
23 //function : BinMDataStd_ReferenceListDriver
24 //purpose  : Constructor
25 //=======================================================================
26 BinMDataStd_ReferenceListDriver::BinMDataStd_ReferenceListDriver(const Handle(CDM_MessageDriver)& theMsgDriver)
27      : BinMDF_ADriver (theMsgDriver, STANDARD_TYPE(TDataStd_ReferenceList)->Name())
28 {
29
30 }
31
32 //=======================================================================
33 //function : NewEmpty
34 //purpose  : 
35 //=======================================================================
36 Handle(TDF_Attribute) BinMDataStd_ReferenceListDriver::NewEmpty() const
37 {
38   return new TDataStd_ReferenceList();
39 }
40
41 //=======================================================================
42 //function : Paste
43 //purpose  : persistent -> transient (retrieve)
44 //=======================================================================
45 Standard_Boolean BinMDataStd_ReferenceListDriver::Paste(const BinObjMgt_Persistent&  theSource,
46                                                         const Handle(TDF_Attribute)& theTarget,
47                                                         BinObjMgt_RRelocationTable&  ) const
48 {
49   Standard_Integer aFirstInd, aLastInd;
50   if (! (theSource >> aFirstInd >> aLastInd))
51     return Standard_False;
52   if(aLastInd == 0) return Standard_True;
53
54   const Standard_Integer aLength = aLastInd - aFirstInd + 1;
55   if (aLength <= 0)
56     return Standard_False;
57
58   const Handle(TDataStd_ReferenceList) anAtt = Handle(TDataStd_ReferenceList)::DownCast(theTarget);
59   for (Standard_Integer i = aFirstInd; i <= aLastInd; i++)
60   {
61     TCollection_AsciiString entry;
62     if ( !(theSource >> entry) )
63       return Standard_False;
64     TDF_Label L;
65     TDF_Tool::Label(anAtt->Label().Data(), entry, L, Standard_True);
66     if (!L.IsNull())
67       anAtt->Append(L);
68   }
69
70   return Standard_True;
71 }
72
73 //=======================================================================
74 //function : Paste
75 //purpose  : transient -> persistent (store)
76 //=======================================================================
77 void BinMDataStd_ReferenceListDriver::Paste(const Handle(TDF_Attribute)& theSource,
78                                             BinObjMgt_Persistent&        theTarget,
79                                             BinObjMgt_SRelocationTable&  ) const
80 {
81   const Handle(TDataStd_ReferenceList) anAtt = Handle(TDataStd_ReferenceList)::DownCast(theSource);
82   if (anAtt.IsNull())
83     return;
84   const Standard_Integer aFirstInd = (anAtt->Extent()> 0) ? 1 : 0;
85   const Standard_Integer aLastInd(anAtt->Extent());  
86   theTarget << aFirstInd << aLastInd;
87   if(aLastInd == 0) return;
88   TDF_ListIteratorOfLabelList itr(anAtt->List());
89   for (Standard_Integer i = aFirstInd; itr.More(); itr.Next(), i++)
90   {
91     TDF_Label L = itr.Value();
92     if (!L.IsNull())
93     {
94       TCollection_AsciiString entry;
95       TDF_Tool::Entry(L, entry);
96       theTarget << entry;
97     }
98   }
99 }