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_ReferenceArrayDriver.hxx> |
18 | #include <BinObjMgt_Persistent.hxx> |
19 | #include <CDM_MessageDriver.hxx> |
20 | #include <Standard_Type.hxx> |
7fd59977 |
21 | #include <TDataStd_ReferenceArray.hxx> |
42cf5bc1 |
22 | #include <TDF_Attribute.hxx> |
7fd59977 |
23 | #include <TDF_Label.hxx> |
24 | #include <TDF_Tool.hxx> |
25 | |
92efcf78 |
26 | IMPLEMENT_STANDARD_RTTIEXT(BinMDataStd_ReferenceArrayDriver,BinMDF_ADriver) |
27 | |
7fd59977 |
28 | //======================================================================= |
29 | //function : BinMDataStd_ReferenceArrayDriver |
30 | //purpose : Constructor |
31 | //======================================================================= |
32 | BinMDataStd_ReferenceArrayDriver::BinMDataStd_ReferenceArrayDriver(const Handle(CDM_MessageDriver)& theMsgDriver) |
33 | : BinMDF_ADriver (theMsgDriver, STANDARD_TYPE(TDataStd_ReferenceArray)->Name()) |
34 | { |
35 | |
36 | } |
37 | |
38 | //======================================================================= |
39 | //function : NewEmpty |
40 | //purpose : |
41 | //======================================================================= |
42 | Handle(TDF_Attribute) BinMDataStd_ReferenceArrayDriver::NewEmpty() const |
43 | { |
44 | return new TDataStd_ReferenceArray(); |
45 | } |
46 | |
47 | //======================================================================= |
48 | //function : Paste |
49 | //purpose : persistent -> transient (retrieve) |
50 | //======================================================================= |
51 | Standard_Boolean BinMDataStd_ReferenceArrayDriver::Paste(const BinObjMgt_Persistent& theSource, |
52 | const Handle(TDF_Attribute)& theTarget, |
53 | BinObjMgt_RRelocationTable& ) const |
54 | { |
55 | Standard_Integer aFirstInd, aLastInd; |
56 | if (! (theSource >> aFirstInd >> aLastInd)) |
57 | return Standard_False; |
58 | const Standard_Integer aLength = aLastInd - aFirstInd + 1; |
59 | if (aLength <= 0) |
60 | return Standard_False; |
61 | |
62 | Handle(TDataStd_ReferenceArray) anAtt = Handle(TDataStd_ReferenceArray)::DownCast(theTarget); |
63 | anAtt->Init(aFirstInd, aLastInd); |
64 | for (Standard_Integer i = aFirstInd; i <= aLastInd; i++) |
65 | { |
66 | TCollection_AsciiString entry; |
67 | if ( !(theSource >> entry) ) |
68 | return Standard_False; |
69 | TDF_Label L; |
70 | TDF_Tool::Label(anAtt->Label().Data(), entry, L, Standard_True); |
71 | if (!L.IsNull()) |
72 | anAtt->SetValue(i, L); |
73 | } |
74 | |
75 | return Standard_True; |
76 | } |
77 | |
78 | //======================================================================= |
79 | //function : Paste |
80 | //purpose : transient -> persistent (store) |
81 | //======================================================================= |
82 | void BinMDataStd_ReferenceArrayDriver::Paste(const Handle(TDF_Attribute)& theSource, |
83 | BinObjMgt_Persistent& theTarget, |
84 | BinObjMgt_SRelocationTable& ) const |
85 | { |
86 | Handle(TDataStd_ReferenceArray) anAtt = Handle(TDataStd_ReferenceArray)::DownCast(theSource); |
87 | Standard_Integer aFirstInd = anAtt->Lower(), aLastInd = anAtt->Upper(), i = aFirstInd; |
88 | if (aFirstInd > aLastInd) |
89 | return; |
90 | theTarget << aFirstInd << aLastInd; |
91 | for (; i <= aLastInd; i++) |
92 | { |
93 | TDF_Label L = anAtt->Value(i); |
94 | if (!L.IsNull()) |
95 | { |
96 | TCollection_AsciiString entry; |
97 | TDF_Tool::Entry(L, entry); |
98 | theTarget << entry; |
99 | } |
100 | } |
101 | } |