0026936: Drawbacks of inlining in new type system in OCCT 7.0 -- automatic
[occt.git] / src / CDM / CDM_Reference.cxx
CommitLineData
b311480e 1// Created on: 1997-10-22
2// Created by: Jean-Louis Frenkel
3// Copyright (c) 1997-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
7fd59977 17
42cf5bc1 18#include <CDM_Application.hxx>
19#include <CDM_Document.hxx>
20#include <CDM_MetaData.hxx>
21#include <CDM_Reference.hxx>
22#include <Standard_Type.hxx>
7fd59977 23
92efcf78 24IMPLEMENT_STANDARD_RTTIEXT(CDM_Reference,Standard_Transient)
25
7fd59977 26CDM_Reference::CDM_Reference(const Handle(CDM_Document)& aFromDocument, const Handle(CDM_Document)& aToDocument, const Standard_Integer aReferenceIdentifier, const Standard_Integer aToDocumentVersion):
27myToDocument(aToDocument),
28myFromDocument(aFromDocument.operator->()),
29myReferenceIdentifier(aReferenceIdentifier),
30myDocumentVersion(aToDocumentVersion)
31{}
32
33CDM_Reference::CDM_Reference(const Handle(CDM_Document)& aFromDocument, const Handle(CDM_MetaData)& aToDocument, const Standard_Integer aReferenceIdentifier, const Handle(CDM_Application)& anApplication, const Standard_Integer aToDocumentVersion, const Standard_Boolean UseStorageConfiguration):
34myFromDocument(aFromDocument.operator->()),
35myReferenceIdentifier(aReferenceIdentifier),
36myApplication(anApplication),
37myMetaData(aToDocument),
38myDocumentVersion(aToDocumentVersion),
39myUseStorageConfiguration(UseStorageConfiguration)
40{}
41
42Handle(CDM_Document) CDM_Reference::FromDocument() {
43 return myFromDocument;
44}
45
46Handle(CDM_Document) CDM_Reference::ToDocument() {
47 if(myToDocument.IsNull()) {
48 myToDocument=myApplication->Retrieve(myMetaData,myUseStorageConfiguration);
49 myApplication.Nullify();
50 }
51 return myToDocument;
52}
53Standard_Integer CDM_Reference::ReferenceIdentifier() {
54 return myReferenceIdentifier;
55}
56
57
58void CDM_Reference::Update(const Handle(CDM_MetaData)& aMetaData) {
59 if(myToDocument.IsNull()) {
60 if(myMetaData == aMetaData) {
61 myToDocument=myMetaData->Document();
62 myToDocument->AddFromReference(this);
63 myApplication.Nullify();
64 }
65 }
66}
67
68Standard_Boolean CDM_Reference::IsUpToDate() const {
69 Standard_Integer theActualDocumentVersion;
70 if(myToDocument.IsNull())
71 theActualDocumentVersion=myMetaData->DocumentVersion(myApplication);
72 else
73 theActualDocumentVersion=myToDocument->Modifications();
74
75 return myDocumentVersion==theActualDocumentVersion;
76}
77void CDM_Reference::SetIsUpToDate() {
78
79 Standard_Integer theActualDocumentVersion;
80 if(myToDocument.IsNull())
81 theActualDocumentVersion=myMetaData->DocumentVersion(myApplication);
82 else
83 theActualDocumentVersion=myToDocument->Modifications();
84
85 if(theActualDocumentVersion != -1) myDocumentVersion=theActualDocumentVersion;
86}
87void CDM_Reference::UnsetToDocument(const Handle(CDM_MetaData)& aMetaData, const Handle(CDM_Application)& anApplication) {
88 myToDocument.Nullify();
89 myApplication=anApplication;
90 myMetaData=aMetaData;
91}
92
93Standard_Integer CDM_Reference::DocumentVersion() const {
94 return myDocumentVersion;
95}
96Standard_Boolean CDM_Reference::IsOpened() const {
97 if(myToDocument.IsNull()) return Standard_False;
98 return myToDocument->IsOpened();
99}
100Standard_Boolean CDM_Reference::IsReadOnly() const {
101 if(myToDocument.IsNull()) return myMetaData->IsReadOnly();
102 return myToDocument->IsReadOnly();
103}
104Handle(CDM_Document) CDM_Reference::Document() const {
105 return myToDocument;
106}
107Handle(CDM_MetaData) CDM_Reference::MetaData() const {
108 return myMetaData;
109}
110Handle(CDM_Application) CDM_Reference::Application() const {
111 return myApplication;
112}
113
114Standard_Boolean CDM_Reference::UseStorageConfiguration() const {
115 return myUseStorageConfiguration;
116}
117Standard_Boolean CDM_Reference::IsInSession() const {
118 return !myToDocument.IsNull();
119}
120Standard_Boolean CDM_Reference::IsStored() const {
121 return !myMetaData.IsNull();
122}