0024870: Provide OCCT RTTI test cases
[occt.git] / src / XmlMFunction / XmlMFunction_FunctionDriver.cxx
CommitLineData
b311480e 1// Created on: 2001-09-04
2// Created by: Julia DOROVSKIKH
973c2be1 3// Copyright (c) 2001-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>
19#include <TDF_Attribute.hxx>
7fd59977 20#include <TDF_Tool.hxx>
42cf5bc1 21#include <TFunction_Function.hxx>
22#include <XmlMFunction_FunctionDriver.hxx>
23#include <XmlObjMgt.hxx>
24#include <XmlObjMgt_Persistent.hxx>
7fd59977 25
26IMPLEMENT_DOMSTRING (GuidString, "guid")
27IMPLEMENT_DOMSTRING (FailureString, "failure")
28
29//=======================================================================
30//function : XmlMFunction_FunctionDriver
31//purpose : Constructor
32//=======================================================================
33XmlMFunction_FunctionDriver::XmlMFunction_FunctionDriver
34 (const Handle(CDM_MessageDriver)& theMsgDriver)
35 : XmlMDF_ADriver (theMsgDriver, NULL)
36{}
37
38//=======================================================================
39//function : NewEmpty
40//purpose :
41//=======================================================================
42Handle(TDF_Attribute) XmlMFunction_FunctionDriver::NewEmpty() const
43{
44 return (new TFunction_Function());
45}
46
47//=======================================================================
48//function : Paste
49//purpose : persistent -> transient (retrieve)
50//=======================================================================
51Standard_Boolean XmlMFunction_FunctionDriver::Paste
52 (const XmlObjMgt_Persistent& theSource,
53 const Handle(TDF_Attribute)& theTarget,
54 XmlObjMgt_RRelocationTable& ) const
55{
56 Handle(TFunction_Function) aF = Handle(TFunction_Function)::DownCast(theTarget);
57
58 // function GUID
59 XmlObjMgt_DOMString aGuidDomStr =
60 theSource.Element().getAttribute(::GuidString());
61 Standard_CString aGuidStr = (Standard_CString)aGuidDomStr.GetString();
62 if (aGuidStr[0] == '\0')
63 {
64 WriteMessage ("error retrieving GUID for type TFunction_Function");
65 return Standard_False;
66 }
67 aF->SetDriverGUID(aGuidStr);
68
69 // failure
70 Standard_Integer aValue;
71 XmlObjMgt_DOMString aFStr = theSource.Element().getAttribute(::FailureString());
72 if (!aFStr.GetInteger(aValue))
73 {
74 TCollection_ExtendedString aMessageString =
75 TCollection_ExtendedString
76 ("Cannot retrieve failure number for TFunction_Function attribute from \"")
77 + aFStr + "\"";
78 WriteMessage (aMessageString);
79 return Standard_False;
80 }
81 aF->SetFailure(aValue);
82
83 return Standard_True;
84}
85
86//=======================================================================
87//function : Paste
88//purpose : transient -> persistent (store)
89//=======================================================================
90void XmlMFunction_FunctionDriver::Paste (const Handle(TDF_Attribute)& theSource,
91 XmlObjMgt_Persistent& theTarget,
92 XmlObjMgt_SRelocationTable& ) const
93{
94 Handle(TFunction_Function) aF =
95 Handle(TFunction_Function)::DownCast(theSource);
96 if (!aF.IsNull())
97 {
98 //convert GUID into attribute value
99 Standard_Character aGuidStr [40];
100 Standard_PCharacter pGuidStr;
101 //
102 pGuidStr=aGuidStr;
103 aF->GetDriverGUID().ToCString(pGuidStr);
104 theTarget.Element().setAttribute(::GuidString(), aGuidStr);
105
106 //integer value of failure
107 theTarget.Element().setAttribute(::FailureString(), aF->GetFailure());
108 }
109}