1 // Created on: 2007-05-29
2 // Created by: Vlad Romashko
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.
17 #include <BinMDataStd.hxx>
18 #include <BinMDataStd_ByteArrayDriver.hxx>
19 #include <BinObjMgt_Persistent.hxx>
20 #include <Message_Messenger.hxx>
21 #include <Standard_Type.hxx>
22 #include <TColStd_Array1OfInteger.hxx>
23 #include <TColStd_HArray1OfByte.hxx>
24 #include <TDataStd_ByteArray.hxx>
25 #include <TDF_Attribute.hxx>
27 IMPLEMENT_STANDARD_RTTIEXT(BinMDataStd_ByteArrayDriver,BinMDF_ADriver)
29 //=======================================================================
30 //function : BinMDataStd_ByteArrayDriver
31 //purpose : Constructor
32 //=======================================================================
33 BinMDataStd_ByteArrayDriver::BinMDataStd_ByteArrayDriver(const Handle(Message_Messenger)& theMsgDriver)
34 : BinMDF_ADriver (theMsgDriver, STANDARD_TYPE(TDataStd_ByteArray)->Name())
39 //=======================================================================
42 //=======================================================================
43 Handle(TDF_Attribute) BinMDataStd_ByteArrayDriver::NewEmpty() const
45 return new TDataStd_ByteArray();
48 //=======================================================================
50 //purpose : persistent -> transient (retrieve)
51 //=======================================================================
52 Standard_Boolean BinMDataStd_ByteArrayDriver::Paste(const BinObjMgt_Persistent& theSource,
53 const Handle(TDF_Attribute)& theTarget,
54 BinObjMgt_RRelocationTable& ) const
56 Standard_Integer aFirstInd, aLastInd;
57 if (! (theSource >> aFirstInd >> aLastInd))
58 return Standard_False;
59 if (aLastInd < aFirstInd)
60 return Standard_False;
62 TColStd_Array1OfByte aTargetArray(aFirstInd, aLastInd);
63 theSource.GetByteArray (&aTargetArray(aFirstInd), aTargetArray.Length());
65 const Handle(TDataStd_ByteArray) anAtt = Handle(TDataStd_ByteArray)::DownCast(theTarget);
66 Handle(TColStd_HArray1OfByte) bytes = new TColStd_HArray1OfByte(aFirstInd, aLastInd);
67 for (Standard_Integer i = aFirstInd; i <= aLastInd; i++)
69 bytes->SetValue(i, aTargetArray.Value(i));
71 anAtt->ChangeArray(bytes);
73 Standard_Boolean aDelta(Standard_False);
74 if(BinMDataStd::DocumentVersion() > 2) {
75 Standard_Byte aDeltaValue;
76 if (! (theSource >> aDeltaValue))
77 return Standard_False;
79 aDelta = (aDeltaValue != 0);
81 anAtt->SetDelta(aDelta);
83 BinMDataStd::SetAttributeID(theSource, anAtt);
87 //=======================================================================
89 //purpose : transient -> persistent (store)
90 //=======================================================================
91 void BinMDataStd_ByteArrayDriver::Paste(const Handle(TDF_Attribute)& theSource,
92 BinObjMgt_Persistent& theTarget,
93 BinObjMgt_SRelocationTable& ) const
95 Handle(TDataStd_ByteArray) anAtt = Handle(TDataStd_ByteArray)::DownCast(theSource);
96 const Standard_Integer aFirstInd = anAtt->Lower();
97 const Standard_Integer aLastInd = anAtt->Upper();
98 if (aLastInd < aFirstInd)
100 theTarget << aFirstInd << aLastInd;
102 const Handle(TColStd_HArray1OfByte)& bytes = anAtt->InternalArray();
103 Standard_Integer lower = bytes->Lower(), i = lower, upper = bytes->Upper();
104 TColStd_Array1OfByte aSourceArray(lower, upper);
105 for (; i <= upper; i++)
107 aSourceArray.SetValue(i, bytes->Value(i));
109 Standard_Byte *aPtr = (Standard_Byte *) &aSourceArray(lower);
110 theTarget.PutByteArray(aPtr, bytes->Length());
111 theTarget << (Standard_Byte)(anAtt->GetDelta() ? 1 : 0);
113 // process user defined guid
114 if(anAtt->ID() != TDataStd_ByteArray::GetID())
115 theTarget << anAtt->ID();