]> Creatis software - bbtk.git/blob - kernel/src/bbtkPimpl.h
68c725a5b47709556d1b0603e457dce89913709f
[bbtk.git] / kernel / src / bbtkPimpl.h
1 #ifndef __bbtkPimpl_h_INCLUDED__
2 #define __bbtkPimpl_h_INCLUDED__
3
4
5 /** \brief Macro defining the members used to hide a class implementation details using the pimpl idom  
6  *    /// See http://c2.com/cgi/wiki?PimplIdiom
7  * NOTE :
8  *  - Defines the struct Pimpl to be implemented in cpp file
9  *  - Declares a private member called p
10  *  - Declares the methods PimplConstruct/PimplCopyConstruct/PimplDestruct
11  */
12 #define BBTK_DECLARE_PIMPL(CLASS)                                     \
13   private:                                                            \
14   /* The Pimpl struct forward definition */                           \
15   class Pimpl;                                                        \
16   /* The Pimpl pointer */                                             \
17   Pimpl* p;                                                           \
18   /* Constructs the Pimpl (to be called in all Ctors) */              \
19   void PimplConstruct();                                              \
20   /* Copy constructs the Pimpl (to be called in copy Ctor) */         \
21   void PimplCopyConstruct(const CLASS&);                              \
22   /* Destructs the Pimpl (to be called in Dtor) */                    \
23   void PimplDestruct();
24
25 #endif
26
27 /** \brief Macro implementing the PimplConstruct/PimplCopyConstruct/PimplDestruct method declared by BBTK_DECLARE_PIMPL: to be put in cpp **/
28 #define BBTK_IMPL_PIMPL(CLASS)                                          \
29   void CLASS::PimplConstruct()                                          \
30   {                                                                     \
31     p = new Pimpl;                                                      \
32   }                                                                     \
33   void CLASS::PimplCopyConstruct(const CLASS& o)                        \
34   {                                                                     \
35     p = new Pimpl(*(o.p));                                              \
36   }                                                                     \
37   void CLASS::PimplDestruct()                                           \
38   {                                                                     \
39     delete p;                                                           \
40   }                                                                     
41
42