0024870: Provide OCCT RTTI test cases
[occt.git] / src / XmlMFunction / XmlMFunction_GraphNodeDriver.cxx
CommitLineData
b311480e 1// Created on: 2008-03-07
2// Created by: Vlad ROMASHKO
973c2be1 3// Copyright (c) 2008-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
7fd59977 16
42cf5bc1 17#include <CDM_MessageDriver.hxx>
18#include <Standard_Type.hxx>
7fd59977 19#include <TColStd_MapIteratorOfMapOfInteger.hxx>
42cf5bc1 20#include <TDF_Attribute.hxx>
21#include <TFunction_GraphNode.hxx>
22#include <XmlMFunction_GraphNodeDriver.hxx>
23#include <XmlObjMgt.hxx>
24#include <XmlObjMgt_Persistent.hxx>
7fd59977 25
26IMPLEMENT_DOMSTRING (LastPreviousIndex, "lastprev")
27IMPLEMENT_DOMSTRING (LastNextIndex, "lastnext")
28IMPLEMENT_DOMSTRING (ExecutionStatus, "exec")
29
30//=======================================================================
31//function : XmlMFunction_GraphNodeDriver
32//purpose : Constructor
33//=======================================================================
34XmlMFunction_GraphNodeDriver::XmlMFunction_GraphNodeDriver(const Handle(CDM_MessageDriver)& theMsgDriver)
35 : XmlMDF_ADriver (theMsgDriver, NULL)
36{
37
38}
39
40//=======================================================================
41//function : NewEmpty
42//purpose :
43//=======================================================================
44Handle(TDF_Attribute) XmlMFunction_GraphNodeDriver::NewEmpty() const
45{
46 return (new TFunction_GraphNode());
47}
48
49//=======================================================================
50//function : Paste
51//purpose : persistent -> transient (retrieve)
52//=======================================================================
53Standard_Boolean XmlMFunction_GraphNodeDriver::Paste(const XmlObjMgt_Persistent& theSource,
54 const Handle(TDF_Attribute)& theTarget,
55 XmlObjMgt_RRelocationTable& ) const
56{
57 Handle(TFunction_GraphNode) G = Handle(TFunction_GraphNode)::DownCast(theTarget);
58
59 Standard_Integer aFirstIndPrev, aLastIndPrev, aFirstIndNext, aLastIndNext, aValue, ind;
60 const XmlObjMgt_Element& anElement = theSource;
61
62 // Previous
63 // ========
64
65 // Read the FirstIndex; if the attribute is absent initialize to 1
66 aFirstIndPrev = 1; // It is absent :-) because I didn't wrote it on the stage of writing the file.
67
68 // Read the LastIndex; the attribute should present
69 if (!anElement.getAttribute(::LastPreviousIndex()).GetInteger(aLastIndPrev))
70 {
71 TCollection_ExtendedString aMessageString =
72 TCollection_ExtendedString("Cannot retrieve the last index"
73 " for previous functions of GraphNode attribute");
74 WriteMessage (aMessageString);
75 return Standard_False;
76 }
77
78 if (aFirstIndPrev == aLastIndPrev)
79 {
80 Standard_Integer anInteger;
81 if (!XmlObjMgt::GetStringValue(anElement).GetInteger(anInteger))
82 {
83 TCollection_ExtendedString aMessageString =
84 TCollection_ExtendedString("Cannot retrieve integer member"
85 " for previous functions of GraphNode attribute");
86 WriteMessage (aMessageString);
87 return Standard_False;
88 }
89 G->AddPrevious(anInteger);
90 }
91 else
92 {
93 Standard_CString aValueStr =
94 Standard_CString(XmlObjMgt::GetStringValue(anElement).GetString());
95
96 for (ind = aFirstIndPrev; ind <= aLastIndPrev; ind++)
97 {
98 if (!XmlObjMgt::GetInteger(aValueStr, aValue))
99 {
100 TCollection_ExtendedString aMessageString =
101 TCollection_ExtendedString("Cannot retrieve integer member"
102 " for previous functions of GraphNode attribute as \"")
103 + aValueStr + "\"";
104 WriteMessage (aMessageString);
105 return Standard_False;
106 }
107 G->AddPrevious(aValue);
108 }
109 }
110
111
112 // Next
113 // ====
114
115 // Read the FirstIndex; if the attribute is absent initialize to 1
116 aFirstIndNext = aLastIndPrev + 1; // It is absent :-) because I didn't wrote it on the stage of writing the file.
117
118 // Read the LastIndex; the attribute should present
119 if (!anElement.getAttribute(::LastNextIndex()).GetInteger(aLastIndNext))
120 {
121 TCollection_ExtendedString aMessageString =
122 TCollection_ExtendedString("Cannot retrieve the last index"
123 " for next functions of GraphNode attribute");
124 WriteMessage (aMessageString);
125 return Standard_False;
126 }
127 aLastIndNext += aLastIndPrev;
128
129 Standard_CString aValueStr =
130 Standard_CString(XmlObjMgt::GetStringValue(anElement).GetString());
131
132 for (ind = 1; ind <= aLastIndNext; ind++)
133 {
134 if (!XmlObjMgt::GetInteger(aValueStr, aValue))
135 {
136 TCollection_ExtendedString aMessageString =
137 TCollection_ExtendedString("Cannot retrieve integer member"
138 " for next functions of GraphNode attribute as \"")
139 + aValueStr + "\"";
140 WriteMessage (aMessageString);
141 return Standard_False;
142 }
143 if (ind < aFirstIndNext)
144 continue;
145 G->AddNext(aValue);
146 }
147
148 // Execution status
149 Standard_Integer exec = 0;
150 if (!anElement.getAttribute(::ExecutionStatus()).GetInteger(exec))
151 {
152 TCollection_ExtendedString aMessageString =
153 TCollection_ExtendedString("Cannot retrieve the execution status"
154 " for GraphNode attribute");
155 WriteMessage (aMessageString);
156 return Standard_False;
157 }
158 G->SetStatus((TFunction_ExecutionStatus) exec);
159
160 return Standard_True;
161}
162
163//=======================================================================
164//function : Paste
165//purpose : transient -> persistent (store)
166//=======================================================================
167void XmlMFunction_GraphNodeDriver::Paste (const Handle(TDF_Attribute)& theSource,
168 XmlObjMgt_Persistent& theTarget,
169 XmlObjMgt_SRelocationTable& ) const
170{
171 Handle(TFunction_GraphNode) G = Handle(TFunction_GraphNode)::DownCast(theSource);
172
173 // Previous
174 // ========
175
176 theTarget.Element().setAttribute(::LastPreviousIndex(), G->GetPrevious().Extent());
177
178 TCollection_AsciiString aValueStr;
179 TColStd_MapIteratorOfMapOfInteger itrm(G->GetPrevious());
180 for (; itrm.More(); itrm.Next())
181 {
182 const Standard_Integer ID = itrm.Key();
183 aValueStr += TCollection_AsciiString(ID);
184 aValueStr += ' ';
185 }
186 aValueStr += "\n";
187
188 // Next
189 // ====
190
191 theTarget.Element().setAttribute(::LastNextIndex(), G->GetNext().Extent());
192
193 itrm.Initialize(G->GetNext());
194 for (; itrm.More(); itrm.Next())
195 {
196 const Standard_Integer ID = itrm.Key();
197 aValueStr += TCollection_AsciiString(ID);
198 aValueStr += ' ';
199 }
200
201 XmlObjMgt::SetStringValue (theTarget, aValueStr.ToCString(), Standard_True);
202
203 // Execution status
204 theTarget.Element().setAttribute(::ExecutionStatus(), (Standard_Integer) G->GetStatus());
205}