Salome HOME
This commit was generated by cvs2git to create branch 'CCAR_br1'.
[modules/kernel.git] / doc / KernelResources / kernel_resources-3.html
diff --git a/doc/KernelResources/kernel_resources-3.html b/doc/KernelResources/kernel_resources-3.html
new file mode 100644 (file)
index 0000000..64cdedd
--- /dev/null
@@ -0,0 +1,77 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<HTML>
+<HEAD>
+ <META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.9">
+ <TITLE>SALOME Kernel resources for developer: Miscellaneous tools</TITLE>
+ <LINK HREF="kernel_resources-2.html" REL=previous>
+ <LINK HREF="kernel_resources.html#toc3" REL=contents>
+</HEAD>
+<BODY>
+Next
+<A HREF="kernel_resources-2.html">Previous</A>
+<A HREF="kernel_resources.html#toc3">Contents</A>
+<HR>
+<H2><A NAME="s3">3. Miscellaneous tools</A></H2>
+
+<H2><A NAME="ss3.1">3.1 Singleton</A>
+</H2>
+
+<H3>Definition</H3>
+
+<P>A singleton is an application data which is created and deleted
+only once at the end of the application process. The C++ compiler
+allows the user to create a static singleton data before the first
+executable statement. They are deleted after the last statement execution.
+<P>The <CODE>SINGLETON_</CODE> template class deals with dynamic singleton. It
+is useful for functor objects. For example, an object that connects
+the application to a system at creation and disconnects the application
+at deletion.
+<H3>Usage</H3>
+
+<P>To create a single instance a POINT object :
+<P>
+<PRE>
+# include &quot;Utils_SINGLETON.hxx&quot;
+... 
+POINT *ptrPoint=SINGLETON_&lt;POINT&gt;::Instance() ; 
+assert(ptrPoint!=NULL) ;
+</PRE>
+<P>No need to delete ptrPoint. Deletion is achieved automatically
+at exit. If the user tries to create more than one singleton by using
+the class method <CODE>SINGLETON_&lt;TYPE&gt;::Instance()</CODE>, the pointer
+is returned with the same value even if this is done in different
+functions (threads ?).
+<P>
+<PRE>
+POINT *p1=SINGLETON_&lt;POINT&gt;::Instance() ;
+... 
+POINT *p2=SINGLETON_&lt;POINT&gt;::Instance() ; 
+assert(p1==p2)
+</PRE>
+<H3>Design description</H3>
+
+<P>Here are the principles features of the singleton design :
+<P>
+<UL>
+<LI>the user creates an object of class <CODE>TYPE</CODE> by using the class method
+<CODE>SINGLETON_&lt;TYPE&gt;::Instance()</CODE> which returns a pointer to the
+single object ;</LI>
+<LI>to create an object, <CODE>SINGLETON_&lt;TYPE&gt;::Instance()</CODE> uses
+the default constructor of class <CODE>TYPE</CODE> ;</LI>
+<LI>at the same time, this class method creates a destructor object
+which is added to the generic list of destructor objects to be executed
+at the end of the application (<CODE>atexit</CODE>) ;</LI>
+<LI>at the end of the application process all the deletions are performed
+by the <CODE>Nettoyage()</CODE> C function which executes the destruction objects
+end then deletes the destructions objects themselves ;</LI>
+<LI>the <CODE>Nettoyage()</CODE> C  function using atexit() C  function is embedded
+in a static single object <CODE>ATEXIT_()</CODE>.</LI>
+</UL>
+<P>
+<P>
+<HR>
+Next
+<A HREF="kernel_resources-2.html">Previous</A>
+<A HREF="kernel_resources.html#toc3">Contents</A>
+</BODY>
+</HTML>