0027960: Configuration - fix compilation of OSD_Directory with MinGW-w64
[occt.git] / src / BinMFunction / BinMFunction_ScopeDriver.cxx
... / ...
CommitLineData
1// Created on: 2008-05-11
2// Created by: Vlad Romashko
3// Copyright (c) 2008-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 <BinMDF_ADriver.hxx>
18#include <BinMFunction_ScopeDriver.hxx>
19#include <BinObjMgt_Persistent.hxx>
20#include <BinObjMgt_RRelocationTable.hxx>
21#include <BinObjMgt_SRelocationTable.hxx>
22#include <CDM_MessageDriver.hxx>
23#include <Standard_Type.hxx>
24#include <TColStd_Array1OfInteger.hxx>
25#include <TDF_Attribute.hxx>
26#include <TDF_Label.hxx>
27#include <TDF_Tool.hxx>
28#include <TFunction_DoubleMapIteratorOfDoubleMapOfIntegerLabel.hxx>
29#include <TFunction_Scope.hxx>
30
31IMPLEMENT_STANDARD_RTTIEXT(BinMFunction_ScopeDriver,BinMDF_ADriver)
32
33//=======================================================================
34//function : BinMFunction_GraphNodeDriver
35//purpose :
36//=======================================================================
37BinMFunction_ScopeDriver::BinMFunction_ScopeDriver(const Handle(CDM_MessageDriver)& theMsgDriver)
38: BinMDF_ADriver (theMsgDriver, STANDARD_TYPE(TFunction_Scope)->Name())
39{
40}
41
42//=======================================================================
43//function : NewEmpty
44//purpose :
45//=======================================================================
46
47Handle(TDF_Attribute) BinMFunction_ScopeDriver::NewEmpty() const
48{
49 return new TFunction_Scope();
50}
51
52//=======================================================================
53//function : Paste
54//purpose : persistent -> transient (retrieve)
55//=======================================================================
56
57Standard_Boolean BinMFunction_ScopeDriver::Paste(const BinObjMgt_Persistent& theSource,
58 const Handle(TDF_Attribute)& theTarget,
59 BinObjMgt_RRelocationTable& ) const
60{
61 Handle(TFunction_Scope) S = Handle(TFunction_Scope)::DownCast(theTarget);
62
63 Standard_Integer nb;
64 if ( !(theSource >> nb) )
65 return Standard_False;
66 if (!nb)
67 return Standard_True;
68
69 TFunction_DoubleMapOfIntegerLabel& map = S->ChangeFunctions();
70
71 // IDs
72 TColStd_Array1OfInteger IDs(1, nb);
73 theSource.GetIntArray (&IDs(1), nb);
74
75 // Labels
76 Standard_Integer freeID = 0;
77 for (Standard_Integer i = 1; i <= nb; i++)
78 {
79 TCollection_AsciiString entry;
80 if ( !(theSource >> entry) )
81 return Standard_False;
82 TDF_Label L;
83 TDF_Tool::Label(S->Label().Data(), entry, L, Standard_True);
84 if (!L.IsNull())
85 {
86 map.Bind(IDs.Value(i), L);
87 if (IDs.Value(i) > freeID)
88 freeID = IDs.Value(i);
89 }
90 }
91
92 // Free ID
93 freeID++;
94 S->SetFreeID(freeID);
95
96 return Standard_True;
97}
98
99//=======================================================================
100//function : Paste
101//purpose : transient -> persistent (store)
102//=======================================================================
103
104void BinMFunction_ScopeDriver::Paste (const Handle(TDF_Attribute)& theSource,
105 BinObjMgt_Persistent& theTarget,
106 BinObjMgt_SRelocationTable& ) const
107{
108 Handle(TFunction_Scope) S = Handle(TFunction_Scope)::DownCast(theSource);
109 const TFunction_DoubleMapOfIntegerLabel& map = S->GetFunctions();
110 const Standard_Integer nb = map.Extent();
111
112 // Number of functions
113 theTarget << nb;
114 if (!nb)
115 return;
116
117 // IDs
118 {
119 TColStd_Array1OfInteger aSourceArray(1, nb);
120 TFunction_DoubleMapIteratorOfDoubleMapOfIntegerLabel itr(map);
121 for (Standard_Integer i = 1; itr.More(); itr.Next(), i++)
122 {
123 aSourceArray.SetValue(i, itr.Key1());
124 }
125 Standard_Integer *aPtr = (Standard_Integer *) &aSourceArray(1);
126 theTarget.PutIntArray(aPtr, nb);
127 }
128
129 // Labels
130 {
131 TFunction_DoubleMapIteratorOfDoubleMapOfIntegerLabel itr(map);
132 for (; itr.More(); itr.Next())
133 {
134 TDF_Label L = itr.Key2();
135 if (!L.IsNull())
136 {
137 TCollection_AsciiString entry;
138 TDF_Tool::Entry(L, entry);
139 theTarget << entry;
140 }
141 }
142 }
143}
144