IMP  2.1.0
The Integrative Modeling Platform
base/object_macros.h
Go to the documentation of this file.
1 /**
2  * \file IMP/base/object_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_OBJECT_MACROS_H
10 #define IMPBASE_OBJECT_MACROS_H
11 #include <IMP/base/base_config.h>
12 #include "doxygen_macros.h"
13 #include "ref_counted_macros.h"
14 #include "Vector.h"
15 #include "Pointer.h"
16 #include "WeakPointer.h"
17 #include "SetLogState.h"
18 
19 //! Define the basic things needed by any Object
20 /** This defines
21  - IMP::base::Object::get_version_info()
22  - IMP::base::Object::get_type_name()
23  - a private destructor
24 */
25 #define IMP_OBJECT_METHODS(Name) \
26  public: \
27  virtual std::string get_type_name() const IMP_OVERRIDE { return #Name; } \
28  virtual ::IMP::base::VersionInfo get_version_info() const IMP_OVERRIDE { \
29  return ::IMP::base::VersionInfo(get_module_name(), get_module_version()); \
30  } \
31  IMP_REF_COUNTED_INLINE_DESTRUCTOR(Name, IMP::base::Object::_on_destruction();)
32 
33 /** \deprecated_at{2.1} Use IMP_OBJECT_METHODS() */
34 #define IMP_OBJECT_INLINE(Name, show, destructor) \
35  public: \
36  IMPBASE_DEPRECATED_MACRO(2.1, "Use IMP_OBJECT_METHODS() instead."); \
37  virtual std::string get_type_name() const IMP_OVERRIDE { return #Name; } \
38  virtual ::IMP::base::VersionInfo get_version_info() const IMP_OVERRIDE { \
39  return ::IMP::base::VersionInfo(get_module_name(), get_module_version()); \
40  } \
41  IMP_REF_COUNTED_INLINE_DESTRUCTOR(Name, \
42  try { \
43  IMP::base::Object::_on_destruction(); \
44  destructor; \
45  } catch (const std::exception & \
46  e) { \
47  IMP_LOG_VARIABLE(e); \
48  IMP_WARN("Caught exception " << e.what() << " in destructor."); \
49  })
50 
51 //! Only to work aroung a gcc bug
52 #define IMP_OBJECT_NO_WARNING(Name) \
53  public: \
54  virtual std::string get_type_name() const IMP_OVERRIDE { return #Name; } \
55  virtual ::IMP::base::VersionInfo get_version_info() const IMP_OVERRIDE { \
56  return ::IMP::base::VersionInfo(get_module_name(), get_module_version()); \
57  } \
58  void do_show(std::ostream &out) const; \
59  IMP_REF_COUNTED_INLINE_DESTRUCTOR(Name, IMP::base::Object::_on_destruction();)
60 
61 //! \deprecated_at{2.1} Use IMP_OBJECT_METHODS()
62 #define IMP_OBJECT(Name) \
63  public: \
64  IMPBASE_DEPRECATED_MACRO(2.1, "Use IMP_OBJECT_METHODS() instead."); \
65  IMP_OBJECT_NO_WARNING(Name)
66 
67 /** \deprecated_at{2.1} Use IMP_OBJECT_METHODS() */
68 #define IMP_OBJECT_2(Name) \
69  IMP_DEPRECATED_MACRO(2.0, "Use IMP_OBJECT_METHODS() macro") \
70  IMP_OBJECT_METHODS(Name)
71 
72 //! Define the types for storing sets of objects
73 /** The macro defines the types PluralName and PluralNameTemp.
74  PluralName should be Names unless the English spelling is
75  different.
76  */
77 #define IMP_OBJECTS(Name, PluralName) \
78  /** Store a set of objects.*/ \
79  typedef IMP::base::Vector<IMP::base::Pointer<Name> > PluralName; /** Pass a \
80  set of \
81  objects. \
82  See \
83  Name */ \
84  typedef IMP::base::Vector<IMP::base::WeakPointer<Name> > PluralName##Temp;
85 
86 #define IMP_GENERIC_OBJECT(Name, lcname, targument, carguments, cparguments) \
87  typedef Generic##Name<targument> Name; \
88  template <class targument> \
89  Generic##Name<targument> *create_##lcname carguments { \
90  return new Generic##Name<targument> cparguments; \
91  }
92 
93 //! Declare a ref counted pointer to a new object
94 /** \param[in] Typename The namespace qualified type being declared
95  \param[in] varname The name for the ref counted pointer
96  \param[in] args The arguments to the constructor, or ()
97  if there are none.
98  Please read the documentation for IMP::Pointer before using.
99 */
100 #define IMP_NEW(Typename, varname, args) \
101  IMP::base::Pointer<Typename> varname(new Typename args)
102 
103 #endif /* IMPBASE_OBJECT_MACROS_H */
Various general useful macros for IMP.
A nullptr-initialized pointer to an IMP Object.
Logging and error reporting support.
A class for storing lists of IMP items.
Various general useful macros for IMP.
A nullptr-initialized pointer to an Object.