1 // Created on: 2007-08-01
2 // Created by: Sergey ZARITCHNY
3 // Copyright (c) 2007-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
17 #include <BinMDataStd.hxx>
18 #include <BinMDataStd_IntPackedMapDriver.hxx>
19 #include <BinMDF_ADriver.hxx>
20 #include <BinObjMgt_Persistent.hxx>
21 #include <BinObjMgt_RRelocationTable.hxx>
22 #include <BinObjMgt_SRelocationTable.hxx>
23 #include <Message_Messenger.hxx>
24 #include <Standard_Type.hxx>
25 #include <TCollection_ExtendedString.hxx>
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>
32 IMPLEMENT_STANDARD_RTTIEXT(BinMDataStd_IntPackedMapDriver,BinMDF_ADriver)
34 //=======================================================================
35 //function : BinMDataStd_IntPackedMapDriver
37 //=======================================================================
38 BinMDataStd_IntPackedMapDriver::BinMDataStd_IntPackedMapDriver
39 (const Handle(Message_Messenger)& theMessageDriver)
40 : BinMDF_ADriver (theMessageDriver, STANDARD_TYPE(TDataStd_IntPackedMap)->Name())
44 //=======================================================================
47 //=======================================================================
49 Handle(TDF_Attribute) BinMDataStd_IntPackedMapDriver::NewEmpty() const
51 return new TDataStd_IntPackedMap;
54 //=======================================================================
56 //purpose : persistent -> transient (retrieve)
57 //=======================================================================
59 Standard_Boolean BinMDataStd_IntPackedMapDriver::Paste
60 (const BinObjMgt_Persistent& Source,
61 const Handle(TDF_Attribute)& Target,
62 BinObjMgt_RRelocationTable& RelocTable) const
64 Handle(TDataStd_IntPackedMap) aTagAtt = Handle(TDataStd_IntPackedMap)::DownCast(Target);
65 if(aTagAtt.IsNull()) {
66 myMessageDriver->Send ("IntPackedMapDriver:: The target attribute is Null.", Message_Fail);
67 return Standard_False;
70 Standard_Integer aSize = 0;
71 if (! (Source >> aSize)) {
72 myMessageDriver->Send ("Cannot retrieve size for IntPackedMap attribute.", Message_Fail);
73 return Standard_False;
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;
81 myMessageDriver->Send ("Cannot retrieve integer member for IntPackedMap attribute.", Message_Fail);
82 return Standard_False;
84 if(!aHMap->ChangeMap().Add( aKey )) return Standard_False;
86 aTagAtt->ChangeMap(aHMap);
89 Standard_Boolean aDelta(Standard_False);
90 if(RelocTable.GetHeaderData()->StorageVersion().IntegerValue() > 2) {
91 Standard_Byte aDeltaValue;
92 if (! (Source >> aDeltaValue))
93 return Standard_False;
95 aDelta = (aDeltaValue != 0);
97 aTagAtt->SetDelta(aDelta);
101 //=======================================================================
103 //purpose : transient -> persistent (store)
104 //=======================================================================
106 void BinMDataStd_IntPackedMapDriver::Paste
107 (const Handle(TDF_Attribute)& Source,
108 BinObjMgt_Persistent& Target,
109 BinObjMgt_SRelocationTable& /*RelocTable*/) const
111 Handle(TDataStd_IntPackedMap) anAtt = Handle(TDataStd_IntPackedMap)::DownCast(Source);
112 if (anAtt.IsNull()) {
113 myMessageDriver->Send ("IntPackedMapDriver:: The source attribute is Null.", Message_Fail);
116 Standard_Integer aSize = (anAtt->IsEmpty()) ? 0 : anAtt->Extent();
119 TColStd_MapIteratorOfPackedMapOfInteger anIt(anAtt->GetMap());
120 for(;anIt.More();anIt.Next())
121 Target << anIt.Key();
123 Target << (Standard_Byte)(anAtt->GetDelta() ? 1 : 0);