home
about
news
download
doc
source
systems
tests
bugs
contact
IMP Reference Guide
develop.63b38c487d,2024/12/21
The Integrative Modeling Platform
IMP Manual
Reference Guide
Tutorial Index
Modules
Classes
Examples
include
IMP
version 20241221.develop.63b38c487d
raii_macros.h
Go to the documentation of this file.
1
/**
2
* \file IMP/raii_macros.h
3
* \brief Macros to aid in writing RAII-style classes.
4
*
5
* Copyright 2007-2022 IMP Inventors. All rights reserved.
6
*
7
*/
8
9
#ifndef IMPKERNEL_RAII_MACROS_H
10
#define IMPKERNEL_RAII_MACROS_H
11
#include <IMP/kernel_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 parentheses) for the explicit
26
constructor 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
/** \brief Explicit constructor that sets the properties of Name */
\
37
explicit Name args { \
38
Initialize; \
39
Set; \
40
} \
41
/** \brief Assign new properties to the class */
\
42
void set args { \
43
reset(); \
44
Set; \
45
} \
46
/** \brief Remove 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
/* IMPKERNEL_RAII_MACROS_H */
RAII.h
Basic types used by IMP.
showable_macros.h
Macros to help with objects that can be printed to a stream.