IMP  2.0.0
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-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) \
41  void show(std::ostream &out=std::cout) const
42 
43 //! Declare the methods needed by an object that can be printed
44 /** This macro declares the method
45  - \c void \c show(std::ostream &out) const
46  It also makes it so that the object can be printed
47  in Python.
48 
49  The \c ostream and \c sstream headers must be included.
50 
51  See also IMP_SHOWABLE_INLINE()
52 */
53 #define IMP_SHOWABLE_INLINE(Name, how_to_show) \
54  void show(std::ostream &out=std::cout) const
55 /** @} */
56 
57 #else
58 
59 #define IMP_SHOWABLE(Name) \
60  IMP_HELPER_MACRO_PUSH_WARNINGS \
61  void show(std::ostream &out=std::cout) const; \
62  operator IMP::base::Showable() const { \
63  std::ostringstream oss; \
64  show(oss); \
65  return IMP::base::Showable(oss.str()); \
66  } \
67  IMP_HELPER_MACRO_POP_WARNINGS \
68  IMP_REQUIRE_SEMICOLON_CLASS(showable)
69 
70 #define IMP_SHOWABLE_INLINE(Name, how_to_show) \
71  IMP_HELPER_MACRO_PUSH_WARNINGS \
72  void show(std::ostream &out=std::cout) const{ \
73  how_to_show; \
74  } \
75  operator IMP::base::Showable() const { \
76  std::ostringstream oss; \
77  show(oss); \
78  return IMP::base::Showable(oss.str()); \
79  } \
80  IMP_HELPER_MACRO_POP_WARNINGS \
81  IMP_REQUIRE_SEMICOLON_CLASS(showable)
82 
83 #endif
84 
85 /** @} */
86 
87 
88 #endif /* IMPBASE_SHOWABLE_MACROS_H */