]> Creatis software - bbtk.git/commitdiff
*** empty log message ***
authorguigues <guigues>
Tue, 9 Jun 2009 08:34:38 +0000 (08:34 +0000)
committerguigues <guigues>
Tue, 9 Jun 2009 08:34:38 +0000 (08:34 +0000)
kernel/src/bbtkPimpl.h [new file with mode: 0644]

diff --git a/kernel/src/bbtkPimpl.h b/kernel/src/bbtkPimpl.h
new file mode 100644 (file)
index 0000000..68c725a
--- /dev/null
@@ -0,0 +1,42 @@
+#ifndef __bbtkPimpl_h_INCLUDED__
+#define __bbtkPimpl_h_INCLUDED__
+
+
+/** \brief Macro defining the members used to hide a class implementation details using the pimpl idom 
+ *    /// See http://c2.com/cgi/wiki?PimplIdiom
+ * NOTE :
+ *  - Defines the struct Pimpl to be implemented in cpp file
+ *  - Declares a private member called p
+ *  - Declares the methods PimplConstruct/PimplCopyConstruct/PimplDestruct
+ */
+#define BBTK_DECLARE_PIMPL(CLASS)                                    \
+  private:                                                           \
+  /* The Pimpl struct forward definition */                          \
+  class Pimpl;                                                       \
+  /* The Pimpl pointer */                                            \
+  Pimpl* p;                                                          \
+  /* Constructs the Pimpl (to be called in all Ctors) */             \
+  void PimplConstruct();                                             \
+  /* Copy constructs the Pimpl (to be called in copy Ctor) */        \
+  void PimplCopyConstruct(const CLASS&);                             \
+  /* Destructs the Pimpl (to be called in Dtor) */                   \
+  void PimplDestruct();
+
+#endif
+
+/** \brief Macro implementing the PimplConstruct/PimplCopyConstruct/PimplDestruct method declared by BBTK_DECLARE_PIMPL: to be put in cpp **/
+#define BBTK_IMPL_PIMPL(CLASS)                                         \
+  void CLASS::PimplConstruct()                                         \
+  {                                                                    \
+    p = new Pimpl;                                                     \
+  }                                                                    \
+  void CLASS::PimplCopyConstruct(const CLASS& o)                       \
+  {                                                                    \
+    p = new Pimpl(*(o.p));                                             \
+  }                                                                    \
+  void CLASS::PimplDestruct()                                          \
+  {                                                                    \
+    delete p;                                                          \
+  }                                                                    
+
+