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