summaryrefslogtreecommitdiff
path: root/src/XmlMFunction/XmlMFunction_FunctionDriver.cxx
blob: 16f5fdf0723a71583796646495653fd077597985 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// File:      XmlMFunction_FunctionDriver.cxx
// Created:   04.09.01 14:47:31
// Author:    Julia DOROVSKIKH
// Copyright: Open Cascade 2001
// History:

#include <XmlMFunction_FunctionDriver.ixx>

#include <XmlObjMgt.hxx>

#include <TFunction_Function.hxx>
#include <TDF_Tool.hxx>

IMPLEMENT_DOMSTRING (GuidString, "guid")
IMPLEMENT_DOMSTRING (FailureString, "failure")

//=======================================================================
//function : XmlMFunction_FunctionDriver
//purpose  : Constructor
//=======================================================================
XmlMFunction_FunctionDriver::XmlMFunction_FunctionDriver
                        (const Handle(CDM_MessageDriver)& theMsgDriver)
      : XmlMDF_ADriver (theMsgDriver, NULL)
{}

//=======================================================================
//function : NewEmpty
//purpose  : 
//=======================================================================
Handle(TDF_Attribute) XmlMFunction_FunctionDriver::NewEmpty() const
{
  return (new TFunction_Function());
}

//=======================================================================
//function : Paste
//purpose  : persistent -> transient (retrieve)
//=======================================================================
Standard_Boolean XmlMFunction_FunctionDriver::Paste
                (const XmlObjMgt_Persistent&  theSource,
                 const Handle(TDF_Attribute)& theTarget,
                 XmlObjMgt_RRelocationTable&  ) const
{
  Handle(TFunction_Function) aF = Handle(TFunction_Function)::DownCast(theTarget);

  // function GUID
  XmlObjMgt_DOMString aGuidDomStr =
    theSource.Element().getAttribute(::GuidString());
  Standard_CString aGuidStr = (Standard_CString)aGuidDomStr.GetString();
  if (aGuidStr[0] == '\0')
  {
    WriteMessage ("error retrieving GUID for type TFunction_Function");
    return Standard_False;
  }
  aF->SetDriverGUID(aGuidStr);

  // failure
  Standard_Integer aValue;
  XmlObjMgt_DOMString aFStr = theSource.Element().getAttribute(::FailureString());
  if (!aFStr.GetInteger(aValue))
  {
    TCollection_ExtendedString aMessageString =
      TCollection_ExtendedString
        ("Cannot retrieve failure number for TFunction_Function attribute from \"")
          + aFStr + "\"";
    WriteMessage (aMessageString);
    return Standard_False;
  }
  aF->SetFailure(aValue);

  return Standard_True;
}

//=======================================================================
//function : Paste
//purpose  : transient -> persistent (store)
//=======================================================================
void XmlMFunction_FunctionDriver::Paste (const Handle(TDF_Attribute)& theSource,
                                         XmlObjMgt_Persistent&        theTarget,
                                         XmlObjMgt_SRelocationTable&  ) const
{
  Handle(TFunction_Function) aF =
    Handle(TFunction_Function)::DownCast(theSource);
  if (!aF.IsNull())
  {
    //convert GUID into attribute value
    Standard_Character aGuidStr [40];
    Standard_PCharacter pGuidStr;
    //
    pGuidStr=aGuidStr;
    aF->GetDriverGUID().ToCString(pGuidStr);
    theTarget.Element().setAttribute(::GuidString(), aGuidStr);

    //integer value of failure
    theTarget.Element().setAttribute(::FailureString(), aF->GetFailure());
  }
}