0026936: Drawbacks of inlining in new type system in OCCT 7.0 -- automatic
[occt.git] / src / BinTObjDrivers / BinTObjDrivers_ObjectDriver.cxx
CommitLineData
b311480e 1// Created on: 2004-11-24
2// Created by: Edward AGAPOV
973c2be1 3// Copyright (c) 2004-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.
b311480e 15
7fd59977 16// The original implementation Copyright: (C) RINA S.p.A
17
18
19#include <CDM_MessageDriver.hxx>
20#include <BinObjMgt_Persistent.hxx>
21#include <TDF_Tool.hxx>
22
23#include <BinTObjDrivers_ObjectDriver.hxx>
24#include <TObj_Assistant.hxx>
25#include <TObj_TObject.hxx>
26#include <TObj_Persistence.hxx>
27
ec357c5c 28
29
7fd59977 30
92efcf78 31IMPLEMENT_STANDARD_RTTIEXT(BinTObjDrivers_ObjectDriver,BinMDF_ADriver)
32
7fd59977 33//=======================================================================
34//function : BinTObjDrivers_ObjectDriver
35//purpose : constructor
36//=======================================================================
37
38BinTObjDrivers_ObjectDriver::BinTObjDrivers_ObjectDriver
39 (const Handle(CDM_MessageDriver)& theMessageDriver)
40: BinMDF_ADriver( theMessageDriver, NULL)
41{
42}
43
44//=======================================================================
45//function : NewEmpty
46//purpose : Creates a new attribute
47//=======================================================================
48
49Handle(TDF_Attribute) BinTObjDrivers_ObjectDriver::NewEmpty() const
50{
51 return new TObj_TObject;
52}
53
54//=======================================================================
55//function : Paste
56//purpose : Translate the contents of <theSource> and put it
57// into <theTarget>.
58//=======================================================================
59
60Standard_Boolean BinTObjDrivers_ObjectDriver::Paste
61 (const BinObjMgt_Persistent& theSource,
62 const Handle(TDF_Attribute)& theTarget,
63 BinObjMgt_RRelocationTable&) const
64{
65 Standard_Integer aSavedPos = theSource.Position();
66
67 // first try to get the type as an integer ID
68 Standard_Integer anID;
69 if (! (theSource >> anID)) return Standard_False;
70 Handle(TObj_Object) anObject;
71 if ( (unsigned)anID > 0xffff)
72 {
73 // if we are here it means that the type was stored as an ascii string,
74 // so rewind theSource and reget
75 theSource.SetPosition(aSavedPos);
76 TCollection_AsciiString aName;
77 if (! (theSource >> aName)) return Standard_False;
78 anObject =
79 TObj_Persistence::CreateNewObject(aName.ToCString(),theTarget->Label());
80 if (anObject.IsNull())
81 {
82 TCollection_AsciiString anEntry;
83 TDF_Tool::Entry (theTarget->Label(), anEntry);
84 WriteMessage (TCollection_ExtendedString
85 ("TObj_TObject retrieval: wrong object type name ") +
86 aName + ", entry " + anEntry);
87 TObj_Assistant::BindType(0);
88 return Standard_False;
89 }
90 // register the type
91 TObj_Assistant::BindType(anObject->DynamicType());
92 }
93 else
94 {
95 // use anID to get the type from earlier registered ones
96 Handle(Standard_Type) aType = TObj_Assistant::FindType(anID);
97 if(!aType.IsNull())
98 anObject =
99 TObj_Persistence::CreateNewObject(aType->Name(), theTarget->Label());
100 else
101 {
102 return Standard_False;
103 }
104 }
105 Handle(TObj_TObject)::DownCast (theTarget) ->Set( anObject );
106 return Standard_True;
107}
108
109//=======================================================================
110//function : Paste
111//purpose : Translate the contents of <theSource> and put it
112// into <theTarget>.
113// anObject is stored as a Name of class derived from TObj_Object
114//=======================================================================
115
116void BinTObjDrivers_ObjectDriver::Paste
117 (const Handle(TDF_Attribute)& theSource,
118 BinObjMgt_Persistent& theTarget,
119 BinObjMgt_SRelocationTable&) const
120{
121 Handle(TObj_TObject) aTObj =
122 Handle(TObj_TObject)::DownCast( theSource );
123 Handle(TObj_Object) anIObject = aTObj->Get();
124 if (anIObject.IsNull()) return;
125
126 Handle(Standard_Type) aType = anIObject->DynamicType();
127
128 Standard_Integer anID = TObj_Assistant::FindTypeIndex(anIObject->DynamicType());
129
130 if(anID == 0)
131 {
132 // we first meet this type;
133 // register a type and store a type name as a string
134 TObj_Assistant::BindType(aType);
135 TCollection_AsciiString aName = aType->Name();
136 theTarget << aName;
137 }
138 else
139 {
140 // store the integer type ID
141 theTarget << anID;
142 }
143}