IMP  2.3.1
The Integrative Modeling Platform
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-2014 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 suffixes 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 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 #define IMP_SHOWABLE_INLINE(Name, how_to_show) \
51  void show(std::ostream &out = std::cout) const
52 /** @} */
53 
54 #else
55 
56 #define IMP_SHOWABLE(Name) \
57  IMP_HELPER_MACRO_PUSH_WARNINGS void show(std::ostream &out = \
58  std::cout) const; \
59  operator IMP::base::Showable() const { \
60  std::ostringstream oss; \
61  show(oss); \
62  return IMP::base::Showable(oss.str()); \
63  } \
64  IMP_HELPER_MACRO_POP_WARNINGS IMP_REQUIRE_SEMICOLON_CLASS(showable)
65 
66 #define IMP_SHOWABLE_INLINE(Name, how_to_show) \
67  IMP_HELPER_MACRO_PUSH_WARNINGS void show(std::ostream &out = \
68  std::cout) const { \
69  how_to_show; \
70  } \
71  operator IMP::base::Showable() const { \
72  std::ostringstream oss; \
73  show(oss); \
74  return IMP::base::Showable(oss.str()); \
75  } \
76  IMP_HELPER_MACRO_POP_WARNINGS IMP_REQUIRE_SEMICOLON_CLASS(showable)
77 
78 #endif
79 
80 /** @} */
81 
82 #endif /* IMPBASE_SHOWABLE_MACROS_H */
IO support.
Various general useful macros for IMP.