IMP  2.3.1
The Integrative Modeling Platform
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-2014 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 constructor, 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 #endif /* IMPBASE_RAII_MACROS_H */
Basic types used by IMP.
Various general useful macros for IMP.