0026937: Eliminate NO_CXX_EXCEPTION macro support
[occt.git] / src / CDF / CDF_Application.hxx
1 // Created on: 1997-08-07
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 #ifndef _CDF_Application_HeaderFile
18 #define _CDF_Application_HeaderFile
19
20 #include <TCollection_ExtendedString.hxx>
21 #include <PCDM_ReaderStatus.hxx>
22 #include <CDM_Application.hxx>
23 #include <CDM_CanCloseStatus.hxx>
24 #include <TColStd_SequenceOfExtendedString.hxx>
25 #include <CDF_TypeOfActivation.hxx>
26 #include <Standard_IStream.hxx>
27 #include <NCollection_IndexedDataMap.hxx>
28
29 class Standard_NoSuchObject;
30 class CDF_Session;
31 class Standard_GUID;
32 class CDM_Document;
33 class TCollection_ExtendedString;
34 class PCDM_Reader;
35 class CDM_MetaData;
36 class PCDM_RetrievalDriver;
37 class PCDM_StorageDriver;
38
39 class CDF_Application;
40 DEFINE_STANDARD_HANDLE(CDF_Application, CDM_Application)
41
42
43 class CDF_Application : public CDM_Application
44 {
45
46 public:
47
48   
49   //! plugs an application.
50   //!
51   //! Open is used
52   //! - for opening a Document that has been created in an application
53   //! - for opening a Document from the database
54   //! - for opening a Document from a file.
55   //! The Open methods always add the document in the session directory and
56   //! calls the virtual Activate method. The document is considered to be
57   //! opened until Close is used. To be storable, a document must be
58   //! opened by an application since the application resources are
59   //! needed to store it.
60   Standard_EXPORT static Handle(CDF_Application) Load (const Standard_GUID& aGUID);
61   
62   //! puts the document in the current session directory
63   //! and calls the virtual method Activate on it.
64   Standard_EXPORT void Open (const Handle(CDM_Document)& aDocument);
65   
66   Standard_EXPORT CDM_CanCloseStatus CanClose (const Handle(CDM_Document)& aDocument);
67   
68   //! removes the document of the current session directory
69   //! and closes the document;
70   Standard_EXPORT void Close (const Handle(CDM_Document)& aDocument);
71   
72   //! This method retrieves a document from the database.
73   //! If the Document references other documents which have
74   //! been updated, the latest version of these documents will
75   //! be used if {UseStorageConfiguration} is Standard_True.
76   //! The content of {aFolder}, {aName} and {aVersion} depends on
77   //! the Database Manager system. If the DBMS is only based on
78   //! the OS, {aFolder} is a directory and {aName} is the name of a
79   //! file. In this case the use of the syntax with {aVersion}
80   //! has no sense. For example:
81   //!
82   //! Handle(CDM_Document) theDocument=myApplication->Retrieve("/home/cascade","box.dsg");
83   //! If the DBMS is EUCLID/Design Manager, {aFolder}, {aName}
84   //! have the form they have in EUCLID/Design Manager. For example:
85   //!
86   //! Handle(CDM_Document) theDocument=myApplication->Retrieve("|user|cascade","box");
87   //!
88   //! Since  the version is not specified in  this syntax, the  latest wil be used.
89   //! A link is kept with the database through an instance of CDM_MetaData
90   Standard_EXPORT Handle(CDM_Document) Retrieve (const TCollection_ExtendedString& aFolder, const TCollection_ExtendedString& aName, const Standard_Boolean UseStorageConfiguration = Standard_True);
91   
92   //! This method retrieves  a  document from the database.
93   //! If the  Document references other documents which have
94   //! been  updated, the  latest version of  these documents
95   //! will    be   used  if   {UseStorageConfiguration}  is
96   //! Standard_True.  --  If the DBMS is  only  based on the
97   //! OS, this syntax  should not be used.
98   //!
99   //! If the DBMS is EUCLID/Design Manager, {aFolder}, {aName}
100   //! and  {aVersion} have the form they have in
101   //! EUCLID/Design Manager. For example:
102   //!
103   //! Handle(CDM_Document) theDocument=myApplication->Retrieve("|user|cascade","box","2");
104   //! A link is kept with the database through an instance
105   //! of CDM_MetaData
106   Standard_EXPORT Handle(CDM_Document) Retrieve (const TCollection_ExtendedString& aFolder, const TCollection_ExtendedString& aName, const TCollection_ExtendedString& aVersion, const Standard_Boolean UseStorageConfiguration = Standard_True);
107   
108   Standard_EXPORT PCDM_ReaderStatus CanRetrieve (const TCollection_ExtendedString& aFolder, const TCollection_ExtendedString& aName);
109   
110   Standard_EXPORT PCDM_ReaderStatus CanRetrieve (const TCollection_ExtendedString& aFolder, const TCollection_ExtendedString& aName, const TCollection_ExtendedString& aVersion);
111   
112   //! Checks  status  after  Retrieve
113   PCDM_ReaderStatus GetRetrieveStatus() const { return myRetrievableStatus; }
114   
115   //! Reads aDoc from standard SEEKABLE stream theIStream,
116   //! the stream should support SEEK fuctionality
117   Standard_EXPORT Handle(CDM_Document) Read (Standard_IStream& theIStream);
118  
119   //! Returns instance of read driver for specified format.
120   //!
121   //! Default implementation uses plugin mechanism to load reader dynamically.
122   //! For this to work, application resources should define GUID of
123   //! the plugin as value of [Format].RetrievalPlugin, and "Plugin"
124   //! resource should define name of plugin library to be loaded as
125   //! value of [GUID].Location. Plugin library should provide
126   //! method PLUGINFACTORY returning instance of the reader for the
127   //! same GUID (see Plugin_Macro.hxx).
128   //!
129   //! In case if reader is not available, will raise Standard_NoSuchObject
130   //! or other exception if raised by plugin loader.
131   Standard_EXPORT virtual Handle(PCDM_Reader) ReaderFromFormat (const TCollection_ExtendedString& aFormat);
132   
133   //! Returns instance of storage driver for specified format.
134   //!
135   //! Default implementation uses plugin mechanism to load driver dynamically.
136   //! For this to work, application resources should define GUID of
137   //! the plugin as value of [Format].StoragePlugin, and "Plugin"
138   //! resource should define name of plugin library to be loaded as
139   //! value of [GUID].Location. Plugin library should provide
140   //! method PLUGINFACTORY returning instance of the reader for the
141   //! same GUID (see Plugin_Macro.hxx).
142   //!
143   //! In case if driver is not available, will raise Standard_NoSuchObject
144   //! or other exception if raised by plugin loader.
145   Standard_EXPORT virtual Handle(PCDM_StorageDriver) WriterFromFormat (const TCollection_ExtendedString& aFormat);
146   
147   //! try to  retrieve a Format  directly in the  file or in
148   //! application   resource  by using   extension. returns
149   //! True if found;
150   Standard_EXPORT Standard_Boolean Format (const TCollection_ExtendedString& aFileName, TCollection_ExtendedString& theFormat);
151   
152   Standard_EXPORT Standard_ExtString DefaultFolder();
153   
154   Standard_EXPORT Standard_Boolean SetDefaultFolder (const Standard_ExtString aFolder);
155   
156 friend class CDF_Session;
157
158
159   DEFINE_STANDARD_RTTIEXT(CDF_Application,CDM_Application)
160
161 protected:
162
163   
164   Standard_EXPORT CDF_Application();
165
166   PCDM_ReaderStatus myRetrievableStatus;
167   NCollection_IndexedDataMap<TCollection_ExtendedString, Handle(PCDM_RetrievalDriver)> myReaders;
168   NCollection_IndexedDataMap<TCollection_ExtendedString, Handle(PCDM_StorageDriver)> myWriters;
169
170 private:
171
172   
173   //! Informs the  application that aDocument has  been
174   //! activated. A document is activated when it is created or
175   //! retrieved.
176   //! aTypeOfActivation will be:
177   //! - CDF_TOA_New if the document is a new one
178   //! (even empty or retrieved from the database for
179   //! the first time).
180   //! - CDF_TOA_Unchanged if the document was already
181   //! retrieved but had no changes since the previous retrieval.
182   //! - CDF_TOA_Modified if the document was already
183   //! retrieved and modified since the previous retrieval.
184   //! You do not need to call <Activate>, but you should  redefine
185   //! this method to implement application specific behavior.
186   Standard_EXPORT virtual void Activate (const Handle(CDM_Document)& aDocument, const CDF_TypeOfActivation aTypeOfActivation);
187   
188   Standard_EXPORT Handle(CDM_Document) Retrieve (const Handle(CDM_MetaData)& aMetaData, const Standard_Boolean UseStorageConfiguration) Standard_OVERRIDE;
189   
190   Standard_EXPORT Handle(CDM_Document) Retrieve (const Handle(CDM_MetaData)& aMetaData, const Standard_Boolean UseStorageConfiguration, const Standard_Boolean IsComponent);
191   
192   Standard_EXPORT Standard_Integer DocumentVersion (const Handle(CDM_MetaData)& theMetaData) Standard_OVERRIDE;
193   
194   Standard_EXPORT CDF_TypeOfActivation TypeOfActivation (const Handle(CDM_MetaData)& aMetaData);
195   
196   Standard_EXPORT PCDM_ReaderStatus CanRetrieve (const Handle(CDM_MetaData)& aMetaData);
197
198 private:
199   TCollection_ExtendedString myDefaultFolder;
200 };
201
202 #endif // _CDF_Application_HeaderFile