Program listing for file kernel/src/utils/SiconosTools/SiconosPointers.hpp

Program listing for file kernel/src/utils/SiconosTools/SiconosPointers.hpp#

  1#ifndef SiconosPointers_hpp
  2#define SiconosPointers_hpp
  3
  4
  5
  6
  7#include <memory>
  8
  9
 10
 11#include <boost/shared_array.hpp>
 12
 13namespace SP {}
 14namespace SPC {}
 15namespace SA {}
 16
 17
 18namespace SharedPointer = SP;
 19
 20
 21namespace SharedArray = SA;
 22
 23
 24namespace SharedPointerConst = SPC;
 25
 26
 27
 28
 29struct nullDeleter
 30{
 31  void operator()(void const *) const {}
 32};
 33
 34
 35
 36#define NAME_SPACE_SPTR(X) \
 37  namespace SP \
 38  { \
 39    typedef SPtr##X X; \
 40  } \
 41  namespace SPC \
 42  { \
 43    typedef SPtrConst##X X;\
 44  }
 45
 46#define NAME_SPACE_SAPTR(X)                     \
 47  namespace SA \
 48  { \
 49    typedef X##SAPtr X; \
 50  }
 51
 52
 53
 54
 55#define TYPEDEF_SPTR(X) \
 56  typedef std::shared_ptr<X> SPtr##X; \
 57  typedef std::shared_ptr<const X> SPtrConst##X; \
 58  inline SPtr##X create##SPtr##X(X &x) \
 59  { \
 60    std::shared_ptr<X> px(&x, nullDeleter()); \
 61    return px; \
 62  } \
 63  inline SPtrConst##X create##SPtrConst##X(const X &x) \
 64  { \
 65    std::shared_ptr<const X> px(&x, nullDeleter()); \
 66    return px; \
 67  } \
 68  NAME_SPACE_SPTR(X)
 69
 70#define TYPEDEF_SAPTR(X)                        \
 71  typedef boost::shared_array<X> X##SAPtr ;     \
 72  NAME_SPACE_SAPTR(X)
 73
 74
 75#define DEFINE_SPTR(X)                          \
 76  class X; \
 77  TYPEDEF_SPTR(X)
 78
 79#define DEFINE_SPTR_STRUCT(X) \
 80  struct X; \
 81  TYPEDEF_SPTR(X)
 82
 83#define DEFINE_SAPTR(X) \
 84  class X; \
 85  TYPEDEF_SAPTR(X)
 86
 87
 88
 89
 90#define NAME_SPACE_TPL1_SPTR(N,X,Y)              \
 91  namespace SP                                   \
 92  {                                              \
 93    typedef SPtr##N N;                           \
 94  }                                              \
 95  namespace SPC                                  \
 96  {                                              \
 97    typedef SPtrConst##N N;                      \
 98  }
 99
100#define TYPEDEF_TPL1_SPTR(N,X,Y)                           \
101  typedef std::shared_ptr<X<Y> > SPtr##N;                \
102  typedef std::shared_ptr<const X<Y> > SPtrConst##N;     \
103  inline SPtr##N create##SPtr##N(X<Y> &x)                  \
104  {                                                        \
105    std::shared_ptr<X<Y> > px(&x, nullDeleter());        \
106    return px;                                             \
107  }                                                        \
108  inline SPtrConst##N create##SPtrConst##N(const X<Y> &x)  \
109  {                                                        \
110    std::shared_ptr<const X<Y> > px(&x, nullDeleter());  \
111    return px;                                             \
112  }                                                        \
113  NAME_SPACE_TPL1_SPTR(N,X,Y)
114
115#endif