IMP logo
IMP Reference Guide  2.17.0
The Integrative Modeling Platform
object_macros.h
Go to the documentation of this file.
1 /**
2  * \file IMP/object_macros.h
3  * \brief Helper macros for implementing \imp Objects.
4  *
5  * Copyright 2007-2022 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPKERNEL_OBJECT_MACROS_H
10 #define IMPKERNEL_OBJECT_MACROS_H
11 #include <IMP/kernel_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::Object::get_version_info()
22  - IMP::Object::get_type_name()
23  - a protected destructor
24 */
25 #define IMP_OBJECT_METHODS(Name) \
26  public: \
27  virtual std::string get_type_name() const override { return #Name; } \
28  virtual ::IMP::VersionInfo get_version_info() const override { \
29  return ::IMP::VersionInfo(get_module_name(), get_module_version()); \
30  } \
31  \
32  protected: \
33  virtual ~Name() { IMP::Object::_on_destruction(); } \
34  \
35  public:
36 
37 //! Define the types for storing lists of object pointers
38 /** The macro defines the types PluralName and PluralNameTemp,
39  which are vectors of either reference-counting or non reference-counting
40  pointers to Name objects, respectively.
41  PluralName should be Names unless the English spelling is
42  different.
43  */
44 #define IMP_OBJECTS(Name, PluralName) \
45  /** A vector of reference-counting object pointers.*/ \
46  typedef IMP::Vector<IMP::Pointer<Name> > PluralName; \
47  /** A vector of weak (non reference-counting) pointers to specified objects. \see Name */ \
48  typedef IMP::Vector<IMP::WeakPointer<Name> > PluralName##Temp;
49 
50 //! Typedefs a default instantiation for a generic (templated) object
51 /**
52  Define type [Name] to be an an instantiation of of Generic[Name] with
53  template targument, and a function create_[lcname]() that generates a
54  newly allocated object of type [Name], taking parameters [crguments]
55  and internally paassing [cparguments] to the constructor.
56 
57  @note doxygen documentatio prior to this macro will be applied to the type
58  definition
59  */
60 #define IMP_GENERIC_OBJECT(Name, lcname, targument, carguments, cparguments) \
61  typedef Generic##Name<targument> Name; \
62  template <class targument> \
63  Generic##Name<targument> *create_##lcname carguments { \
64  return new Generic##Name<targument> cparguments; \
65  }
66 
67 //! Declare a ref counted pointer to a new object
68 /** \param[in] Typename The namespace qualified type being declared
69  \param[in] varname The name for the ref counted pointer
70  \param[in] args The arguments to the constructor, or ()
71  if there are none.
72  Please read the documentation for IMP::Pointer before using.
73 */
74 #define IMP_NEW(Typename, varname, args) \
75  IMP::Pointer<Typename> varname(new Typename args)
76 
77 #endif /* IMPKERNEL_OBJECT_MACROS_H */
Macros to help with reference counting.
A class to change and restore log state.
Helper macros for writing doxygen documentation.
A weak pointer to an Object or RefCountedObject.
A class for storing lists of IMP items.
A nullptr-initialized pointer to an IMP Object.