b311480e |
1 | // Created on: 2007-05-29 |
2 | // Created by: Vlad Romashko |
973c2be1 |
3 | // Copyright (c) 2007-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
7fd59977 |
15 | |
42cf5bc1 |
16 | |
17 | #include <BinMDataStd_ReferenceListDriver.hxx> |
18 | #include <BinObjMgt_Persistent.hxx> |
19 | #include <CDM_MessageDriver.hxx> |
20 | #include <Standard_Type.hxx> |
7fd59977 |
21 | #include <TDataStd_ReferenceList.hxx> |
42cf5bc1 |
22 | #include <TDF_Attribute.hxx> |
7fd59977 |
23 | #include <TDF_Label.hxx> |
42cf5bc1 |
24 | #include <TDF_ListIteratorOfLabelList.hxx> |
7fd59977 |
25 | #include <TDF_Tool.hxx> |
26 | |
92efcf78 |
27 | IMPLEMENT_STANDARD_RTTIEXT(BinMDataStd_ReferenceListDriver,BinMDF_ADriver) |
28 | |
7fd59977 |
29 | //======================================================================= |
30 | //function : BinMDataStd_ReferenceListDriver |
31 | //purpose : Constructor |
32 | //======================================================================= |
33 | BinMDataStd_ReferenceListDriver::BinMDataStd_ReferenceListDriver(const Handle(CDM_MessageDriver)& theMsgDriver) |
34 | : BinMDF_ADriver (theMsgDriver, STANDARD_TYPE(TDataStd_ReferenceList)->Name()) |
35 | { |
36 | |
37 | } |
38 | |
39 | //======================================================================= |
40 | //function : NewEmpty |
41 | //purpose : |
42 | //======================================================================= |
43 | Handle(TDF_Attribute) BinMDataStd_ReferenceListDriver::NewEmpty() const |
44 | { |
45 | return new TDataStd_ReferenceList(); |
46 | } |
47 | |
48 | //======================================================================= |
49 | //function : Paste |
50 | //purpose : persistent -> transient (retrieve) |
51 | //======================================================================= |
52 | Standard_Boolean BinMDataStd_ReferenceListDriver::Paste(const BinObjMgt_Persistent& theSource, |
53 | const Handle(TDF_Attribute)& theTarget, |
54 | BinObjMgt_RRelocationTable& ) const |
55 | { |
56 | Standard_Integer aFirstInd, aLastInd; |
57 | if (! (theSource >> aFirstInd >> aLastInd)) |
58 | return Standard_False; |
d585e74e |
59 | if(aLastInd == 0) return Standard_True; |
60 | |
7fd59977 |
61 | const Standard_Integer aLength = aLastInd - aFirstInd + 1; |
62 | if (aLength <= 0) |
63 | return Standard_False; |
64 | |
d585e74e |
65 | const Handle(TDataStd_ReferenceList) anAtt = Handle(TDataStd_ReferenceList)::DownCast(theTarget); |
7fd59977 |
66 | for (Standard_Integer i = aFirstInd; i <= aLastInd; i++) |
67 | { |
68 | TCollection_AsciiString entry; |
69 | if ( !(theSource >> entry) ) |
70 | return Standard_False; |
71 | TDF_Label L; |
72 | TDF_Tool::Label(anAtt->Label().Data(), entry, L, Standard_True); |
73 | if (!L.IsNull()) |
74 | anAtt->Append(L); |
75 | } |
76 | |
77 | return Standard_True; |
78 | } |
79 | |
80 | //======================================================================= |
81 | //function : Paste |
82 | //purpose : transient -> persistent (store) |
83 | //======================================================================= |
84 | void BinMDataStd_ReferenceListDriver::Paste(const Handle(TDF_Attribute)& theSource, |
85 | BinObjMgt_Persistent& theTarget, |
86 | BinObjMgt_SRelocationTable& ) const |
87 | { |
d585e74e |
88 | const Handle(TDataStd_ReferenceList) anAtt = Handle(TDataStd_ReferenceList)::DownCast(theSource); |
89 | if (anAtt.IsNull()) |
7fd59977 |
90 | return; |
d585e74e |
91 | const Standard_Integer aFirstInd = (anAtt->Extent()> 0) ? 1 : 0; |
92 | const Standard_Integer aLastInd(anAtt->Extent()); |
7fd59977 |
93 | theTarget << aFirstInd << aLastInd; |
d585e74e |
94 | if(aLastInd == 0) return; |
7fd59977 |
95 | TDF_ListIteratorOfLabelList itr(anAtt->List()); |
d585e74e |
96 | for (Standard_Integer i = aFirstInd; itr.More(); itr.Next(), i++) |
7fd59977 |
97 | { |
98 | TDF_Label L = itr.Value(); |
99 | if (!L.IsNull()) |
100 | { |
101 | TCollection_AsciiString entry; |
102 | TDF_Tool::Entry(L, entry); |
103 | theTarget << entry; |
104 | } |
105 | } |
106 | } |