7fd59977 |
1 | // File: BinMDataStd_BooleanListDriver.cxx |
2 | // Created: May 29 11:40:00 2007 |
3 | // Author: Vlad Romashko |
4 | // <vladislav.romashko@opencascade.com> |
5 | // Copyright: Open CASCADE |
6 | |
7 | #include <BinMDataStd_BooleanListDriver.ixx> |
8 | #include <TDataStd_BooleanList.hxx> |
9 | #include <TDataStd_ListIteratorOfListOfByte.hxx> |
10 | #include <TColStd_Array1OfByte.hxx> |
11 | |
12 | //======================================================================= |
13 | //function : BinMDataStd_BooleanListDriver |
14 | //purpose : Constructor |
15 | //======================================================================= |
16 | BinMDataStd_BooleanListDriver::BinMDataStd_BooleanListDriver(const Handle(CDM_MessageDriver)& theMsgDriver) |
17 | : BinMDF_ADriver (theMsgDriver, STANDARD_TYPE(TDataStd_BooleanList)->Name()) |
18 | { |
19 | |
20 | } |
21 | |
22 | //======================================================================= |
23 | //function : NewEmpty |
24 | //purpose : |
25 | //======================================================================= |
26 | Handle(TDF_Attribute) BinMDataStd_BooleanListDriver::NewEmpty() const |
27 | { |
28 | return new TDataStd_BooleanList(); |
29 | } |
30 | |
31 | //======================================================================= |
32 | //function : Paste |
33 | //purpose : persistent -> transient (retrieve) |
34 | //======================================================================= |
35 | Standard_Boolean BinMDataStd_BooleanListDriver::Paste(const BinObjMgt_Persistent& theSource, |
36 | const Handle(TDF_Attribute)& theTarget, |
37 | BinObjMgt_RRelocationTable& ) const |
38 | { |
39 | Standard_Integer aIndex, aFirstInd, aLastInd; |
40 | if (! (theSource >> aFirstInd >> aLastInd)) |
41 | return Standard_False; |
42 | const Standard_Integer aLength = aLastInd - aFirstInd + 1; |
43 | if (aLength <= 0) |
44 | return Standard_False; |
45 | |
46 | TColStd_Array1OfByte aTargetArray(aFirstInd, aLastInd); |
47 | theSource.GetByteArray (&aTargetArray(aFirstInd), aLength); |
48 | |
49 | Handle(TDataStd_BooleanList) anAtt = Handle(TDataStd_BooleanList)::DownCast(theTarget); |
50 | for (aIndex = aFirstInd; aIndex <= aLastInd; aIndex++) |
51 | { |
52 | anAtt->Append(aTargetArray.Value(aIndex) ? Standard_True : Standard_False); |
53 | } |
54 | return Standard_True; |
55 | } |
56 | |
57 | //======================================================================= |
58 | //function : Paste |
59 | //purpose : transient -> persistent (store) |
60 | //======================================================================= |
61 | void BinMDataStd_BooleanListDriver::Paste(const Handle(TDF_Attribute)& theSource, |
62 | BinObjMgt_Persistent& theTarget, |
63 | BinObjMgt_SRelocationTable& ) const |
64 | { |
65 | Handle(TDataStd_BooleanList) anAtt = Handle(TDataStd_BooleanList)::DownCast(theSource); |
66 | const Standard_Integer aFirstInd = 1; |
67 | const Standard_Integer aLastInd = anAtt->Extent(); |
68 | const Standard_Integer aLength = aLastInd - aFirstInd + 1; |
69 | if (aLength <= 0) |
70 | return; |
71 | theTarget << aFirstInd << aLastInd; |
72 | TColStd_Array1OfByte aSourceArray(aFirstInd, aLastInd); |
73 | if (aLastInd >= 1) |
74 | { |
75 | TDataStd_ListIteratorOfListOfByte itr(anAtt->List()); |
76 | for (Standard_Integer i = 1; itr.More(); itr.Next(), i++) |
77 | { |
78 | aSourceArray.SetValue(i, itr.Value()); |
79 | } |
80 | Standard_Byte *aPtr = (Standard_Byte *) &aSourceArray(aFirstInd); |
81 | theTarget.PutByteArray(aPtr, aLength); |
82 | } |
83 | } |