0027932: Improvement of standard attributes usability.
[occt.git] / src / BinMDataStd / BinMDataStd_AsciiStringDriver.cxx
1 // Created on: 2007-08-01
2 // Created by: Sergey ZARITCHNY
3 // Copyright (c) 2007-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 <BinMDataStd_AsciiStringDriver.hxx>
18 #include <BinMDF_ADriver.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 <TDataStd_AsciiString.hxx>
25 #include <TDF_Attribute.hxx>
26 #include <BinMDataStd.hxx>
27
28 IMPLEMENT_STANDARD_RTTIEXT(BinMDataStd_AsciiStringDriver,BinMDF_ADriver)
29
30 //=======================================================================
31 //function : BinMDataStd_AsciiStringDriver
32 //purpose  :
33 //=======================================================================
34 BinMDataStd_AsciiStringDriver::BinMDataStd_AsciiStringDriver
35                          (const Handle(CDM_MessageDriver)& theMessageDriver)
36      : BinMDF_ADriver (theMessageDriver, STANDARD_TYPE(TDataStd_AsciiString)->Name())
37 {
38 }
39
40 //=======================================================================
41 //function : NewEmpty
42 //purpose  :
43 //=======================================================================
44
45 Handle(TDF_Attribute) BinMDataStd_AsciiStringDriver::NewEmpty() const
46 {
47   return new TDataStd_AsciiString;
48 }
49
50 //=======================================================================
51 //function : Paste
52 //purpose  : persistent -> transient (retrieve)
53 //=======================================================================
54
55 Standard_Boolean BinMDataStd_AsciiStringDriver::Paste
56                          (const BinObjMgt_Persistent&  Source,
57                           const Handle(TDF_Attribute)& Target,
58                           BinObjMgt_RRelocationTable&  /*RelocTable*/) const
59 {
60   Handle(TDataStd_AsciiString) aStrAtt = Handle(TDataStd_AsciiString)::DownCast(Target);
61   TCollection_AsciiString aString;
62   Standard_Boolean ok = Source >> aString;
63   if (ok)
64     aStrAtt->Set( aString );
65   if(BinMDataStd::DocumentVersion() > 8) { // process user defined guid
66         const Standard_Integer& aPos = Source.Position();
67         Standard_GUID aGuid;
68         ok = Source >> aGuid;   
69         if (!ok) {
70           Source.SetPosition(aPos);       
71           aStrAtt->SetID(TDataStd_AsciiString::GetID());
72           ok = Standard_True;
73         } else {          
74           aStrAtt->SetID(aGuid);
75         }
76   } else
77         aStrAtt->SetID(TDataStd_AsciiString::GetID());
78   return ok;
79 }
80
81 //=======================================================================
82 //function : Paste
83 //purpose  : transient -> persistent (store)
84 //=======================================================================
85
86 void BinMDataStd_AsciiStringDriver::Paste
87                          (const Handle(TDF_Attribute)& Source,
88                           BinObjMgt_Persistent&        Target,
89                           BinObjMgt_SRelocationTable&  /*RelocTable*/) const
90 {
91   Handle(TDataStd_AsciiString) anAtt = Handle(TDataStd_AsciiString)::DownCast(Source);
92   Target << anAtt->Get();
93  // process user defined guid
94   if(anAtt->ID() != TDataStd_AsciiString::GetID()) 
95         Target << anAtt->ID();
96
97 }