DD4hep - The AIDA detector description toolkit for high energy physics experiments
DD4hep  Rev:Unversioneddirectory
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Memory.h
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation for LCD
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 
14 #ifndef DD4HEP_MEMORY_H
15 #define DD4HEP_MEMORY_H
16 
17 // Framework include files
18 #include "RVersion.h"
19 
20 #ifdef __GNUC__
21 #pragma GCC diagnostic push
22 #pragma GCC diagnostic ignored "-Wdeprecated-declarations" // Code that causes warning goes here
23 #endif
24 
25 // C/C++ include files
26 #include <memory>
27 
28 // Use std::auto_ptr<T> instead of std::unique_ptr<T>
29 #define DD4HEP_DD4HEP_PTR_AUTO
30 
32 namespace DD4hep {
33 
35 
43  template <typename T> class dd4hep_ptr
44  //#if defined(DD4HEP_NEVER) && __cplusplus >= 201103L && ROOT_VERSION_CODE >= ROOT_VERSION(6,0,0)
45 #if !defined(DD4HEP_DD4HEP_PTR_AUTO) && __cplusplus >= 201103L && ROOT_VERSION_CODE >= ROOT_VERSION(6,0,0)
46  : public std::unique_ptr<T> {
47  public:
48  typedef std::unique_ptr<T> base_t;
49 #else
50  : public std::auto_ptr<T> {
51  public:
52  typedef std::auto_ptr<T> base_t;
53  void swap(base_t& c) {
54  this->base_t::operator=(base_t(c.release()));
55  }
57  dd4hep_ptr(dd4hep_ptr<T>& c) : base_t(c) {}
58 #endif
59  public:
61  dd4hep_ptr() : base_t() {}
63  dd4hep_ptr(T* p) : base_t(p) {}
65  dd4hep_ptr(base_t& c) : base_t(c) {}
67  dd4hep_ptr& operator=(base_t& c) {
68  if ( this != &c ) {
69  this->swap(c);
70  }
71  return *this;
72  }
74  dd4hep_ptr& adopt(T* ptr) {
75  base_t smart_ptr(ptr);
76  this->swap(smart_ptr);
77  return *this;
78  }
79  };
80  }
81 
82 #ifdef __GNUC__
83 #pragma GCC diagnostic pop
84 #endif
85 
86 #endif // DD4HEP_MEMORY_H
dd4hep_ptr()
Default Constructor.
Definition: Memory.h:61
dd4hep_ptr & adopt(T *ptr)
Assignment operator.
Definition: Memory.h:74
Out version of the std auto_ptr implementation base either on auto_ptr or unique_ptr.
Definition: Memory.h:43
dd4hep_ptr(dd4hep_ptr< T > &c)
Constructor from copy.
Definition: Memory.h:57
std::auto_ptr< T > base_t
Definition: Memory.h:52
dd4hep_ptr(T *p)
Constructor from pointer.
Definition: Memory.h:63
dd4hep_ptr & operator=(base_t &c)
Assignment operator.
Definition: Memory.h:67
void swap(base_t &c)
Definition: Memory.h:53
dd4hep_ptr(base_t &c)
Constructor from copy.
Definition: Memory.h:65
#define DD4HEP_DD4HEP_PTR_AUTO
Definition: Memory.h:29