b311480e |
1 | // Created on: 2007-05-29 |
2 | // Created by: Vlad Romashko |
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. |
7fd59977 |
15 | |
42cf5bc1 |
16 | |
17 | #include <BinMDataStd_BooleanArrayDriver.hxx> |
18 | #include <BinObjMgt_Persistent.hxx> |
19 | #include <CDM_MessageDriver.hxx> |
20 | #include <Standard_Type.hxx> |
7fd59977 |
21 | #include <TColStd_Array1OfInteger.hxx> |
42cf5bc1 |
22 | #include <TColStd_HArray1OfByte.hxx> |
23 | #include <TDataStd_BooleanArray.hxx> |
24 | #include <TDF_Attribute.hxx> |
7fd59977 |
25 | |
92efcf78 |
26 | IMPLEMENT_STANDARD_RTTIEXT(BinMDataStd_BooleanArrayDriver,BinMDF_ADriver) |
27 | |
7fd59977 |
28 | //======================================================================= |
29 | //function : BinMDataStd_BooleanArrayDriver |
30 | //purpose : Constructor |
31 | //======================================================================= |
32 | BinMDataStd_BooleanArrayDriver::BinMDataStd_BooleanArrayDriver(const Handle(CDM_MessageDriver)& theMsgDriver) |
33 | : BinMDF_ADriver (theMsgDriver, STANDARD_TYPE(TDataStd_BooleanArray)->Name()) |
34 | { |
35 | |
36 | } |
37 | |
38 | //======================================================================= |
39 | //function : NewEmpty |
40 | //purpose : |
41 | //======================================================================= |
42 | Handle(TDF_Attribute) BinMDataStd_BooleanArrayDriver::NewEmpty() const |
43 | { |
44 | return new TDataStd_BooleanArray(); |
45 | } |
46 | |
47 | //======================================================================= |
48 | //function : Paste |
49 | //purpose : persistent -> transient (retrieve) |
50 | //======================================================================= |
51 | Standard_Boolean BinMDataStd_BooleanArrayDriver::Paste(const BinObjMgt_Persistent& theSource, |
52 | const Handle(TDF_Attribute)& theTarget, |
53 | BinObjMgt_RRelocationTable& ) const |
54 | { |
55 | Standard_Integer aFirstInd, aLastInd; |
56 | if (! (theSource >> aFirstInd >> aLastInd)) |
57 | return Standard_False; |
58 | if (aLastInd < aFirstInd) |
59 | return Standard_False; |
60 | |
61 | TColStd_Array1OfByte aTargetArray(0, (aLastInd - aFirstInd + 1) >> 3); |
62 | theSource.GetByteArray (&aTargetArray(0), aTargetArray.Length()); |
63 | |
64 | Handle(TDataStd_BooleanArray) anAtt = Handle(TDataStd_BooleanArray)::DownCast(theTarget); |
65 | anAtt->Init(aFirstInd, aLastInd); |
66 | Handle(TColStd_HArray1OfByte) bytes = new TColStd_HArray1OfByte(aTargetArray.Lower(), aTargetArray.Upper()); |
67 | Standard_Integer lower = bytes->Lower(), i = lower, upper = bytes->Upper(); |
68 | for (; i <= upper; i++) |
69 | { |
70 | bytes->SetValue(i, aTargetArray.Value(i)); |
71 | } |
72 | anAtt->SetInternalArray(bytes); |
73 | return Standard_True; |
74 | } |
75 | |
76 | //======================================================================= |
77 | //function : Paste |
78 | //purpose : transient -> persistent (store) |
79 | //======================================================================= |
80 | void BinMDataStd_BooleanArrayDriver::Paste(const Handle(TDF_Attribute)& theSource, |
81 | BinObjMgt_Persistent& theTarget, |
82 | BinObjMgt_SRelocationTable& ) const |
83 | { |
84 | Handle(TDataStd_BooleanArray) anAtt = Handle(TDataStd_BooleanArray)::DownCast(theSource); |
85 | const Standard_Integer aFirstInd = anAtt->Lower(); |
86 | const Standard_Integer aLastInd = anAtt->Upper(); |
87 | if (aLastInd < aFirstInd) |
88 | return; |
89 | theTarget << aFirstInd << aLastInd; |
90 | |
91 | const Handle(TColStd_HArray1OfByte)& bytes = anAtt->InternalArray(); |
92 | TColStd_Array1OfByte aSourceArray(bytes->Lower(), bytes->Upper()); |
93 | Standard_Integer lower = bytes->Lower(), i = lower, upper = bytes->Upper(); |
94 | for (; i <= upper; i++) |
95 | { |
96 | aSourceArray.SetValue(i, bytes->Value(i)); |
97 | } |
98 | Standard_Byte *aPtr = (Standard_Byte *) &aSourceArray(lower); |
99 | theTarget.PutByteArray(aPtr, upper - lower + 1); |
100 | } |