Mantid
Loading...
Searching...
No Matches
Framework
Kernel
inc
MantidKernel
DynamicPointerCastHelper.h
Go to the documentation of this file.
1
// Mantid Repository : https://github.com/mantidproject/mantid
2
//
3
// Copyright © 2024 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
#include <memory>
10
#include <string>
11
12
namespace
Mantid
{
13
namespace
Kernel {
14
namespace
DynamicPointerCastHelper {
15
16
/*
17
Will cast a shared_ptr of type U to one of type T using std::dynamic_pointer_cast. If the cast
18
is invalid then it will throw an exception. This is useful for avoiding warnings about
19
potential null objects coming out of std::dynamic_pointer_cast.
20
*/
21
template
<
typename
T,
typename
U>
22
std::shared_ptr<T>
dynamicPointerCastWithCheck
(std::shared_ptr<U> sharedPtr,
const
std::string &
error
=
""
) {
23
auto
result = std::dynamic_pointer_cast<T>(sharedPtr);
24
if
(result ==
nullptr
) {
25
throw
std::invalid_argument(
error
.empty() ?
"Invalid cast"
:
error
);
26
}
27
return
result;
28
}
29
30
}
// namespace DynamicPointerCastHelper
31
}
// namespace Kernel
32
}
// namespace Mantid
error
double error
Definition
IndexPeaks.cpp:136
Mantid::Kernel::DynamicPointerCastHelper::dynamicPointerCastWithCheck
std::shared_ptr< T > dynamicPointerCastWithCheck(std::shared_ptr< U > sharedPtr, const std::string &error="")
Definition
DynamicPointerCastHelper.h:22
Mantid
Helper class which provides the Collimation Length for SANS instruments.
Definition
AbsorptionCorrection.h:18
Generated by
1.9.8