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_BooleanListDriver.hxx> |
18 | #include <BinObjMgt_Persistent.hxx> |
19 | #include <CDM_MessageDriver.hxx> |
20 | #include <Standard_Type.hxx> |
21 | #include <TColStd_Array1OfByte.hxx> |
7fd59977 |
22 | #include <TDataStd_BooleanList.hxx> |
23 | #include <TDataStd_ListIteratorOfListOfByte.hxx> |
42cf5bc1 |
24 | #include <TDF_Attribute.hxx> |
7fd59977 |
25 | |
92efcf78 |
26 | IMPLEMENT_STANDARD_RTTIEXT(BinMDataStd_BooleanListDriver,BinMDF_ADriver) |
27 | |
7fd59977 |
28 | //======================================================================= |
29 | //function : BinMDataStd_BooleanListDriver |
30 | //purpose : Constructor |
31 | //======================================================================= |
32 | BinMDataStd_BooleanListDriver::BinMDataStd_BooleanListDriver(const Handle(CDM_MessageDriver)& theMsgDriver) |
33 | : BinMDF_ADriver (theMsgDriver, STANDARD_TYPE(TDataStd_BooleanList)->Name()) |
34 | { |
35 | |
36 | } |
37 | |
38 | //======================================================================= |
39 | //function : NewEmpty |
40 | //purpose : |
41 | //======================================================================= |
42 | Handle(TDF_Attribute) BinMDataStd_BooleanListDriver::NewEmpty() const |
43 | { |
44 | return new TDataStd_BooleanList(); |
45 | } |
46 | |
47 | //======================================================================= |
48 | //function : Paste |
49 | //purpose : persistent -> transient (retrieve) |
50 | //======================================================================= |
51 | Standard_Boolean BinMDataStd_BooleanListDriver::Paste(const BinObjMgt_Persistent& theSource, |
52 | const Handle(TDF_Attribute)& theTarget, |
53 | BinObjMgt_RRelocationTable& ) const |
54 | { |
55 | Standard_Integer aIndex, aFirstInd, aLastInd; |
56 | if (! (theSource >> aFirstInd >> aLastInd)) |
57 | return Standard_False; |
d585e74e |
58 | if(aLastInd == 0) return Standard_True; |
59 | |
7fd59977 |
60 | const Standard_Integer aLength = aLastInd - aFirstInd + 1; |
61 | if (aLength <= 0) |
62 | return Standard_False; |
7fd59977 |
63 | TColStd_Array1OfByte aTargetArray(aFirstInd, aLastInd); |
64 | theSource.GetByteArray (&aTargetArray(aFirstInd), aLength); |
65 | |
d585e74e |
66 | const Handle(TDataStd_BooleanList) anAtt = Handle(TDataStd_BooleanList)::DownCast(theTarget); |
7fd59977 |
67 | for (aIndex = aFirstInd; aIndex <= aLastInd; aIndex++) |
68 | { |
69 | anAtt->Append(aTargetArray.Value(aIndex) ? Standard_True : Standard_False); |
70 | } |
71 | return Standard_True; |
72 | } |
73 | |
74 | //======================================================================= |
75 | //function : Paste |
76 | //purpose : transient -> persistent (store) |
77 | //======================================================================= |
78 | void BinMDataStd_BooleanListDriver::Paste(const Handle(TDF_Attribute)& theSource, |
79 | BinObjMgt_Persistent& theTarget, |
80 | BinObjMgt_SRelocationTable& ) const |
81 | { |
d585e74e |
82 | const Handle(TDataStd_BooleanList) anAtt = Handle(TDataStd_BooleanList)::DownCast(theSource); |
83 | const Standard_Integer aFirstInd = (anAtt->Extent()> 0) ? 1 : 0; |
84 | const Standard_Integer aLastInd(anAtt->Extent()); |
7fd59977 |
85 | const Standard_Integer aLength = aLastInd - aFirstInd + 1; |
d585e74e |
86 | if (aLength <= 0) return; |
7fd59977 |
87 | theTarget << aFirstInd << aLastInd; |
d585e74e |
88 | if(aLastInd == 0) return; |
7fd59977 |
89 | TColStd_Array1OfByte aSourceArray(aFirstInd, aLastInd); |
d585e74e |
90 | TDataStd_ListIteratorOfListOfByte itr(anAtt->List()); |
91 | for (Standard_Integer i = 1; itr.More(); itr.Next(), i++) { |
92 | aSourceArray.SetValue(i, itr.Value()); |
7fd59977 |
93 | } |
d585e74e |
94 | Standard_Byte *aPtr = (Standard_Byte *) &aSourceArray(aFirstInd); |
95 | theTarget.PutByteArray(aPtr, aLength); |
7fd59977 |
96 | } |