IMP  2.0.0
The Integrative Modeling Platform
utility_macros.h
Go to the documentation of this file.
1 /**
2  * \file IMP/base/utility_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_UTILITY_MACROS_H
10 #define IMPBASE_UTILITY_MACROS_H
11 #include <IMP/base/base_config.h>
12 
13 //! Use a copy_from method to create a copy constructor and operator=
14 /** This macro is there to aid with classes which require a custom
15  copy constructor. It simply forwards \c operator= and the copy
16  constructor to a method \c copy_from() which should do the copying.
17 
18  You should think very hard before implementing a class which
19  requires a custom copy custructor as it is easy to get wrong
20  and you can easily wrap most resources with RAII objects
21  (\external{http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization,
22  wikipedia entry}).
23 */
24 #define IMP_COPY_CONSTRUCTOR(Name, Base) Name(const Name &o): Base() \
25  {copy_from(o);} \
26  IMP_NO_SWIG(Name& operator=(const Name &o) {copy_from(o); return *this;}) \
27  IMP_REQUIRE_SEMICOLON_CLASS(copy)
28 
29 #define IMP_PROTECTED_METHOD_DECL(protection, return_value, name, arguments, \
30  const_or_not, body) \
31  protection: \
32  return_value name arguments const_or_not body
33 
34 #define IMP_PROTECTED_CONSTRUCTOR_DECL(protection, Name, arguments, body) \
35  protection: \
36  Name arguments body
37 
38 #define IMP_PROTECTED_DESTRUCTOR_DECL(protection, Name, arguments, body) \
39  protection: \
40  virtual ~Name arguments body
41 
42 #if defined(IMP_DOXYGEN)
43 //! Use this when declaring methods protected
44 /** Using this macro instead of just \c protected: ensures that protected
45  methods are available for use in Python as well as in C++. The methods
46  are made availabe in python with an \c _ prefix to denote that they
47  are protected.*/
48 #define IMP_PROTECTED_METHOD(return_value, name, arguments, const_or_not, \
49  body) \
50  IMP_PROTECTED_METHOD_DECL(protected, return_value, name, arguments,\
51  const_or_not, body)
52 
53 
54 //! Use this when declaring constructors protected
55 /** Using this macro instead of just \c protected: ensures that protected
56  constructors are available for use in Python as well as in C++.*/
57 #define IMP_PROTECTED_CONSTRUCTOR(Name, arguments, body) \
58  IMP_PROTECTED_CONSTRUCTOR_DECL(protected, Name, arguments, body)
59 
60 //! Use this when declaring destructors protected
61 /** Using this macro instead of just \c protected: ensures that protected
62  constructors are available for use in Python as well as in C++.
63  \note These destructors are virtual destructors. Most classes that use
64  this have virtual methods.
65 */
66 #define IMP_PROTECTED_DESTRUCTOR(Name, arguments, body) \
67  IMP_PROTECTED_DESTRUCTOR_DECL(protected, Name, arguments, body)
68 
69 
70 /** Use this to declare a method that should be hidden from swig and
71  the docs, but can't be private so some reason or another. Not
72  something you should do often.*/
73 #define IMP_INTERNAL_METHOD(return_value, name, arguments, const_or_not, \
74  body)
75 
76 #elif defined(IMP_SWIG_WRAPPER) || defined(_MSC_VER)
77 #define IMP_PROTECTED_METHOD(return_value, name, arguments, \
78  const_or_not, body) \
79  IMP_PROTECTED_METHOD_DECL(public, return_value, name, arguments, \
80  const_or_not, body)
81 
82 #define IMP_INTERNAL_METHOD(return_value, name, arguments, \
83  const_or_not, body) \
84  IMP_PROTECTED_METHOD_DECL(public, return_value, name, arguments, \
85  const_or_not, body)
86 
87 
88 
89 #define IMP_PROTECTED_CONSTRUCTOR(Name, arguments, body) \
90  IMP_PROTECTED_CONSTRUCTOR_DECL(public, Name, arguments, body)
91 
92 #define IMP_PROTECTED_DESTRUCTOR(Name, arguments, body) \
93  IMP_PROTECTED_DESTRUCTOR_DECL(public, Name, arguments, body)
94 
95 #elif defined(SWIG)
96 #define IMP_PROTECTED_METHOD(return_value, name, arguments, \
97  const_or_not, body) \
98  %rename(_##name) name; \
99  IMP_PROTECTED_METHOD_DECL(public, return_value, name, arguments, \
100  const_or_not, body)
101 
102 #define IMP_INTERNAL_METHOD(return_value, name, arguments, \
103  const_or_not, body)
104 
105 
106 #define IMP_PROTECTED_CONSTRUCTOR(Name, arguments, body) \
107  IMP_PROTECTED_CONSTRUCTOR_DECL(public, Name, arguments, body)
108 
109 #define IMP_PROTECTED_DESTRUCTOR(Name, arguments, body) \
110  IMP_PROTECTED_DESTRUCTOR_DECL(public, Name, arguments, body)
111 
112 
113 #else
114 #define IMP_PROTECTED_METHOD(return_value, name, arguments, const_or_not, \
115  body) \
116  IMP_PROTECTED_METHOD_DECL(protected, return_value, name, arguments, \
117  const_or_not, body)
118 
119 #define IMP_INTERNAL_METHOD(return_value, name, arguments, const_or_not, \
120  body) \
121  IMP_PROTECTED_METHOD_DECL(public, return_value, name, arguments, \
122  const_or_not, body)
123 
124 
125 #define IMP_PROTECTED_CONSTRUCTOR(Name, arguments, body) \
126  IMP_PROTECTED_CONSTRUCTOR_DECL(protected, Name, arguments, body)
127 
128 
129 #define IMP_PROTECTED_DESTRUCTOR(Name, arguments, body) \
130  IMP_PROTECTED_DESTRUCTOR_DECL(protected, Name, arguments, body)
131 
132 #endif
133 
134 #define IMP_EXPAND_AND_STRINGIFY(x) IMP_STRINGIFY(x)
135 
136 
137 #endif /* IMPBASE_UTILITY_MACROS_H */