0024624: Lost word in license statement in source files
[occt.git] / src / BinMDataStd / BinMDataStd_IntPackedMapDriver.cxx
1 // Created on: 2007-08-01
2 // Created by: Sergey ZARITCHNY
3 // Copyright (c) 2007-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
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
31 //purpose  :
32 //=======================================================================
33
34 BinMDataStd_IntPackedMapDriver::BinMDataStd_IntPackedMapDriver
35                          (const Handle(CDM_MessageDriver)& theMessageDriver)
36      : BinMDF_ADriver (theMessageDriver, STANDARD_TYPE(TDataStd_IntPackedMap)->Name())
37 {
38 }
39
40 //=======================================================================
41 //function : NewEmpty
42 //purpose  :
43 //=======================================================================
44
45 Handle(TDF_Attribute) BinMDataStd_IntPackedMapDriver::NewEmpty() const
46 {
47   return new TDataStd_IntPackedMap;
48 }
49
50 //=======================================================================
51 //function : Paste
52 //purpose  : persistent -> transient (retrieve)
53 //=======================================================================
54
55 Standard_Boolean BinMDataStd_IntPackedMapDriver::Paste
56                          (const BinObjMgt_Persistent&  Source,
57                           const Handle(TDF_Attribute)& Target,
58                           BinObjMgt_RRelocationTable&  /*RelocTable*/) const
59 {
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;
64   }
65
66   Standard_Integer aSize = 0;
67   if (! (Source >> aSize)) {
68     WriteMessage (TCollection_ExtendedString("Cannot retrieve size for IntPackedMap attribute."));
69     return Standard_False;
70   }
71   if(aSize) {
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;
76       if (!ok) {
77         WriteMessage ("Cannot retrieve integer member for IntPackedMap attribute.");
78         return Standard_False;
79       }
80       if(!aHMap->ChangeMap().Add( aKey )) return Standard_False;
81     }
82     aTagAtt->ChangeMap(aHMap);
83   }
84 #ifdef DEB
85   //cout << "CurDocVersion = " << BinMDataStd::DocumentVersion() <<endl;
86 #endif  
87   Standard_Boolean aDelta(Standard_False);
88   if(BinMDataStd::DocumentVersion() > 2) {
89     Standard_Byte aDeltaValue;
90     if (! (Source >> aDeltaValue))
91       return Standard_False;
92     else
93       aDelta = (Standard_Boolean)aDeltaValue;
94   }
95   aTagAtt->SetDelta(aDelta);
96   return Standard_True;
97 }
98
99 //=======================================================================
100 //function : Paste
101 //purpose  : transient -> persistent (store)
102 //=======================================================================
103
104 void BinMDataStd_IntPackedMapDriver::Paste
105                          (const Handle(TDF_Attribute)& Source,
106                           BinObjMgt_Persistent&        Target,
107                           BinObjMgt_SRelocationTable&  /*RelocTable*/) const
108 {
109   Handle(TDataStd_IntPackedMap) anAtt = Handle(TDataStd_IntPackedMap)::DownCast(Source);
110   if (anAtt.IsNull()) {
111     WriteMessage ("IntPackedMapDriver:: The source attribute is Null.");
112     return;
113   }
114   Standard_Integer aSize = (anAtt->IsEmpty()) ? 0 : anAtt->Extent();
115   Target << aSize;
116   if(aSize) {
117     TColStd_MapIteratorOfPackedMapOfInteger anIt(anAtt->GetMap());
118     for(;anIt.More();anIt.Next())
119       Target << anIt.Key();
120   }
121   Target << (Standard_Byte)anAtt->GetDelta(); 
122 }