LIBINT  2.1.0-stable
smart_ptr.h
1 /*
2  * This file is a part of Libint.
3  * Copyright (C) 2004-2014 Edward F. Valeev
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see http://www.gnu.org/licenses/.
17  *
18  */
19 
20 #ifndef _libint2_src_bin_libint_smartptr_h_
21 #define _libint2_src_bin_libint_smartptr_h_
22 
23 #include <libint2/config.h>
24 
25 #if HAVE_SHARED_PTR_IN_BOOST
26  #include <boost/shared_ptr.hpp>
27  #include <boost/enable_shared_from_this.hpp>
28  using namespace boost;
29 
30  // For now I'll do a cheat since templated typedefs are not standard
31  // Should probably at least derive SafePtr from shared_ptr
32  #define SafePtr boost::shared_ptr
33  #define EnableSafePtrFromThis boost::enable_shared_from_this
34  #define SafePtr_from_this shared_from_this
35 #else
36  #include <memory>
37  // For now I'll do a cheat since templated typedefs are not standard
38  // Should probably at least derive SafePtr from shared_ptr
39  #define SafePtr std::shared_ptr
40  #define EnableSafePtrFromThis std::enable_shared_from_this
41  #define SafePtr_from_this shared_from_this
42  using std::dynamic_pointer_cast;
43 #endif
44 
46 template <typename T>
47 struct IsSafePtr {
48  enum { result = false };
49 };
50 
51 template <typename T>
52 struct IsSafePtr< SafePtr<T> > {
53  enum { result = true };
54 };
55 template <typename T>
56 struct IsSafePtr< const SafePtr<T> > {
57  enum { result = true };
58 };
59 template <typename T>
60 struct IsSafePtr< SafePtr<T>& > {
61  enum { result = true };
62 };
63 template <typename T>
64 struct IsSafePtr< const SafePtr<T>& > {
65  enum { result = true };
66 };
67 
68 #endif
69 
Can be used to determine whether a type is a SafePtr.
Definition: smart_ptr.h:47