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.
16 #include <BinMDataStd_IntPackedMapDriver.ixx>
17 #include <CDM_MessageDriver.hxx>
18 #include <TColStd_PackedMapOfInteger.hxx>
19 #include <TColStd_HPackedMapOfInteger.hxx>
20 #include <TColStd_MapIteratorOfPackedMapOfInteger.hxx>
21 #include <BinMDF_ADriver.hxx>
22 #include <TDataStd_IntPackedMap.hxx>
23 #include <TDF_Attribute.hxx>
24 #include <BinObjMgt_Persistent.hxx>
25 #include <BinObjMgt_RRelocationTable.hxx>
26 #include <BinObjMgt_SRelocationTable.hxx>
27 #include <TCollection_ExtendedString.hxx>
28 #include <BinMDataStd.hxx>
29 //=======================================================================
30 //function : BinMDataStd_IntPackedMapDriver
32 //=======================================================================
34 BinMDataStd_IntPackedMapDriver::BinMDataStd_IntPackedMapDriver
35 (const Handle(CDM_MessageDriver)& theMessageDriver)
36 : BinMDF_ADriver (theMessageDriver, STANDARD_TYPE(TDataStd_IntPackedMap)->Name())
40 //=======================================================================
43 //=======================================================================
45 Handle(TDF_Attribute) BinMDataStd_IntPackedMapDriver::NewEmpty() const
47 return new TDataStd_IntPackedMap;
50 //=======================================================================
52 //purpose : persistent -> transient (retrieve)
53 //=======================================================================
55 Standard_Boolean BinMDataStd_IntPackedMapDriver::Paste
56 (const BinObjMgt_Persistent& Source,
57 const Handle(TDF_Attribute)& Target,
58 BinObjMgt_RRelocationTable& /*RelocTable*/) const
60 Handle(TDataStd_IntPackedMap) aTagAtt = Handle(TDataStd_IntPackedMap)::DownCast(Target);
61 if(aTagAtt.IsNull()) {
62 WriteMessage (TCollection_ExtendedString("IntPackedMapDriver:: The target attribute is Null."));
63 return Standard_False;
66 Standard_Integer aSize = 0;
67 if (! (Source >> aSize)) {
68 WriteMessage (TCollection_ExtendedString("Cannot retrieve size for IntPackedMap attribute."));
69 return Standard_False;
72 Handle(TColStd_HPackedMapOfInteger) aHMap = new TColStd_HPackedMapOfInteger ();
73 Standard_Integer aKey;
74 for(Standard_Integer i = 0; i< aSize; i++) {
75 Standard_Boolean ok = Source >> aKey;
77 WriteMessage ("Cannot retrieve integer member for IntPackedMap attribute.");
78 return Standard_False;
80 if(!aHMap->ChangeMap().Add( aKey )) return Standard_False;
82 aTagAtt->ChangeMap(aHMap);
85 //cout << "CurDocVersion = " << BinMDataStd::DocumentVersion() <<endl;
87 Standard_Boolean aDelta(Standard_False);
88 if(BinMDataStd::DocumentVersion() > 2) {
89 Standard_Byte aDeltaValue;
90 if (! (Source >> aDeltaValue))
91 return Standard_False;
93 aDelta = (Standard_Boolean)aDeltaValue;
95 aTagAtt->SetDelta(aDelta);
99 //=======================================================================
101 //purpose : transient -> persistent (store)
102 //=======================================================================
104 void BinMDataStd_IntPackedMapDriver::Paste
105 (const Handle(TDF_Attribute)& Source,
106 BinObjMgt_Persistent& Target,
107 BinObjMgt_SRelocationTable& /*RelocTable*/) const
109 Handle(TDataStd_IntPackedMap) anAtt = Handle(TDataStd_IntPackedMap)::DownCast(Source);
110 if (anAtt.IsNull()) {
111 WriteMessage ("IntPackedMapDriver:: The source attribute is Null.");
114 Standard_Integer aSize = (anAtt->IsEmpty()) ? 0 : anAtt->Extent();
117 TColStd_MapIteratorOfPackedMapOfInteger anIt(anAtt->GetMap());
118 for(;anIt.More();anIt.Next())
119 Target << anIt.Key();
121 Target << (Standard_Byte)anAtt->GetDelta();