0027772: Foundation Classes - define Standard_Boolean using C++ type "bool" instead...
[occt.git] / src / BinMDataStd / BinMDataStd_ExtStringArrayDriver.cxx
CommitLineData
b311480e 1// Created on: 2004-08-24
2// Created by: Pavel TELKOV
973c2be1 3// Copyright (c) 2004-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.hxx>
18#include <BinMDataStd_ExtStringArrayDriver.hxx>
7fd59977 19#include <BinObjMgt_Persistent.hxx>
42cf5bc1 20#include <CDM_MessageDriver.hxx>
21#include <Standard_Type.hxx>
7fd59977 22#include <TColStd_Array1OfExtendedString.hxx>
23#include <TColStd_HArray1OfExtendedString.hxx>
42cf5bc1 24#include <TDataStd_ExtStringArray.hxx>
25#include <TDF_Attribute.hxx>
26
92efcf78 27IMPLEMENT_STANDARD_RTTIEXT(BinMDataStd_ExtStringArrayDriver,BinMDF_ADriver)
28
7fd59977 29//=======================================================================
30//function : BinMDataStd_ExtStringArrayDriver
31//purpose : Constructor
32//=======================================================================
7fd59977 33BinMDataStd_ExtStringArrayDriver::BinMDataStd_ExtStringArrayDriver
34 (const Handle(CDM_MessageDriver)& theMsgDriver)
35 : BinMDF_ADriver (theMsgDriver, STANDARD_TYPE(TDataStd_ExtStringArray)->Name())
36{
37}
38
39//=======================================================================
40//function : NewEmpty
41//purpose :
42//=======================================================================
43
44Handle(TDF_Attribute) BinMDataStd_ExtStringArrayDriver::NewEmpty() const
45{
46 return new TDataStd_ExtStringArray();
47}
48
49//=======================================================================
50//function : Paste
51//purpose : persistent -> transient (retrieve)
52//=======================================================================
53
54Standard_Boolean BinMDataStd_ExtStringArrayDriver::Paste
55 (const BinObjMgt_Persistent& theSource,
56 const Handle(TDF_Attribute)& theTarget,
57 BinObjMgt_RRelocationTable& ) const
58{
59 Standard_Integer aFirstInd, aLastInd;
60 if (! (theSource >> aFirstInd >> aLastInd))
61 return Standard_False;
62 const Standard_Integer aLength = aLastInd - aFirstInd + 1;
63 if (aLength <= 0)
64 return Standard_False;
65
66 Handle(TDataStd_ExtStringArray) anAtt =
67 Handle(TDataStd_ExtStringArray)::DownCast(theTarget);
68 anAtt->Init(aFirstInd, aLastInd);
69 TColStd_Array1OfExtendedString& aTargetArray = anAtt->Array()->ChangeArray1();
70 Standard_Boolean ok = Standard_True;
71 for (Standard_Integer i = aFirstInd; i <= aLastInd; i ++)
72 {
73 TCollection_ExtendedString aStr;
74 if ( !(theSource >> aStr) )
75 {
76 ok = Standard_False;
77 break;
78 }
79 aTargetArray.SetValue( i, aStr );
80 }
81
82 if(ok) {
7fd59977 83 Standard_Boolean aDelta(Standard_False);
84 if(BinMDataStd::DocumentVersion() > 2) {
85 Standard_Byte aDeltaValue;
aa453132 86 if (! (theSource >> aDeltaValue)) {
aa453132 87 return Standard_False;
88 }
7fd59977 89 else
dde68833 90 aDelta = (aDeltaValue != 0);
aa453132 91 }
7fd59977 92 anAtt->SetDelta(aDelta);
93 }
94 return ok;
95}
96
97//=======================================================================
98//function : Paste
99//purpose : transient -> persistent (store)
100//=======================================================================
101
102void BinMDataStd_ExtStringArrayDriver::Paste
103 (const Handle(TDF_Attribute)& theSource,
104 BinObjMgt_Persistent& theTarget,
105 BinObjMgt_SRelocationTable& ) const
106{
107 Handle(TDataStd_ExtStringArray) anAtt =
108 Handle(TDataStd_ExtStringArray)::DownCast(theSource);
109 const TColStd_Array1OfExtendedString& aSourceArray = anAtt->Array()->Array1();
110 const Standard_Integer aFirstInd = aSourceArray.Lower();
111 const Standard_Integer aLastInd = aSourceArray.Upper();
7fd59977 112 theTarget << aFirstInd << aLastInd;
113 for (Standard_Integer i = aFirstInd; i <= aLastInd; i ++)
114 theTarget << anAtt->Value( i );
aa453132 115
dde68833 116 theTarget << (Standard_Byte)(anAtt->GetDelta() ? 1 : 0);
7fd59977 117}