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