IMP logo
IMP Reference Guide  2.12.0
The Integrative Modeling Platform
ref_counted_macros.h
Go to the documentation of this file.
1 /**
2  * \file IMP/ref_counted_macros.h
3  * \brief Various general useful macros for IMP.
4  *
5  * Copyright 2007-2019 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPKERNEL_REF_COUNTED_MACROS_H
10 #define IMPKERNEL_REF_COUNTED_MACROS_H
11 #include <IMP/kernel_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 destruction 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 */
60 #define IMP_REF_COUNTED_DESTRUCTOR(Name)
61 
62 /** Like IMP_REF_COUNTED_DESTRUCTOR(), but the destructor is only
63  declared, not defined.
64 */
65 #define IMP_REF_COUNTED_NONTRIVIAL_DESTRUCTOR(Name)
66 
67 /** Like IMP_REF_COUNTED_DESTRUCTOR(), but the destructor is declared
68  inline.
69 */
70 #define IMP_REF_COUNTED_INLINE_DESTRUCTOR(Name, destructor)
71 
72 #else
73 #define IMP_REF_COUNTED_DESTRUCTOR(Name) \
74  protected: \
75  virtual ~Name() {} \
76  \
77  public: \
78  IMP_REQUIRE_SEMICOLON_CLASS(destructor)
79 
80 #define IMP_REF_COUNTED_INLINE_DESTRUCTOR(Name, dest) \
81  protected: \
82  virtual ~Name() { dest } \
83  \
84  public: \
85  IMP_REQUIRE_SEMICOLON_CLASS(destructor)
86 
87 #define IMP_REF_COUNTED_NONTRIVIAL_DESTRUCTOR(Name) \
88  protected: \
89  virtual ~Name(); \
90  \
91  public: \
92  IMP_REQUIRE_SEMICOLON_CLASS(destructor)
93 #endif
94 
95 #endif /* IMPKERNEL_REF_COUNTED_MACROS_H */
Various general useful macros for IMP.