]> OCCT Git - occt-copy.git/commitdiff
Implement mechanism to remove static variables related to STEP exchange plugin.
authorazv <azv@opencascade.com>
Sat, 27 Mar 2021 11:59:28 +0000 (14:59 +0300)
committerazv <azv@opencascade.com>
Sat, 27 Mar 2021 12:02:37 +0000 (15:02 +0300)
19 files changed:
src/IGESData/IGESData_GlobalNodeOfSpecificLib.hxx
src/IGESData/IGESData_GlobalNodeOfWriterLib.hxx
src/IGESData/IGESData_SpecificLib.hxx
src/IGESData/IGESData_WriterLib.hxx
src/Interface/Interface_GeneralLib.hxx
src/Interface/Interface_GlobalNodeOfGeneralLib.hxx
src/Interface/Interface_GlobalNodeOfReaderLib.hxx
src/Interface/Interface_ReaderLib.hxx
src/LibCtl/LibCtl_GlobalNode.gxx
src/LibCtl/LibCtl_Library.gxx
src/RWStepAP214/RWStepAP214.cxx
src/STEPCAFControl/STEPCAFControl_Controller.cxx
src/STEPCAFControl/STEPCAFControl_Controller.hxx
src/STEPCAFControl/STEPCAFControl_Reader.cxx
src/STEPCAFControl/STEPCAFControl_Reader.hxx
src/StepData/StepData_GlobalNodeOfWriterLib.hxx
src/StepData/StepData_WriterLib.hxx
src/XSControl/XSControl_Controller.cxx
src/XSControl/XSControl_Controller.hxx

index e9db7ad2afd0541f377c76937370412c91b4999c..bf91d5199820cfe18c72f5c4aa3ccfbf6b8a3102 100644 (file)
@@ -46,7 +46,10 @@ public:
   //! match) and Same State (that is, IsEqual is not required)
   //! Once added, stores its attached Protocol in correspondance
   Standard_EXPORT void Add (const Handle(IGESData_SpecificModule)& amodule, const Handle(IGESData_Protocol)& aprotocol);
-  
+
+  //! Removes a Module from the list
+  Standard_EXPORT void Remove(const Handle(IGESData_SpecificModule)& amodule);
+
   //! Returns the Module stored in a given GlobalNode
   Standard_EXPORT const Handle(IGESData_SpecificModule)& Module() const;
   
index cea9c9c7f3a264c58e2bc23bd5827fb48d2bb1f4..c8f781f9a60e8d9f020c2a4fe68f68e7a8733090 100644 (file)
@@ -46,7 +46,10 @@ public:
   //! match) and Same State (that is, IsEqual is not required)
   //! Once added, stores its attached Protocol in correspondance
   Standard_EXPORT void Add (const Handle(IGESData_ReadWriteModule)& amodule, const Handle(IGESData_Protocol)& aprotocol);
-  
+
+  //! Removes a Module from the list
+  Standard_EXPORT void Remove(const Handle(IGESData_ReadWriteModule)& amodule);
+
   //! Returns the Module stored in a given GlobalNode
   Standard_EXPORT const Handle(IGESData_ReadWriteModule)& Module() const;
   
index 99454e5adbba1d5b24d08691d76ad1c5d72ad09c..8f9e0e80045c1f5805e4d0085b5a03e9d7959650 100644 (file)
@@ -43,7 +43,10 @@ public:
   //! Adds a couple (Module-Protocol) into the global definition set
   //! for this class of Library.
   Standard_EXPORT static void SetGlobal (const Handle(IGESData_SpecificModule)& amodule, const Handle(IGESData_Protocol)& aprotocol);
-  
+
+  //! Releases a module from the global definition set.
+  Standard_EXPORT static void ReleaseGlobal(const Handle(IGESData_SpecificModule)& amodule);
+
   //! Creates a Library which complies with a Protocol, that is :
   //! Same class (criterium IsInstance)
   //! This creation gets the Modules from the global set, those
index d4f394f611714525b2991af1f7e5581f86c6275c..fc37284eb77c4d3ecc4f73c24b97cad422d05871 100644 (file)
@@ -43,7 +43,10 @@ public:
   //! Adds a couple (Module-Protocol) into the global definition set
   //! for this class of Library.
   Standard_EXPORT static void SetGlobal (const Handle(IGESData_ReadWriteModule)& amodule, const Handle(IGESData_Protocol)& aprotocol);
