-
Notifications
You must be signed in to change notification settings - Fork 30
/
showable_macros.h
83 lines (67 loc) · 2.91 KB
/
showable_macros.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
* \file IMP/showable_macros.h
* \brief Macros to help with objects that can be printed to a stream.
*
* Copyright 2007-2022 IMP Inventors. All rights reserved.
*
*/
#ifndef IMPKERNEL_SHOWABLE_MACROS_H
#define IMPKERNEL_SHOWABLE_MACROS_H
#include <IMP/kernel_config.h>
#include "Showable.h"
#include "warning_macros.h"
#if defined(IMP_DOXYGEN) || defined(SWIG)
/** \name Showable
Declare the methods needed by an object that can be printed,
both from C++ and Python. Each value-type class should have an
IMP_SHOWABLE() call internal to it and an IMP_OUTPUT_OPERATOR()
call external to it.
The suffixes are the number of template arguments that the
object has (eg _1 means one template argument). _D means
one integer template argument.
@{
*/
/** This macro declares the method
- void show(std::ostream &out) const
It also makes it so that the object can be printed
in Python.
The \c ostream and \c sstream headers must be included.
\see IMP_SHOWABLE_INLINE().
Do not use with IMP::Object objects as they have their
own show mechanism.
*/
#define IMP_SHOWABLE(Name) void show(std::ostream &out = std::cout) const
//! Declare the methods needed by an object that can be printed
/** This macro declares the method
- \c void \c show(std::ostream &out) const
It also makes it so that the object can be printed
in Python.
The \c ostream and \c sstream headers must be included.
*/
#define IMP_SHOWABLE_INLINE(Name, how_to_show) \
void show(std::ostream &out = std::cout) const
/** @} */
#else
#define IMP_SHOWABLE(Name) \
IMP_HELPER_MACRO_PUSH_WARNINGS void show(std::ostream &out = \
std::cout) const; \
operator IMP::Showable() const { \
std::ostringstream oss; \
show(oss); \
return IMP::Showable(oss.str()); \
} \
IMP_HELPER_MACRO_POP_WARNINGS IMP_REQUIRE_SEMICOLON_CLASS(showable)
#define IMP_SHOWABLE_INLINE(Name, how_to_show) \
IMP_HELPER_MACRO_PUSH_WARNINGS void show(std::ostream &out = \
std::cout) const { \
how_to_show; \
} \
operator IMP::Showable() const { \
std::ostringstream oss; \
show(oss); \
return IMP::Showable(oss.str()); \
} \
IMP_HELPER_MACRO_POP_WARNINGS IMP_REQUIRE_SEMICOLON_CLASS(showable)
#endif
/** @} */
#endif /* IMPKERNEL_SHOWABLE_MACROS_H */