0024428: Implementation of LGPL license
[occt.git] / src / BinMDataStd / BinMDataStd_IntegerArrayDriver.cxx
CommitLineData
b311480e 1// Created on: 2002-10-31
2// Created by: Michael SAZONOV
973c2be1 3// Copyright (c) 2002-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
973c2be1 7// This library is free software; you can redistribute it and / or modify it
8// under the terms of the GNU Lesser General Public 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.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
7fd59977 15
16#include <BinMDataStd_IntegerArrayDriver.ixx>
17#include <TDataStd_IntegerArray.hxx>
18#include <TColStd_HArray1OfInteger.hxx>
19#include <BinMDataStd.hxx>
20
21//=======================================================================
22//function : BinMDataStd_IntegerArrayDriver
23//purpose : Constructor
24//=======================================================================
25
26BinMDataStd_IntegerArrayDriver::BinMDataStd_IntegerArrayDriver
27 (const Handle(CDM_MessageDriver)& theMsgDriver)
28 : BinMDF_ADriver (theMsgDriver, STANDARD_TYPE(TDataStd_IntegerArray)->Name())
29{
30}
31
32//=======================================================================
33//function : NewEmpty
34//purpose :
35//=======================================================================
36
37Handle(TDF_Attribute) BinMDataStd_IntegerArrayDriver::NewEmpty() const
38{
39 return new TDataStd_IntegerArray();
40}
41
42//=======================================================================
43//function : Paste
44//purpose : persistent -> transient (retrieve)
45//=======================================================================
46
47Standard_Boolean BinMDataStd_IntegerArrayDriver::Paste
48 (const BinObjMgt_Persistent& theSource,
49 const Handle(TDF_Attribute)& theTarget,
50 BinObjMgt_RRelocationTable& ) const
51{
52 Standard_Integer aFirstInd, aLastInd;
53 if (! (theSource >> aFirstInd >> aLastInd))
54 return Standard_False;
55 const Standard_Integer aLength = aLastInd - aFirstInd + 1;
56 if (aLength <= 0)
57 return Standard_False;
58
59 Handle(TDataStd_IntegerArray) anAtt =
60 Handle(TDataStd_IntegerArray)::DownCast(theTarget);
61 anAtt->Init(aFirstInd, aLastInd);
62 TColStd_Array1OfInteger& aTargetArray = anAtt->Array()->ChangeArray1();
63 if(!theSource.GetIntArray (&aTargetArray(aFirstInd), aLength))
64 return Standard_False;
65 Standard_Boolean aDelta(Standard_False);
66#ifdef DEB
67 //cout << "CurDocVersion = " << BinMDataStd::DocumentVersion() <<endl;
68#endif
69 if(BinMDataStd::DocumentVersion() > 2) {
70 Standard_Byte aDeltaValue;
71 if (! (theSource >> aDeltaValue))
72 return Standard_False;
73 else
74 aDelta = (Standard_Boolean)aDeltaValue;
75 }
76#ifdef DEB
77 else if(BinMDataStd::DocumentVersion() == -1)
78 cout << "Current DocVersion field is not initialized. " <<endl;
79#endif
80 anAtt->SetDelta(aDelta);
81 return Standard_True;
82}
83
84//=======================================================================
85//function : Paste
86//purpose : transient -> persistent (store)
87//=======================================================================
88
89void BinMDataStd_IntegerArrayDriver::Paste
90 (const Handle(TDF_Attribute)& theSource,
91 BinObjMgt_Persistent& theTarget,
92 BinObjMgt_SRelocationTable& ) const
93{
94 Handle(TDataStd_IntegerArray) anAtt =
95 Handle(TDataStd_IntegerArray)::DownCast(theSource);
96 const TColStd_Array1OfInteger& aSourceArray = anAtt->Array()->Array1();
97 const Standard_Integer aFirstInd = aSourceArray.Lower();
98 const Standard_Integer aLastInd = aSourceArray.Upper();
99 const Standard_Integer aLength = aLastInd - aFirstInd + 1;
100 theTarget << aFirstInd << aLastInd;
101 Standard_Integer *aPtr = (Standard_Integer *) &aSourceArray(aFirstInd);
102 theTarget.PutIntArray (aPtr, aLength);
103 theTarget << (Standard_Byte)anAtt->GetDelta();
104}