IMP  2.1.1
The Integrative Modeling Platform
base/showable_macros.h
Go to the documentation of this file.
1 /**
2  * \file IMP/base/showable_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_SHOWABLE_MACROS_H
10 #define IMPBASE_SHOWABLE_MACROS_H
11 #include <IMP/base/base_config.h>
12 #include "Showable.h"
13 #include "warning_macros.h"
14 
15 #if defined(IMP_DOXYGEN) || defined(SWIG)
16 /** \name Showable
17  Declare the methods needed by an object that can be printed,
18  both from C++ and Python. Each value-type class should have an
19  IMP_SHOWABLE() call internal to it and an IMP_OUTPUT_OPERATOR()
20  call external to it.
21 
22  The suffixs are the number of template arguments that the
23  object has (eg _1 means one template argument). _D means
24  one integer template argument.
25  @{
26 */
27 
28 /** This macro declares the method
29  - void show(std::ostream &out) const
30  It also makes it so that the object can be printed
31  in Python.
32 
33  The \c ostream and \c sstream headers must be included.
34 
35  See also IMP_SHOWABLE_INLINE().
36 
37  Do not use with IMP::Object objects as they have their
38  own show mechanism.
39 */
40 #define IMP_SHOWABLE(Name) void show(std::ostream &out = std::cout) const
41 
42 //! Declare the methods needed by an object that can be printed
43 /** This macro declares the method
44  - \c void \c show(std::ostream &out) const
45  It also makes it so that the object can be printed
46  in Python.
47 
48  The \c ostream and \c sstream headers must be included.
49 
50  See also IMP_SHOWABLE_INLINE()
51 */
52 #define IMP_SHOWABLE_INLINE(Name, how_to_show) \
53  void show(std::ostream &out = std::cout) const
54 /** @} */
55 
56 #else
57 
58 #define IMP_SHOWABLE(Name) \
59  IMP_HELPER_MACRO_PUSH_WARNINGS void show(std::ostream &out = \
60  std::cout) const; \
61  operator IMP::base::Showable() const { \
62  std::ostringstream oss; \
63  show(oss); \
64  return IMP::base::Showable(oss.str()); \
65  } \
66  IMP_HELPER_MACRO_POP_WARNINGS IMP_REQUIRE_SEMICOLON_CLASS(showable)
67 
68 #define IMP_SHOWABLE_INLINE(Name, how_to_show) \
69  IMP_HELPER_MACRO_PUSH_WARNINGS void show(std::ostream &out = \
70  std::cout) const { \
71  how_to_show; \
72  } \
73  operator IMP::base::Showable() const { \
74  std::ostringstream oss; \
75  show(oss); \
76  return IMP::base::Showable(oss.str()); \
77  } \
78  IMP_HELPER_MACRO_POP_WARNINGS IMP_REQUIRE_SEMICOLON_CLASS(showable)
79 
80 #endif
81 
82 /** @} */
83 
84 #endif /* IMPBASE_SHOWABLE_MACROS_H */
Various general useful macros for IMP.
IO support.