-  
+
+  //! Releases a module from the global definition set.
+  Standard_EXPORT static void ReleaseGlobal(const Handle(IGESData_ReadWriteModule)& amodule);
+
   //! Creates a Library which complies with a Protocol, that is :
   //! Same class (criterium IsInstance)
   //! This creation gets the Modules from the global set, those
index c7c0bf5112fb028d046a1f4eed147383173bd4e0..8ddd9b064659dd1fe7a04ac5ae785df845efc53e 100644 (file)
@@ -42,7 +42,10 @@ public:
   //! Adds a couple (Module-Protocol) into the global definition set
   //! for this class of Library.
   Standard_EXPORT static void SetGlobal (const Handle(Interface_GeneralModule)& amodule, const Handle(Interface_Protocol)& aprotocol);
-  
+
+  //! Releases a module from the global definition set.
+  Standard_EXPORT static void ReleaseGlobal(const Handle(Interface_GeneralModule)& amodule);
+
   //! Creates a Library which complies with a Protocol, that is :
   //! Same class (criterium IsInstance)
   //! This creation gets the Modules from the global set, those
index 713425ef7cce663e1f8dde9d0c24b88ac79a6b7e..f78cae3a04ac4cd26571aa29e1a4d7796dc6f475 100644 (file)
@@ -46,7 +46,10 @@ public:
   //! match) and Same State (that is, IsEqual is not required)
   //! Once added, stores its attached Protocol in correspondance
   Standard_EXPORT void Add (const Handle(Interface_GeneralModule)& amodule, const Handle(Interface_Protocol)& aprotocol);
-  
+
+  //! Removes a Module from the list
+  Standard_EXPORT void Remove(const Handle(Interface_GeneralModule)& amodule);
+
   //! Returns the Module stored in a given GlobalNode
   Standard_EXPORT const Handle(Interface_GeneralModule)& Module() const;
   
index 6d6c9eac51cd7ba39fc100d6f844f1fd9f90dc9d..5b3b3b78f53924a52f85c744e2f7592007f3f1c6 100644 (file)
@@ -46,7 +46,10 @@ public:
   //! match) and Same State (that is, IsEqual is not required)
   //! Once added, stores its attached Protocol in correspondance
   Standard_EXPORT void Add (const Handle(Interface_ReaderModule)& amodule, const Handle(Interface_Protocol)& aprotocol);
-  
+
+  //! Removes a Module from the list
+  Standard_EXPORT void Remove(const Handle(Interface_ReaderModule)& amodule);
+
   //! Returns the Module stored in a given GlobalNode
   Standard_EXPORT const Handle(Interface_ReaderModule)& Module() const;
   
index 7d982d8e0bff0aa4d6bae1fb105f68e61393ce9d..85eef38955a0fae5436b1fb30049e27291c127a4 100644 (file)
@@ -42,7 +42,10 @@ public:
   //! Adds a couple (Module-Protocol) into the global definition set
   //! for this class of Library.
   Standard_EXPORT static void SetGlobal (const Handle(Interface_ReaderModule)& amodule, const Handle(Interface_Protocol)& aprotocol);
-  
+
+  //! Releases a module from the global definition set.
+  Standard_EXPORT static void ReleaseGlobal(const Handle(Interface_ReaderModule)& amodule);
+
   //! Creates a Library which complies with a Protocol, that is :
   //! Same class (criterium IsInstance)
   //! This creation gets the Modules from the global set, those
index a989a1dad2fe99cc4364559ef841346f52fc6fac..5c089d625a7ebde38a28ee21662afb66e1b1d48e 100644 (file)
@@ -38,6 +38,26 @@ LibCtl_GlobalNode::LibCtl_GlobalNode ()    {  }
   else thenext->Add (amodule,aprotocol);
 }
 
+void LibCtl_GlobalNode::Remove(const Handle(TheModule)& amodule)
+{
+  if (themod == amodule)
+  {
+    if (thenext.IsNull())
+    {
+      themod = Handle(TheModule)();
+      theprot = Handle(TheProtocol)();
+    }
+    else
+    {
+      themod = thenext->themod;
+      theprot = thenext->theprot;
+      thenext = thenext->thenext;
+    }
+  }
+  else if (!thenext.IsNull())
+    thenext->Remove(amodule);
+}
+
     const Handle(TheModule)& LibCtl_GlobalNode::Module () const
       {  return themod;  }
 
