1 // Created on: 2002-10-31
2 // Created by: Michael SAZONOV
3 // Copyright (c) 2002-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.
17 #include <BinMDataStd.hxx>
18 #include <BinMDataStd_IntegerArrayDriver.hxx>
19 #include <BinObjMgt_Persistent.hxx>
20 #include <CDM_MessageDriver.hxx>
21 #include <Standard_Type.hxx>
22 #include <TColStd_HArray1OfInteger.hxx>
23 #include <TDataStd_IntegerArray.hxx>
24 #include <TDF_Attribute.hxx>
26 IMPLEMENT_STANDARD_RTTIEXT(BinMDataStd_IntegerArrayDriver,BinMDF_ADriver)
28 //=======================================================================
29 //function : BinMDataStd_IntegerArrayDriver
30 //purpose : Constructor
31 //=======================================================================
32 BinMDataStd_IntegerArrayDriver::BinMDataStd_IntegerArrayDriver
33 (const Handle(CDM_MessageDriver)& theMsgDriver)
34 : BinMDF_ADriver (theMsgDriver, STANDARD_TYPE(TDataStd_IntegerArray)->Name())
38 //=======================================================================
41 //=======================================================================
43 Handle(TDF_Attribute) BinMDataStd_IntegerArrayDriver::NewEmpty() const
45 return new TDataStd_IntegerArray();
48 //=======================================================================
50 //purpose : persistent -> transient (retrieve)
51 //=======================================================================
53 Standard_Boolean BinMDataStd_IntegerArrayDriver::Paste
54 (const BinObjMgt_Persistent& theSource,
55 const Handle(TDF_Attribute)& theTarget,
56 BinObjMgt_RRelocationTable& ) const
58 Standard_Integer aFirstInd, aLastInd;
59 if (! (theSource >> aFirstInd >> aLastInd))
60 return Standard_False;
61 const Standard_Integer aLength = aLastInd - aFirstInd + 1;
63 return Standard_False;
65 const Handle(TDataStd_IntegerArray) anAtt =
66 Handle(TDataStd_IntegerArray)::DownCast(theTarget);
67 anAtt->Init(aFirstInd, aLastInd);
68 TColStd_Array1OfInteger& aTargetArray = anAtt->Array()->ChangeArray1();
69 if(!theSource.GetIntArray (&aTargetArray(aFirstInd), aLength))
70 return Standard_False;
71 Standard_Boolean aDelta(Standard_False);
72 if(BinMDataStd::DocumentVersion() > 2) {
73 Standard_Byte aDeltaValue;
74 if (! (theSource >> aDeltaValue))
75 return Standard_False;
77 aDelta = (aDeltaValue != 0);
80 else if(BinMDataStd::DocumentVersion() == -1)
81 cout << "Current DocVersion field is not initialized. " <<endl;
83 anAtt->SetDelta(aDelta);
85 BinMDataStd::SetAttributeID(theSource, anAtt);
89 //=======================================================================
91 //purpose : transient -> persistent (store)
92 //=======================================================================
94 void BinMDataStd_IntegerArrayDriver::Paste
95 (const Handle(TDF_Attribute)& theSource,
96 BinObjMgt_Persistent& theTarget,
97 BinObjMgt_SRelocationTable& ) const
99 Handle(TDataStd_IntegerArray) anAtt =
100 Handle(TDataStd_IntegerArray)::DownCast(theSource);
101 const TColStd_Array1OfInteger& aSourceArray = anAtt->Array()->Array1();
102 const Standard_Integer aFirstInd = aSourceArray.Lower();
103 const Standard_Integer aLastInd = aSourceArray.Upper();
104 const Standard_Integer aLength = aLastInd - aFirstInd + 1;
105 theTarget << aFirstInd << aLastInd;
106 Standard_Integer *aPtr = (Standard_Integer *) &aSourceArray(aFirstInd);
107 theTarget.PutIntArray (aPtr, aLength);
108 theTarget << (Standard_Byte)(anAtt->GetDelta() ? 1 : 0);
110 // process user defined guid
111 if(anAtt->ID() != TDataStd_IntegerArray::GetID())
112 theTarget << anAtt->ID();