0027932: Improvement of standard attributes usability.
[occt.git] / src / BinMDataStd / BinMDataStd_AsciiStringDriver.cxx
CommitLineData
b311480e 1// Created on: 2007-08-01
2// Created by: Sergey ZARITCHNY
973c2be1 3// Copyright (c) 2007-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
42cf5bc1 16
17#include <BinMDataStd_AsciiStringDriver.hxx>
7fd59977 18#include <BinMDF_ADriver.hxx>
7fd59977 19#include <BinObjMgt_Persistent.hxx>
20#include <BinObjMgt_RRelocationTable.hxx>
21#include <BinObjMgt_SRelocationTable.hxx>
42cf5bc1 22#include <CDM_MessageDriver.hxx>
23#include <Standard_Type.hxx>
24#include <TDataStd_AsciiString.hxx>
25#include <TDF_Attribute.hxx>
fa53efef 26#include <BinMDataStd.hxx>
42cf5bc1 27
92efcf78 28IMPLEMENT_STANDARD_RTTIEXT(BinMDataStd_AsciiStringDriver,BinMDF_ADriver)
29
7fd59977 30//=======================================================================
31//function : BinMDataStd_AsciiStringDriver
32//purpose :
33//=======================================================================
7fd59977 34BinMDataStd_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
45Handle(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
55Standard_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 );
fa53efef 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());
7fd59977 78 return ok;
79}
80
81//=======================================================================
82//function : Paste
83//purpose : transient -> persistent (store)
84//=======================================================================
85
86void 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();
fa53efef 93 // process user defined guid
94 if(anAtt->ID() != TDataStd_AsciiString::GetID())
95 Target << anAtt->ID();
96
7fd59977 97}