index d7fcef9f2bc00ed6a2729ecebc144ff1f8489289..d6dca27d95eb28c2b87e9b27b300ac78fda6e327 100644 (file)
@@ -36,6 +36,12 @@ static Handle(LibCtl_Node) thelast;
   theglobal->Add(amodule,aprotocol);
 }
 
+void LibCtl_Library::ReleaseGlobal(const Handle(TheModule)& amodule)
+{
+  if (!theglobal.IsNull())
+    theglobal->Remove(amodule);
+}
+
 // Constructeur d apres Protocole
     LibCtl_Library::LibCtl_Library (const Handle(TheProtocol)& aprotocol)
 {
index 66933632837cb6536d1e4bb4c48d9dd07361f4b6..ca8a5b73a8506a97eb0333724a24318685f7cccb 100644 (file)
 #include <StepAP214_Protocol.hxx>
 #include <StepData_WriterLib.hxx>
 
-static int THE_RWStepAP214_init = 0;
+DEFINE_STANDARD_HANDLE(RWStepAP214_Mgr, Standard_Transient)
+
+class RWStepAP214_Mgr : public Standard_Transient
+{
+public:
+  RWStepAP214_Mgr()
+  {
+    myProtocol = StepAP214::Protocol();
+    myGeneralModule = new RWStepAP214_GeneralModule;
+    myRWModule = new RWStepAP214_ReadWriteModule;
+    Interface_GeneralLib::SetGlobal(myGeneralModule, myProtocol);
+    Interface_ReaderLib::SetGlobal(myRWModule, myProtocol);
+    StepData_WriterLib::SetGlobal(myRWModule, myProtocol);
+  }
+
+  virtual ~RWStepAP214_Mgr()
+  {
+    Interface_GeneralLib::ReleaseGlobal(myGeneralModule);
+    Interface_ReaderLib::ReleaseGlobal(myRWModule);
+    StepData_WriterLib::ReleaseGlobal(myRWModule);
+  }
+
+  DEFINE_STANDARD_RTTI_INLINE(RWStepAP214_Mgr, Standard_Transient)
+
+private:
+  Handle(StepAP214_Protocol) myProtocol;
+  Handle(RWStepAP214_ReadWriteModule) myRWModule;
+  Handle(RWStepAP214_GeneralModule) myGeneralModule;
+};
+
+static Handle(RWStepAP214_Mgr) THE_MGR;
 
 void RWStepAP214::Init()
 {
-  if (THE_RWStepAP214_init)
+  if (THE_MGR.IsNull())
   {
-    return;
+    RWHeaderSection::Init();
+    THE_MGR = new RWStepAP214_Mgr;
   }
-  THE_RWStepAP214_init = 1;
-  RWHeaderSection::Init();
-  Handle(StepAP214_Protocol) proto = StepAP214::Protocol();
-  Interface_GeneralLib::SetGlobal (new RWStepAP214_GeneralModule,proto);
-  Interface_ReaderLib::SetGlobal  (new RWStepAP214_ReadWriteModule,proto);
-  StepData_WriterLib::SetGlobal   (new RWStepAP214_ReadWriteModule,proto);
 }
index 5e43b80697796d15b50d525964aef7de1d10423a..8ca3253c92c4c845ae6b2fae4f979e9733ba2097 100644 (file)
@@ -83,3 +83,10 @@ Standard_Boolean STEPCAFControl_Controller::Init ()
 
   return Standard_True;
 }
+
+Standard_Boolean STEPCAFControl_Controller::Release()
+{
+  Handle(STEPCAFControl_Controller) STEPCTL = new STEPCAFControl_Controller;
+  STEPCTL->AutoRemove();
+  return Standard_True;
+}
index bf5e782e6ac8da9285f3b05a26d77020620ae717..f9e6ec0d86340d5715859f45e103fbfdac1629d3 100644 (file)
@@ -44,6 +44,7 @@ public:
   //! Returns True when done, False if could not be done
   Standard_EXPORT static Standard_Boolean Init();
 
+  Standard_EXPORT static Standard_Boolean Release();
 
 
 
