IMP  2.1.0
The Integrative Modeling Platform
base/ref_counted_macros.h
Go to the documentation of this file.
1 /**
2  * \file IMP/base/ref_counted_macros.h
3  * \brief Various general useful macros for IMP.
4  *
5  * Copyright 2007-2013 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPBASE_REF_COUNTED_MACROS_H
10 #define IMPBASE_REF_COUNTED_MACROS_H
11 #include <IMP/base/base_config.h>
12 #include "utility_macros.h"
13 
14 #ifdef _MSC_VER
15 // VC doesn't understand friends properly
16 #define IMP_REF_COUNTED_DESTRUCTOR(Name) \
17  public: \
18  virtual ~Name() {} \
19  IMP_REQUIRE_SEMICOLON_CLASS(destructor)
20 
21 #define IMP_REF_COUNTED_INLINE_DESTRUCTOR(Name, dest) \
22  public: \
23  virtual ~Name() { dest } \
24  IMP_REQUIRE_SEMICOLON_CLASS(destructor)
25 
26 #define IMP_REF_COUNTED_NONTRIVIAL_DESTRUCTOR(Name) \
27  public: \
28  virtual ~Name()
29 
30 #elif defined(SWIG)
31 // SWIG doesn't do friends right either, but we don't care as much
32 #define IMP_REF_COUNTED_DESTRUCTOR(Name) \
33  public: \
34  virtual ~Name() {} \
35  IMP_REQUIRE_SEMICOLON_CLASS(destructor)
36 
37 #define IMP_REF_COUNTED_INLINE_DESTRUCTOR(Name, dest) \
38  public: \
39  virtual ~Name() { dest } \
40  IMP_REQUIRE_SEMICOLON_CLASS(destructor)
41 
42 #define IMP_REF_COUNTED_NONTRIVIAL_DESTRUCTOR(Name) \
43  public: \
44  virtual ~Name()
45 
46 #elif defined(IMP_DOXYGEN)
47 /* The destructor is unprotected for SWIG since if it is protected
48  SWIG does not wrap the Python proxy distruction and so does not
49  dereference the ref counted pointer. SWIG also gets confused
50  on template friends.
51 */
52 //! Ref counted objects should have private destructors
53 /** This macro defines a private destructor and adds the appropriate
54  friend methods so that the class can be used with ref counting.
55  By defining a private destructor, you make it so that the object
56  cannot be declared on the stack and so must be ref counted.
57 
58  \see IMP_REF_COUNTED_NONTRIVIAL_DESTRUCTOR()
59  \see IMP::base::RefCounted
60 */
61 #define IMP_REF_COUNTED_DESTRUCTOR(Name)
62 
63 /** Like IMP_REF_COUNTED_DESTRUCTOR(), but the destructor is only
64  declared, not defined.
65 */
66 #define IMP_REF_COUNTED_NONTRIVIAL_DESTRUCTOR(Name)
67 
68 /** Like IMP_REF_COUNTED_DESTRUCTOR(), but the destructor is only
69  declared, not defined and is virtual.
70 */
71 #define IMP_REF_COUNTED_NONTRIVIAL_VIRTUAL_DESTRUCTOR(Name)
72 
73 /** Like IMP_REF_COUNTED_DESTRUCTOR(), but the destructor is declared
74  inline.
75 */
76 #define IMP_REF_COUNTED_INLINE_DESTRUCTOR(Name, destructor)
77 
78 #else
79 #define IMP_REF_COUNTED_DESTRUCTOR(Name) \
80  protected: \
81  template <class T, class E> \
82  friend struct IMP::base::internal::RefStuff; \
83  virtual ~Name() {} \
84  \
85  public: \
86  IMP_REQUIRE_SEMICOLON_CLASS(destructor)
87 
88 #define IMP_REF_COUNTED_INLINE_DESTRUCTOR(Name, dest) \
89  protected: \
90  template <class T, class E> \
91  friend struct IMP::base::internal::RefStuff; \
92  virtual ~Name() { dest } \
93  \
94  public: \
95  IMP_REQUIRE_SEMICOLON_CLASS(destructor)
96 
97 #define IMP_REF_COUNTED_NONTRIVIAL_DESTRUCTOR(Name) \
98  protected: \
99  template <class T, class E> \
100  friend struct IMP::base::internal::RefStuff; \
101  virtual ~Name(); \
102  \
103  public: \
104  IMP_REQUIRE_SEMICOLON_CLASS(destructor)
105 
106 #define IMP_REF_COUNTED_NONTRIVIAL_VIRTUAL_DESTRUCTOR(Name) \
107  protected: \
108  template <class T, class E> \
109  friend struct IMP::base::internal::RefStuff; \
110  virtual ~Name(); \
111  \
112  public: \
113  IMP_REQUIRE_SEMICOLON_CLASS(destructor)
114 #endif
115 
116 #endif /* IMPBASE_REF_COUNTED_MACROS_H */
Various general useful macros for IMP.