0026936: Drawbacks of inlining in new type system in OCCT 7.0 -- automatic
[occt.git] / src / BinTObjDrivers / BinTObjDrivers_IntSparseArrayDriver.cxx
CommitLineData
b311480e 1// Created on: 2007-03-30
2// Created by: Michael SAZONOV
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.
b311480e 15
7fd59977 16// The original implementation Copyright: (C) RINA S.p.A
17
18#include <BinTObjDrivers_IntSparseArrayDriver.hxx>
19#include <CDM_MessageDriver.hxx>
20#include <TDF_Attribute.hxx>
21#include <BinObjMgt_Persistent.hxx>
22#include <TObj_TIntSparseArray.hxx>
23#include <TObj_Assistant.hxx>
24#include <TCollection_AsciiString.hxx>
25#include <TDF_Tool.hxx>
26
7fd59977 27
92efcf78 28IMPLEMENT_STANDARD_RTTIEXT(BinTObjDrivers_IntSparseArrayDriver,BinMDF_ADriver)
29
7fd59977 30//=======================================================================
31//function : BinTObjDrivers_IntSparseArrayDriver
32//purpose : constructor
33//=======================================================================
34
35BinTObjDrivers_IntSparseArrayDriver::BinTObjDrivers_IntSparseArrayDriver
36 (const Handle(CDM_MessageDriver)& theMessageDriver)
37: BinMDF_ADriver( theMessageDriver, NULL)
38{
39}
40
41//=======================================================================
42//function : NewEmpty
43//purpose : Creates a new attribute
44//=======================================================================
45
46Handle(TDF_Attribute) BinTObjDrivers_IntSparseArrayDriver::NewEmpty() const
47{
48 return new TObj_TIntSparseArray;
49}
50
51//=======================================================================
52//function : Paste
53//purpose : Retrieve. Translate the contents of <theSource> and put it
54// into <theTarget>.
55//=======================================================================
56
57Standard_Boolean BinTObjDrivers_IntSparseArrayDriver::Paste
58 (const BinObjMgt_Persistent& theSource,
59 const Handle(TDF_Attribute)& theTarget,
60 BinObjMgt_RRelocationTable&) const
61{
62 Handle(TObj_TIntSparseArray) aTarget =
63 Handle(TObj_TIntSparseArray)::DownCast(theTarget);
64
65 // get pairs (ID, value) while ID != 0
66 Standard_Integer anId;
67 if (!(theSource >> anId) || anId < 0)
68 return Standard_False;
69 while (anId)
70 {
71 Standard_Integer aValue;
72 if (!(theSource >> aValue) || aValue <= 0)
73 return Standard_False;
74
75 // store the value in the target array
76 aTarget->SetDoBackup (Standard_False);
77 aTarget->SetValue (anId, aValue);
78 aTarget->SetDoBackup (Standard_True);
79
80 // get next ID
81 if (!(theSource >> anId) || anId < 0)
82 return Standard_False;
83 }
84 return Standard_True;
85}
86
87//=======================================================================
88//function : Paste
89//purpose : Store. Translate the contents of <theSource> and put it
90// into <theTarget>
91//=======================================================================
92
93void BinTObjDrivers_IntSparseArrayDriver::Paste
94 (const Handle(TDF_Attribute)& theSource,
95 BinObjMgt_Persistent& theTarget,
96 BinObjMgt_SRelocationTable&) const
97{
98 Handle(TObj_TIntSparseArray) aSource =
99 Handle(TObj_TIntSparseArray)::DownCast (theSource);
100
101 // put only non-null values as pairs (ID, value)
102 // terminate the list by ID=0
103 TObj_TIntSparseArray::Iterator anIt = aSource->GetIterator();
104 for ( ; anIt.More() ; anIt.Next() )
105 {
106 Standard_Integer aValue = anIt.Value();
107 if (aValue == 0)
108 continue;
109
110 // store ID and value
111 theTarget << (Standard_Integer) anIt.Index() << aValue;
112 }
113 // zero indicates end of the entities
114 theTarget << (Standard_Integer) 0;
115}