b311480e |
1 | // Created on: 2007-03-30 |
2 | // Created by: Michael SAZONOV |
3 | // Copyright (c) 2007-2012 OPEN CASCADE SAS |
4 | // |
5 | // The content of this file is subject to the Open CASCADE Technology Public |
6 | // License Version 6.5 (the "License"). You may not use the content of this file |
7 | // except in compliance with the License. Please obtain a copy of the License |
8 | // at http://www.opencascade.org and read it completely before using this file. |
9 | // |
10 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
11 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
12 | // |
13 | // The Original Code and all software distributed under the License is |
14 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
15 | // Initial Developer hereby disclaims all such warranties, including without |
16 | // limitation, any warranties of merchantability, fitness for a particular |
17 | // purpose or non-infringement. Please see the License for the specific terms |
18 | // and conditions governing the rights and limitations under the License. |
19 | |
7fd59977 |
20 | // The original implementation Copyright: (C) RINA S.p.A |
21 | |
22 | #include <BinTObjDrivers_IntSparseArrayDriver.hxx> |
23 | #include <CDM_MessageDriver.hxx> |
24 | #include <TDF_Attribute.hxx> |
25 | #include <BinObjMgt_Persistent.hxx> |
26 | #include <TObj_TIntSparseArray.hxx> |
27 | #include <TObj_Assistant.hxx> |
28 | #include <TCollection_AsciiString.hxx> |
29 | #include <TDF_Tool.hxx> |
30 | |
31 | IMPLEMENT_STANDARD_HANDLE(BinTObjDrivers_IntSparseArrayDriver,BinMDF_ADriver) |
32 | IMPLEMENT_STANDARD_RTTIEXT(BinTObjDrivers_IntSparseArrayDriver,BinMDF_ADriver) |
33 | |
34 | //======================================================================= |
35 | //function : BinTObjDrivers_IntSparseArrayDriver |
36 | //purpose : constructor |
37 | //======================================================================= |
38 | |
39 | BinTObjDrivers_IntSparseArrayDriver::BinTObjDrivers_IntSparseArrayDriver |
40 | (const Handle(CDM_MessageDriver)& theMessageDriver) |
41 | : BinMDF_ADriver( theMessageDriver, NULL) |
42 | { |
43 | } |
44 | |
45 | //======================================================================= |
46 | //function : NewEmpty |
47 | //purpose : Creates a new attribute |
48 | //======================================================================= |
49 | |
50 | Handle(TDF_Attribute) BinTObjDrivers_IntSparseArrayDriver::NewEmpty() const |
51 | { |
52 | return new TObj_TIntSparseArray; |
53 | } |
54 | |
55 | //======================================================================= |
56 | //function : Paste |
57 | //purpose : Retrieve. Translate the contents of <theSource> and put it |
58 | // into <theTarget>. |
59 | //======================================================================= |
60 | |
61 | Standard_Boolean BinTObjDrivers_IntSparseArrayDriver::Paste |
62 | (const BinObjMgt_Persistent& theSource, |
63 | const Handle(TDF_Attribute)& theTarget, |
64 | BinObjMgt_RRelocationTable&) const |
65 | { |
66 | Handle(TObj_TIntSparseArray) aTarget = |
67 | Handle(TObj_TIntSparseArray)::DownCast(theTarget); |
68 | |
69 | // get pairs (ID, value) while ID != 0 |
70 | Standard_Integer anId; |
71 | if (!(theSource >> anId) || anId < 0) |
72 | return Standard_False; |
73 | while (anId) |
74 | { |
75 | Standard_Integer aValue; |
76 | if (!(theSource >> aValue) || aValue <= 0) |
77 | return Standard_False; |
78 | |
79 | // store the value in the target array |
80 | aTarget->SetDoBackup (Standard_False); |
81 | aTarget->SetValue (anId, aValue); |
82 | aTarget->SetDoBackup (Standard_True); |
83 | |
84 | // get next ID |
85 | if (!(theSource >> anId) || anId < 0) |
86 | return Standard_False; |
87 | } |
88 | return Standard_True; |
89 | } |
90 | |
91 | //======================================================================= |
92 | //function : Paste |
93 | //purpose : Store. Translate the contents of <theSource> and put it |
94 | // into <theTarget> |
95 | //======================================================================= |
96 | |
97 | void BinTObjDrivers_IntSparseArrayDriver::Paste |
98 | (const Handle(TDF_Attribute)& theSource, |
99 | BinObjMgt_Persistent& theTarget, |
100 | BinObjMgt_SRelocationTable&) const |
101 | { |
102 | Handle(TObj_TIntSparseArray) aSource = |
103 | Handle(TObj_TIntSparseArray)::DownCast (theSource); |
104 | |
105 | // put only non-null values as pairs (ID, value) |
106 | // terminate the list by ID=0 |
107 | TObj_TIntSparseArray::Iterator anIt = aSource->GetIterator(); |
108 | for ( ; anIt.More() ; anIt.Next() ) |
109 | { |
110 | Standard_Integer aValue = anIt.Value(); |
111 | if (aValue == 0) |
112 | continue; |
113 | |
114 | // store ID and value |
115 | theTarget << (Standard_Integer) anIt.Index() << aValue; |
116 | } |
117 | // zero indicates end of the entities |
118 | theTarget << (Standard_Integer) 0; |
119 | } |