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