974ed9e8b9a295d8444ddec8b58767d4b64724d3
[occt.git] / src / BinMDataStd / BinMDataStd_BooleanListDriver.cxx
1 // Created on: 2007-05-29
2 // Created by: Vlad Romashko
3 // Copyright (c) 2007-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16
17 #include <BinMDataStd_BooleanListDriver.hxx>
18 #include <BinMDataStd.hxx>
19 #include <BinObjMgt_Persistent.hxx>
20 #include <CDM_MessageDriver.hxx>
21 #include <Standard_Type.hxx>
22 #include <TColStd_Array1OfByte.hxx>
23 #include <TDataStd_BooleanList.hxx>
24 #include <TDataStd_ListIteratorOfListOfByte.hxx>
25 #include <TDF_Attribute.hxx>
26
27 IMPLEMENT_STANDARD_RTTIEXT(BinMDataStd_BooleanListDriver,BinMDF_ADriver)
28
29 //=======================================================================
30 //function : BinMDataStd_BooleanListDriver
31 //purpose  : Constructor
32 //=======================================================================
33 BinMDataStd_BooleanListDriver::BinMDataStd_BooleanListDriver(const Handle(CDM_MessageDriver)& theMsgDriver)
34      : BinMDF_ADriver (theMsgDriver, STANDARD_TYPE(TDataStd_BooleanList)->Name())
35 {
36
37 }
38
39 //=======================================================================
40 //function : NewEmpty
41 //purpose  : 
42 //=======================================================================
43 Handle(TDF_Attribute) BinMDataStd_BooleanListDriver::NewEmpty() const
44 {
45   return new TDataStd_BooleanList();
46 }
47
48 //=======================================================================
49 //function : Paste
50 //purpose  : persistent -> transient (retrieve)
51 //=======================================================================
52 Standard_Boolean BinMDataStd_BooleanListDriver::Paste(const BinObjMgt_Persistent&  theSource,
53                                                       const Handle(TDF_Attribute)& theTarget,
54                                                       BinObjMgt_RRelocationTable&  ) const
55 {
56   Standard_Integer aIndex, aFirstInd, aLastInd;
57   if (! (theSource >> aFirstInd >> aLastInd))
58     return Standard_False;
59
60   const Handle(TDataStd_BooleanList) anAtt = Handle(TDataStd_BooleanList)::DownCast(theTarget);
61   if(aLastInd > 0) {
62
63     const Standard_Integer aLength = aLastInd - aFirstInd + 1;
64     if (aLength > 0) {    
65       TColStd_Array1OfByte aTargetArray(aFirstInd, aLastInd);
66       theSource.GetByteArray (&aTargetArray(aFirstInd), aLength);
67       for (aIndex = aFirstInd; aIndex <= aLastInd; aIndex++)
68       {
69         anAtt->Append(aTargetArray.Value(aIndex) ? Standard_True : Standard_False);
70       }
71     }
72   }
73
74   BinMDataStd::SetAttributeID(theSource, anAtt);
75   return Standard_True;
76 }
77
78 //=======================================================================
79 //function : Paste
80 //purpose  : transient -> persistent (store)
81 //=======================================================================
82 void BinMDataStd_BooleanListDriver::Paste(const Handle(TDF_Attribute)& theSource,
83                                           BinObjMgt_Persistent&        theTarget,
84                                           BinObjMgt_SRelocationTable&  ) const
85 {
86   const Handle(TDataStd_BooleanList) anAtt = Handle(TDataStd_BooleanList)::DownCast(theSource);
87   const Standard_Integer aFirstInd = (anAtt->Extent()> 0) ? 1 : 0;
88   const Standard_Integer aLastInd(anAtt->Extent());  
89   const Standard_Integer aLength   = aLastInd - aFirstInd + 1;
90   if (aLength <= 0) return;
91   theTarget << aFirstInd << aLastInd;
92   if(aLastInd == 0) return;
93   TColStd_Array1OfByte aSourceArray(aFirstInd, aLastInd);
94   TDataStd_ListIteratorOfListOfByte itr(anAtt->List());
95   for (Standard_Integer i = 1; itr.More(); itr.Next(), i++) {
96     aSourceArray.SetValue(i, itr.Value());
97   }
98   Standard_Byte *aPtr = (Standard_Byte *) &aSourceArray(aFirstInd);
99   theTarget.PutByteArray(aPtr, aLength);
100
101   // process user defined guid
102   if(anAtt->ID() != TDataStd_BooleanList::GetID()) 
103     theTarget << anAtt->ID();
104 }