0023024: Update headers of OCCT files
[occt.git] / src / XmlMDataStd / XmlMDataStd_RealDriver.cxx
1 // Created on: 2001-08-24
2 // Created by: Alexnder GRIGORIEV
3 // Copyright (c) 2001-2012 OPEN CASCADE SAS
4 //
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
9 //
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 //
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
19
20 //AGV 150202: Changed prototype XmlObjMgt::SetStringValue()
21
22 #define OCC6010 // vro 09.06.2004
23
24 #include <stdio.h>
25 #include <XmlMDataStd_RealDriver.ixx>
26 #include <TDataStd_Real.hxx>
27 #include <XmlObjMgt.hxx>
28
29 //=======================================================================
30 //function : XmlMDataStd_RealDriver
31 //purpose  : Constructor
32 //=======================================================================
33
34 XmlMDataStd_RealDriver::XmlMDataStd_RealDriver
35                         (const Handle(CDM_MessageDriver)& theMsgDriver)
36       : XmlMDF_ADriver (theMsgDriver, NULL)
37 {}
38
39 //=======================================================================
40 //function : NewEmpty
41 //purpose  : 
42 //=======================================================================
43 Handle(TDF_Attribute) XmlMDataStd_RealDriver::NewEmpty() const
44 {
45   return (new TDataStd_Real());
46 }
47
48 //=======================================================================
49 //function : Paste
50 //purpose  : persistent -> transient (retrieve)
51 //=======================================================================
52 Standard_Boolean XmlMDataStd_RealDriver::Paste
53                                         (const XmlObjMgt_Persistent&  theSource,
54                                          const Handle(TDF_Attribute)& theTarget,
55                                          XmlObjMgt_RRelocationTable&  ) const
56 {
57   Standard_Real aValue;
58   XmlObjMgt_DOMString aRealStr= XmlObjMgt::GetStringValue (theSource);
59
60   if (XmlObjMgt::GetReal(aRealStr, aValue) == Standard_False) {
61     TCollection_ExtendedString aMessageString =
62       TCollection_ExtendedString("Cannot retrieve Real attribute from \"")
63         + aRealStr + "\"";
64     WriteMessage (aMessageString);
65     return Standard_False;
66   }
67
68   Handle(TDataStd_Real) anInt = Handle(TDataStd_Real)::DownCast(theTarget);
69   anInt->Set(aValue);
70
71   return Standard_True;
72 }
73
74 //=======================================================================
75 //function : Paste
76 //purpose  : transient -> persistent (store)
77 //=======================================================================
78 void XmlMDataStd_RealDriver::Paste (const Handle(TDF_Attribute)& theSource,
79                                     XmlObjMgt_Persistent&        theTarget,
80                                     XmlObjMgt_SRelocationTable&  ) const
81 {
82   Handle(TDataStd_Real) anInt = Handle(TDataStd_Real)::DownCast(theSource);
83 #ifndef OCC6010
84   TCollection_AsciiString aValueStr (anInt->Get());
85 #else
86   char aValueChar[32];
87   sprintf(aValueChar, "%.15g", anInt->Get());
88   TCollection_AsciiString aValueStr(aValueChar);
89 #endif
90   // No occurrence of '&', '<' and other irregular XML characters
91   XmlObjMgt::SetStringValue (theTarget, aValueStr.ToCString(), Standard_True);
92 }