0029915: Porting to VC 2017 : Regressions in Modeling Algorithms on VC 2017
[occt.git] / src / BinMDataStd / BinMDataStd_RealArrayDriver.cxx
1 // Created on: 2002-10-31
2 // Created by: Michael SAZONOV
3 // Copyright (c) 2002-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.hxx>
18 #include <BinMDataStd_RealArrayDriver.hxx>
19 #include <BinObjMgt_Persistent.hxx>
20 #include <Message_Messenger.hxx>
21 #include <Standard_Type.hxx>
22 #include <TColStd_HArray1OfReal.hxx>
23 #include <TDataStd_RealArray.hxx>
24 #include <TDF_Attribute.hxx>
25
26 IMPLEMENT_STANDARD_RTTIEXT(BinMDataStd_RealArrayDriver,BinMDF_ADriver)
27
28 //=======================================================================
29 //function : BinMDataStd_RealArrayDriver
30 //purpose  : Constructor
31 //=======================================================================
32 BinMDataStd_RealArrayDriver::BinMDataStd_RealArrayDriver
33                         (const Handle(Message_Messenger)& theMsgDriver)
34      : BinMDF_ADriver (theMsgDriver, STANDARD_TYPE(TDataStd_RealArray)->Name())
35 {
36 }
37
38 //=======================================================================
39 //function : NewEmpty
40 //purpose  : 
41 //=======================================================================
42
43 Handle(TDF_Attribute) BinMDataStd_RealArrayDriver::NewEmpty() const
44 {
45   return new TDataStd_RealArray();
46 }
47
48 //=======================================================================
49 //function : Paste
50 //purpose  : persistent -> transient (retrieve)
51 //=======================================================================
52
53 Standard_Boolean BinMDataStd_RealArrayDriver::Paste
54                                 (const BinObjMgt_Persistent&  theSource,
55                                  const Handle(TDF_Attribute)& theTarget,
56                                  BinObjMgt_RRelocationTable&  ) const
57 {
58   Standard_Integer aFirstInd, aLastInd;
59   if (! (theSource >> aFirstInd >> aLastInd))
60     return Standard_False;
61   const Standard_Integer aLength = aLastInd - aFirstInd + 1;
62   if (aLength <= 0)
63     return Standard_False;
64
65   const Handle(TDataStd_RealArray) anAtt =
66     Handle(TDataStd_RealArray)::DownCast(theTarget);
67   anAtt->Init(aFirstInd, aLastInd);
68   TColStd_Array1OfReal& aTargetArray = anAtt->Array()->ChangeArray1();
69   if(!theSource.GetRealArray (&aTargetArray(aFirstInd), aLength))
70     return Standard_False;
71
72   Standard_Boolean aDelta(Standard_False);
73   if(BinMDataStd::DocumentVersion() > 2) {
74     Standard_Byte aDeltaValue;
75     if (! (theSource >> aDeltaValue))
76       return Standard_False;
77     else
78       aDelta = (aDeltaValue != 0);
79   }
80   anAtt->SetDelta(aDelta);
81
82   BinMDataStd::SetAttributeID(theSource, anAtt);
83   return Standard_True; 
84 }
85
86 //=======================================================================
87 //function : Paste
88 //purpose  : transient -> persistent (store)
89 //=======================================================================
90
91 void BinMDataStd_RealArrayDriver::Paste
92                                 (const Handle(TDF_Attribute)& theSource,
93                                  BinObjMgt_Persistent&        theTarget,
94                                  BinObjMgt_SRelocationTable&  ) const
95 {
96   Handle(TDataStd_RealArray) anAtt =
97     Handle(TDataStd_RealArray)::DownCast(theSource);
98   const TColStd_Array1OfReal& aSourceArray = anAtt->Array()->Array1();
99   const Standard_Integer aFirstInd = aSourceArray.Lower();
100   const Standard_Integer aLastInd  = aSourceArray.Upper();
101   const Standard_Integer aLength   = aLastInd - aFirstInd + 1;
102   theTarget << aFirstInd << aLastInd;
103   Standard_Real *aPtr = (Standard_Real *) &aSourceArray(aFirstInd);
104   theTarget.PutRealArray (aPtr, aLength);
105   theTarget << (Standard_Byte)(anAtt->GetDelta() ? 1 : 0);
106   // process user defined guid
107   if(anAtt->ID() != TDataStd_RealArray::GetID()) 
108     theTarget << anAtt->ID();
109 }