1 // Created on: 2007-03-30
2 // Created by: Michael SAZONOV
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 // The original implementation Copyright: (C) RINA S.p.A
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>
27 IMPLEMENT_STANDARD_HANDLE(BinTObjDrivers_IntSparseArrayDriver,BinMDF_ADriver)
28 IMPLEMENT_STANDARD_RTTIEXT(BinTObjDrivers_IntSparseArrayDriver,BinMDF_ADriver)
30 //=======================================================================
31 //function : BinTObjDrivers_IntSparseArrayDriver
32 //purpose : constructor
33 //=======================================================================
35 BinTObjDrivers_IntSparseArrayDriver::BinTObjDrivers_IntSparseArrayDriver
36 (const Handle(CDM_MessageDriver)& theMessageDriver)
37 : BinMDF_ADriver( theMessageDriver, NULL)
41 //=======================================================================
43 //purpose : Creates a new attribute
44 //=======================================================================
46 Handle(TDF_Attribute) BinTObjDrivers_IntSparseArrayDriver::NewEmpty() const
48 return new TObj_TIntSparseArray;
51 //=======================================================================
53 //purpose : Retrieve. Translate the contents of <theSource> and put it
55 //=======================================================================
57 Standard_Boolean BinTObjDrivers_IntSparseArrayDriver::Paste
58 (const BinObjMgt_Persistent& theSource,
59 const Handle(TDF_Attribute)& theTarget,
60 BinObjMgt_RRelocationTable&) const
62 Handle(TObj_TIntSparseArray) aTarget =
63 Handle(TObj_TIntSparseArray)::DownCast(theTarget);
65 // get pairs (ID, value) while ID != 0
66 Standard_Integer anId;
67 if (!(theSource >> anId) || anId < 0)
68 return Standard_False;
71 Standard_Integer aValue;
72 if (!(theSource >> aValue) || aValue <= 0)
73 return Standard_False;
75 // store the value in the target array
76 aTarget->SetDoBackup (Standard_False);
77 aTarget->SetValue (anId, aValue);
78 aTarget->SetDoBackup (Standard_True);
81 if (!(theSource >> anId) || anId < 0)
82 return Standard_False;
87 //=======================================================================
89 //purpose : Store. Translate the contents of <theSource> and put it
91 //=======================================================================
93 void BinTObjDrivers_IntSparseArrayDriver::Paste
94 (const Handle(TDF_Attribute)& theSource,
95 BinObjMgt_Persistent& theTarget,
96 BinObjMgt_SRelocationTable&) const
98 Handle(TObj_TIntSparseArray) aSource =
99 Handle(TObj_TIntSparseArray)::DownCast (theSource);
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() )
106 Standard_Integer aValue = anIt.Value();
110 // store ID and value
111 theTarget << (Standard_Integer) anIt.Index() << aValue;
113 // zero indicates end of the entities
114 theTarget << (Standard_Integer) 0;