index 2573a8dc3106b1f562312c0e49ef58ba3ebcb61a..4b5e53c7899ecee88d4a272e8b60b6f7f075337d 100644 (file)
@@ -356,6 +356,10 @@ STEPCAFControl_Reader::STEPCAFControl_Reader(const Handle(XSControl_WorkSession)
   Init(WS, scratch);
 }
 
+STEPCAFControl_Reader::~STEPCAFControl_Reader()
+{
+  STEPCAFControl_Controller::Release();
+}
 
 //=======================================================================
 //function : Init
index b37c05d7c66df52dfc43e8a80bbdb10b1094cbb9..3ae2f6b0d913785614c7c11c97e7340350e0e786 100644 (file)
@@ -70,7 +70,9 @@ public:
   //! Creates a reader tool and attaches it to an already existing Session
   //! Clears the session if it was not yet set for STEP
   Standard_EXPORT STEPCAFControl_Reader(const Handle(XSControl_WorkSession)& WS, const Standard_Boolean scratch = Standard_True);
-  
+
+  Standard_EXPORT virtual ~STEPCAFControl_Reader();
+
   //! Clears the internal data structures and attaches to a new session
   //! Clears the session if it was not yet set for STEP
   Standard_EXPORT void Init (const Handle(XSControl_WorkSession)& WS, const Standard_Boolean scratch = Standard_True);
index ee99849f0f19ff5b11e55f54b32e3c83327ec9cb..08aebf8f2e1ed6e16e3c1f789339ac0a67c7aefc 100644 (file)
@@ -46,7 +46,10 @@ public:
   //! match) and Same State (that is, IsEqual is not required)
   //! Once added, stores its attached Protocol in correspondance
   Standard_EXPORT void Add (const Handle(StepData_ReadWriteModule)& amodule, const Handle(StepData_Protocol)& aprotocol);
-  
+
+  //! Removes a Module from the list
+  Standard_EXPORT void Remove(const Handle(StepData_ReadWriteModule)& amodule);
+
   //! Returns the Module stored in a given GlobalNode
   Standard_EXPORT const Handle(StepData_ReadWriteModule)& Module() const;
   
index 6f0501e9ae788b5ed75a75ec2311bcb2663f9e03..7682879f80e71343978885d8193f7a0ee0b57401 100644 (file)
@@ -42,7 +42,10 @@ public:
   //! Adds a couple (Module-Protocol) into the global definition set
   //! for this class of Library.
   Standard_EXPORT static void SetGlobal (const Handle(StepData_ReadWriteModule)& amodule, const Handle(StepData_Protocol)& aprotocol);
-  
+
+  //! Releases a module from the global definition set.
+  Standard_EXPORT static void ReleaseGlobal(const Handle(StepData_ReadWriteModule)& amodule);
+
   //! Creates a Library which complies with a Protocol, that is :
   //! Same class (criterium IsInstance)
   //! This creation gets the Modules from the global set, those
index e1dc727ba10ffbca919e48c8f07176bdf6cc91e7..1c582740d566abd259082eb82dd905564a59bc8c 100644 (file)
@@ -131,6 +131,13 @@ void XSControl_Controller::Record (const Standard_CString theName) const
   listad.Bind(theName, this);
 }
 
+void XSControl_Controller::Remove(const Standard_CString theName) const
+{
+  if (listad.IsBound(theName)) {
+    listad.UnBind(theName);
+  }
+}
+
 //=======================================================================
 //function : Recorded
 //purpose  : 
index 87b7a4b923140cf1b15d15fa8706a0c59492eaa8..c4bd856963a2844fcbff1c88465f48f79ef1e8f9 100644 (file)
@@ -82,7 +82,14 @@ class XSControl_Controller : public Standard_Transient
   //! Records <me> in a general dictionary under a name
   //! Error if <name> already used for another one
   Standard_EXPORT void Record (const Standard_CString name) const;
-  
+
+  void AutoRemove() const
+  {
+    Remove(Name(Standard_True));
+    Remove(Name(Standard_False));
+  }
+  Standard_EXPORT void Remove(const Standard_CString name) const;
+
   //! Returns the Controller attached to a given name
   //! Returns a Null Handle if <name> is unknown
   Standard_EXPORT static Handle(XSControl_Controller) Recorded (const Standard_CString name);