Mantid
Loading...
Searching...
No Matches
Framework
PythonInterface
core
inc
MantidPythonInterface
core
WeakPtr.h
Go to the documentation of this file.
1
// Mantid Repository : https://github.com/mantidproject/mantid
2
//
3
// Copyright © 2012 ISIS Rutherford Appleton Laboratory UKRI,
4
// NScD Oak Ridge National Laboratory, European Spallation Source,
5
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6
// SPDX - License - Identifier: GPL - 3.0 +
7
#pragma once
8
/*
9
10
This file declares the get_pointer template function to allow
11
boost python to understand weak_pointers. It must be add to the
12
boost namespace
13
*/
14
#include <memory>
15
#include <stdexcept>
16
17
namespace
std
{
29
template
<
typename
HeldType>
inline
HeldType *
get_pointer
(
const
std::weak_ptr<HeldType> &dataItem) {
30
if
(std::shared_ptr<HeldType> lockedItem = dataItem.lock()) {
31
return
lockedItem.get();
// Safe as we can guarantee that another reference exists
32
}
else
{
33
throw
std::runtime_error(
"Variable invalidated, data has been deleted."
);
34
}
35
}
36
}
// namespace std
std
STL namespace.
std::get_pointer
HeldType * get_pointer(const std::weak_ptr< HeldType > &dataItem)
Boost.Python doesn't understand weak_ptrs out of the box.
Definition
WeakPtr.h:29
Generated by
1.9.8