MPQC  3.0.0-alpha
sharedptr.h
1 //
2 // sharedptr.h
3 //
4 // Copyright (C) 2013 MPQC Developers
5 //
6 // Author: David Hollman <dhollman@vt.edu>
7 // Maintainer: DSH, EV
8 //
9 // This file is part of the SC Toolkit.
10 //
11 // The SC Toolkit is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU Library General Public License as published by
13 // the Free Software Foundation; either version 2, or (at your option)
14 // any later version.
15 //
16 // The SC Toolkit is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU Library General Public License for more details.
20 //
21 // You should have received a copy of the GNU Library General Public License
22 // along with the SC Toolkit; see the file COPYING.LIB. If not, write to
23 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24 //
25 // The U.S. Government is granted a limited license as per AL 91-7.
26 //
27 
28 /*******************************************************************************
29  * Temporary fix to Eclipse parsing issues with shared_ptr. Also makes it
30  * possible to use some other shared_ptr implementation as a std::shared_ptr
31  * if C++11 is not available.
32  *******************************************************************************/
33 
34 #ifndef _lib_util_misc_sharedptr_h
35 #define _lib_util_misc_sharedptr_h
36 #include <memory>
37 
38 #ifdef ECLIPSE_PARSER_ONLY
39 
40 #include <cassert>
41 namespace std {
42  template <typename T>
43  class shared_ptr {
44  public:
45  // Act like a dumb pointer. This should never actually get compiled.
46  shared_ptr(T* ptr){ assert(false && "should never get here"); ptr_ = ptr; }
47  T operator*(){ assert(false && "should never get here"); return *ptr_; }
48  const T operator*() const { assert(false && "should never get here"); return *ptr_; }
49  T* operator->(){ assert(false && "should never get here"); return ptr_; }
50  const T operator->() const { assert(false && "should never get here"); return *ptr_; }
51  T* get(){ assert(false && "should never get here"); return ptr_; }
52  const T* get() const { assert(false && "should never get here"); return ptr_; }
53 
54  protected:
55  T* ptr_;
56  };
57  template <typename T>
58  class unique_ptr {
59  public:
60  // Act like a dumb pointer. This should never actually get compiled.
61  shared_ptr(T* ptr){ assert(false && "should never get here"); ptr_ = ptr; }
62  T operator*(){ assert(false && "should never get here"); return *ptr_; }
63  const T operator*() const { assert(false && "should never get here"); return *ptr_; }
64  T* operator->(){ assert(false && "should never get here"); return ptr_; }
65  const T operator->() const { assert(false && "should never get here"); return *ptr_; }
66  T* get(){ assert(false && "should never get here"); return ptr_; }
67  const T* get() const { assert(false && "should never get here"); return ptr_; }
68 
69  protected:
70  T* ptr_;
71  };
72 
73  template <typename T>
74  struct make_shared {
75  template<typename... Args>
76  static shared_ptr<T>
77  operator()(Args args...){
78  return shared_ptr<T>(new T(args...));
79  }
80  };
81 
82 
83 
84  template <typename T> using weak_ptr = shared_ptr<T>;
85 
86 }
87 
88 #endif
89 
90 #endif

Generated at Sun Jan 26 2020 23:24:02 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.8.16.