IMP  2.1.1
The Integrative Modeling Platform
base/raii_macros.h
Go to the documentation of this file.
1 /**
2  * \file IMP/base/raii_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_RAII_MACROS_H
10 #define IMPBASE_RAII_MACROS_H
11 #include <IMP/base/base_config.h>
12 #include "showable_macros.h"
13 #include "RAII.h"
14 
15 //! Declares RAII-style methods in a class
16 /** Since such class methods are typically quite small and simple, all
17  the implementation is inline. The macro declares
18  - default constructor
19  - explicit constructor
20  - RAII::set()
21  - RAII::reset()
22  - destructor
23 
24  @param Name the class name
25  @param args the argument string (in parens) for the explicit constructor
26  and set()
27  @param Initialize code called from any constrcutor, including the default
28  @param Set the code called from the explicit constructor or the set()
29  function
30  @param Reset the code called from the destructor, and in set before calling
31  the Set code
32  @param Show the code for the show() method
33 */
34 #define IMP_RAII(Name, args, Initialize, Set, Reset, Show) \
35  IMP_HELPER_MACRO_PUSH_WARNINGS Name() { Initialize; } \
36  /** explicit constructor that sets the properties of Name */ \
37  explicit Name args { \
38  Initialize; \
39  Set; \
40  } \
41  /** sets the properties of the class to new ones */ \
42  void set args { \
43  reset(); \
44  Set; \
45  } \
46  /** resets the properties previously set for this class */ \
47  void reset() { Reset; } \
48  ~Name() { reset(); } \
49  IMP_HELPER_MACRO_POP_WARNINGS IMP_SHOWABLE_INLINE(Name, out << #Name << '('; \
50  Show; out << ')')
51 
52 #ifdef SWIG
53 #define IMP_DEPRECATED_RAII(version, help_message, MODULE, Name, args, \
54  Initialize, Set, Reset, Show) \
55  Name(); \
56  explicit Name args; \
57  void set args; \
58  void reset(); \
59  ~Name(); \
60  IMP_SHOWABLE_INLINE(Name, out << #Name << '('; Show; out << ')')
61 #else
62 /** Like IMP_RAII, but for deprecated versions (it has hard to apply
63  the deprecated macros oneself.*/
64 #define IMP_DEPRECATED_RAII(version, help_message, MODULE, Name, args, \
65  Initialize, Set, Reset, Show) \
66  IMP_HELPER_MACRO_PUSH_WARNINGS IMP##MODULE##_DEPRECATED_VALUE_DECL(version) \
67  Name() { \
68  IMP##MODULE##_DEPRECATED_VALUE_DEF(version, help_message); \
69  Initialize; \
70  } \
71  IMP##MODULE##_DEPRECATED_VALUE_DECL(version) explicit Name args { \
72  IMP##MODULE##_DEPRECATED_VALUE_DEF(version, help_message); \
73  Initialize; \
74  Set; \
75  } \
76  void set args { \
77  reset(); \
78  Set; \
79  } \
80  void reset() { Reset; } \
81  ~Name() { reset(); } \
82  IMP_HELPER_MACRO_POP_WARNINGS IMP_SHOWABLE_INLINE(Name, out << #Name << '('; \
83  Show; out << ')')
84 #endif
85 
86 #endif /* IMPBASE_RAII_MACROS_H */
Basic types used by IMP.
Various general useful macros for IMP.