Warnings on vc14 were eliminated
[occt.git] / src / CDF / CDF_Session.cxx
1 // Created on: 1997-08-08
2 // Created by: Jean-Louis Frenkel
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <CDF_Application.hxx>
19 #include <CDF_Directory.hxx>
20 #include <CDF_FWOSDriver.hxx>
21 #include <CDF_MetaDataDriver.hxx>
22 #include <CDF_MetaDataDriverFactory.hxx>
23 #include <CDF_Session.hxx>
24 #include <PCDM.hxx>
25 #include <PCDM_Reader.hxx>
26 #include <Plugin.hxx>
27 #include <Standard_ErrorHandler.hxx>
28 #include <Standard_Failure.hxx>
29 #include <Standard_GUID.hxx>
30 #include <Standard_MultiplyDefined.hxx>
31 #include <Standard_NoSuchObject.hxx>
32 #include <Standard_Type.hxx>
33 #include <TCollection_ExtendedString.hxx>
34
35 IMPLEMENT_STANDARD_RTTIEXT(CDF_Session,Standard_Transient)
36
37 static Handle(CDF_Session) CS;
38
39 //=======================================================================
40 //function : 
41 //purpose  : 
42 //=======================================================================
43 CDF_Session::CDF_Session () : myHasCurrentApplication(Standard_False)
44 {  
45   Standard_MultiplyDefined_Raise_if(!CS.IsNull()," a session already exists");
46   myDirectory = new CDF_Directory();
47   CS = this;
48 }
49
50 //=======================================================================
51 //function : Exists
52 //purpose  : 
53 //=======================================================================
54 Standard_Boolean CDF_Session::Exists() {
55   return !CS.IsNull();
56 }
57
58 //=======================================================================
59 //function : Directory
60 //purpose  : 
61 //=======================================================================
62 Handle(CDF_Directory) CDF_Session::Directory() const {
63   
64   return CS->myDirectory;
65 }
66
67 //=======================================================================
68 //function : CurrentSession
69 //purpose  : 
70 //=======================================================================
71 Handle(CDF_Session) CDF_Session::CurrentSession() {
72   Standard_NoSuchObject_Raise_if(CS.IsNull(), "no session has been created");
73   return CS;
74 }
75
76 //=======================================================================
77 //function : HasCurrentApplication
78 //purpose  : 
79 //=======================================================================
80 Standard_Boolean CDF_Session::HasCurrentApplication() const {
81   return myHasCurrentApplication;
82 }
83
84 //=======================================================================
85 //function : CurrentApplication
86 //purpose  : 
87 //=======================================================================
88 Handle(CDF_Application) CDF_Session::CurrentApplication() const {
89   Standard_NoSuchObject_Raise_if(!myHasCurrentApplication,"there is no current application in the session");
90   return myCurrentApplication;
91 }
92
93 //=======================================================================
94 //function : SetCurrentApplication
95 //purpose  : 
96 //=======================================================================
97 void CDF_Session::SetCurrentApplication(const Handle(CDF_Application)& anApplication) {
98   myCurrentApplication  = anApplication;
99   myHasCurrentApplication = Standard_True;
100 }
101
102 //=======================================================================
103 //function : UnsetCurrentApplication
104 //purpose  : 
105 //=======================================================================
106 void CDF_Session::UnsetCurrentApplication() {
107   myHasCurrentApplication = Standard_False;
108   myCurrentApplication.Nullify();
109 }
110
111 //=======================================================================
112 //function : MetaDataDriver
113 //purpose  : 
114 //=======================================================================
115 Handle(CDF_MetaDataDriver) CDF_Session::MetaDataDriver() const {
116   Standard_NoSuchObject_Raise_if(myMetaDataDriver.IsNull(),"no metadatadriver has been provided; this session is not able to store or retrieve files.");
117   return myMetaDataDriver;
118 }
119
120 //=======================================================================
121 //function : LoadDriver
122 //purpose  : 
123 //=======================================================================
124 void CDF_Session::LoadDriver() {
125   if (myMetaDataDriver.IsNull()) {
126     // for compatibility with old code, initialize useless driver directly
127     // instead of loading it as plugin
128     Handle(CDF_MetaDataDriverFactory) aFactory;
129     myMetaDataDriver = new CDF_FWOSDriver;
130   }
131 }