b311480e |
1 | // Created on: 2007-08-01 |
2 | // Created by: Sergey ZARITCHNY |
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.hxx> |
18 | #include <BinMDataStd_IntPackedMapDriver.hxx> |
7fd59977 |
19 | #include <BinMDF_ADriver.hxx> |
7fd59977 |
20 | #include <BinObjMgt_Persistent.hxx> |
21 | #include <BinObjMgt_RRelocationTable.hxx> |
22 | #include <BinObjMgt_SRelocationTable.hxx> |
83ae3591 |
23 | #include <Message_Messenger.hxx> |
42cf5bc1 |
24 | #include <Standard_Type.hxx> |
7fd59977 |
25 | #include <TCollection_ExtendedString.hxx> |
42cf5bc1 |
26 | #include <TColStd_HPackedMapOfInteger.hxx> |
27 | #include <TColStd_MapIteratorOfPackedMapOfInteger.hxx> |
28 | #include <TColStd_PackedMapOfInteger.hxx> |
29 | #include <TDataStd_IntPackedMap.hxx> |
30 | #include <TDF_Attribute.hxx> |
31 | |
92efcf78 |
32 | IMPLEMENT_STANDARD_RTTIEXT(BinMDataStd_IntPackedMapDriver,BinMDF_ADriver) |
33 | |
7fd59977 |
34 | //======================================================================= |
35 | //function : BinMDataStd_IntPackedMapDriver |
36 | //purpose : |
37 | //======================================================================= |
7fd59977 |
38 | BinMDataStd_IntPackedMapDriver::BinMDataStd_IntPackedMapDriver |
83ae3591 |
39 | (const Handle(Message_Messenger)& theMessageDriver) |
7fd59977 |
40 | : BinMDF_ADriver (theMessageDriver, STANDARD_TYPE(TDataStd_IntPackedMap)->Name()) |
41 | { |
42 | } |
43 | |
44 | //======================================================================= |
45 | //function : NewEmpty |
46 | //purpose : |
47 | //======================================================================= |
48 | |
49 | Handle(TDF_Attribute) BinMDataStd_IntPackedMapDriver::NewEmpty() const |
50 | { |
51 | return new TDataStd_IntPackedMap; |
52 | } |
53 | |
54 | //======================================================================= |
55 | //function : Paste |
56 | //purpose : persistent -> transient (retrieve) |
57 | //======================================================================= |
58 | |
59 | Standard_Boolean BinMDataStd_IntPackedMapDriver::Paste |
60 | (const BinObjMgt_Persistent& Source, |
61 | const Handle(TDF_Attribute)& Target, |
b34d86cb |
62 | BinObjMgt_RRelocationTable& RelocTable) const |
7fd59977 |
63 | { |
64 | Handle(TDataStd_IntPackedMap) aTagAtt = Handle(TDataStd_IntPackedMap)::DownCast(Target); |
65 | if(aTagAtt.IsNull()) { |
83ae3591 |
66 | myMessageDriver->Send ("IntPackedMapDriver:: The target attribute is Null.", Message_Fail); |
7fd59977 |
67 | return Standard_False; |
68 | } |
69 | |
70 | Standard_Integer aSize = 0; |
71 | if (! (Source >> aSize)) { |
83ae3591 |
72 | myMessageDriver->Send ("Cannot retrieve size for IntPackedMap attribute.", Message_Fail); |
7fd59977 |
73 | return Standard_False; |
74 | } |
75 | if(aSize) { |
76 | Handle(TColStd_HPackedMapOfInteger) aHMap = new TColStd_HPackedMapOfInteger (); |
77 | Standard_Integer aKey; |
78 | for(Standard_Integer i = 0; i< aSize; i++) { |
79 | Standard_Boolean ok = Source >> aKey; |
80 | if (!ok) { |
83ae3591 |
81 | myMessageDriver->Send ("Cannot retrieve integer member for IntPackedMap attribute.", Message_Fail); |
7fd59977 |
82 | return Standard_False; |
83 | } |
84 | if(!aHMap->ChangeMap().Add( aKey )) return Standard_False; |
85 | } |
86 | aTagAtt->ChangeMap(aHMap); |
87 | } |
63c629aa |
88 | |
7fd59977 |
89 | Standard_Boolean aDelta(Standard_False); |
b34d86cb |
90 | if(RelocTable.GetHeaderData()->StorageVersion().IntegerValue() > 2) { |
7fd59977 |
91 | Standard_Byte aDeltaValue; |
92 | if (! (Source >> aDeltaValue)) |
93 | return Standard_False; |
94 | else |
dde68833 |
95 | aDelta = (aDeltaValue != 0); |
7fd59977 |
96 | } |
97 | aTagAtt->SetDelta(aDelta); |
98 | return Standard_True; |
99 | } |
100 | |
101 | //======================================================================= |
102 | //function : Paste |
103 | //purpose : transient -> persistent (store) |
104 | //======================================================================= |
105 | |
106 | void BinMDataStd_IntPackedMapDriver::Paste |
107 | (const Handle(TDF_Attribute)& Source, |
108 | BinObjMgt_Persistent& Target, |
109 | BinObjMgt_SRelocationTable& /*RelocTable*/) const |
110 | { |
111 | Handle(TDataStd_IntPackedMap) anAtt = Handle(TDataStd_IntPackedMap)::DownCast(Source); |
112 | if (anAtt.IsNull()) { |
83ae3591 |
113 | myMessageDriver->Send ("IntPackedMapDriver:: The source attribute is Null.", Message_Fail); |
7fd59977 |
114 | return; |
115 | } |
116 | Standard_Integer aSize = (anAtt->IsEmpty()) ? 0 : anAtt->Extent(); |
117 | Target << aSize; |
118 | if(aSize) { |
119 | TColStd_MapIteratorOfPackedMapOfInteger anIt(anAtt->GetMap()); |
120 | for(;anIt.More();anIt.Next()) |
121 | Target << anIt.Key(); |
122 | } |
dde68833 |
123 | Target << (Standard_Byte)(anAtt->GetDelta() ? 1 : 0); |
7fd59977 |
124 | } |