0029915: Porting to VC 2017 : Regressions in Modeling Algorithms on VC 2017
[occt.git] / src / BinMDataStd / BinMDataStd_ReferenceArrayDriver.cxx
CommitLineData
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_ReferenceArrayDriver.hxx>
5a1271c8 18#include <BinMDataStd.hxx>
42cf5bc1 19#include <BinObjMgt_Persistent.hxx>
83ae3591 20#include <Message_Messenger.hxx>
42cf5bc1 21#include <Standard_Type.hxx>
7fd59977 22#include <TDataStd_ReferenceArray.hxx>
42cf5bc1 23#include <TDF_Attribute.hxx>
7fd59977 24#include <TDF_Label.hxx>
25#include <TDF_Tool.hxx>
26
92efcf78 27IMPLEMENT_STANDARD_RTTIEXT(BinMDataStd_ReferenceArrayDriver,BinMDF_ADriver)
28
7fd59977 29//=======================================================================
30//function : BinMDataStd_ReferenceArrayDriver
31//purpose : Constructor
32//=======================================================================
83ae3591 33BinMDataStd_ReferenceArrayDriver::BinMDataStd_ReferenceArrayDriver(const Handle(Message_Messenger)& theMsgDriver)
7fd59977 34 : BinMDF_ADriver (theMsgDriver, STANDARD_TYPE(TDataStd_ReferenceArray)->Name())
35{
36
37}
38
39//=======================================================================
40//function : NewEmpty
41//purpose :
42//=======================================================================
43Handle(TDF_Attribute) BinMDataStd_ReferenceArrayDriver::NewEmpty() const
44{
45 return new TDataStd_ReferenceArray();
46}
47
48//=======================================================================
49//function : Paste
50//purpose : persistent -> transient (retrieve)
51//=======================================================================
52Standard_Boolean BinMDataStd_ReferenceArrayDriver::Paste(const BinObjMgt_Persistent& theSource,
5a1271c8 53 const Handle(TDF_Attribute)& theTarget,
54 BinObjMgt_RRelocationTable& ) const
7fd59977 55{
56 Standard_Integer aFirstInd, aLastInd;
57 if (! (theSource >> aFirstInd >> aLastInd))
58 return Standard_False;
59 const Standard_Integer aLength = aLastInd - aFirstInd + 1;
60 if (aLength <= 0)
61 return Standard_False;
62
5a1271c8 63 const Handle(TDataStd_ReferenceArray) anAtt = Handle(TDataStd_ReferenceArray)::DownCast(theTarget);
7fd59977 64 anAtt->Init(aFirstInd, aLastInd);
65 for (Standard_Integer i = aFirstInd; i <= aLastInd; i++)
66 {
67 TCollection_AsciiString entry;
68 if ( !(theSource >> entry) )
69 return Standard_False;
70 TDF_Label L;
71 TDF_Tool::Label(anAtt->Label().Data(), entry, L, Standard_True);
72 if (!L.IsNull())
73 anAtt->SetValue(i, L);
74 }
75
5a1271c8 76 BinMDataStd::SetAttributeID(theSource, anAtt);
7fd59977 77 return Standard_True;
78}
79
80//=======================================================================
81//function : Paste
82//purpose : transient -> persistent (store)
83//=======================================================================
84void BinMDataStd_ReferenceArrayDriver::Paste(const Handle(TDF_Attribute)& theSource,
5a1271c8 85 BinObjMgt_Persistent& theTarget,
86 BinObjMgt_SRelocationTable& ) const
7fd59977 87{
88 Handle(TDataStd_ReferenceArray) anAtt = Handle(TDataStd_ReferenceArray)::DownCast(theSource);
89 Standard_Integer aFirstInd = anAtt->Lower(), aLastInd = anAtt->Upper(), i = aFirstInd;
90 if (aFirstInd > aLastInd)
91 return;
92 theTarget << aFirstInd << aLastInd;
93 for (; i <= aLastInd; i++)
94 {
95 TDF_Label L = anAtt->Value(i);
96 if (!L.IsNull())
97 {
98 TCollection_AsciiString entry;
99 TDF_Tool::Entry(L, entry);
100 theTarget << entry;
101 }
102 }
5a1271c8 103
104 // process user defined guid
105 if(anAtt->ID() != TDataStd_ReferenceArray::GetID())
106 theTarget << anAtt->ID();
7fd59977 107}