Mantid
Loading...
Searching...
No Matches
HKLFilter.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 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 +
8#include <memory>
9#include <stdexcept>
10#include <utility>
11
12namespace Mantid::Geometry {
13
24std::function<bool(const Kernel::V3D &)> HKLFilter::fn() const noexcept {
25 return std::bind(&HKLFilter::isAllowed, this, std::placeholders::_1);
26}
27
30 if (!m_operand) {
31 throw std::runtime_error("Cannot create HKLFilterUnaryLogicOperation from null operand.");
32 }
33}
34
36std::string HKLFilterNot::getDescription() const noexcept { return "!" + m_operand->getDescription(); }
37
39bool HKLFilterNot::isAllowed(const Kernel::V3D &hkl) const noexcept { return !(m_operand->isAllowed(hkl)); }
40
44 : m_lhs(std::move(lhs)), m_rhs(std::move(rhs)) {
45 if (!m_lhs || !m_rhs) {
46 throw std::runtime_error("Cannot construct HKLFilterBinaryLogicOperation "
47 "with one or more null-operands.");
48 }
49}
50
52std::string HKLFilterAnd::getDescription() const noexcept {
53 return "(" + m_lhs->getDescription() + " & " + m_rhs->getDescription() + ")";
54}
55
57bool HKLFilterAnd::isAllowed(const Kernel::V3D &hkl) const noexcept {
58 return m_lhs->isAllowed(hkl) && m_rhs->isAllowed(hkl);
59}
60
62std::string HKLFilterOr::getDescription() const noexcept {
63 return "(" + m_lhs->getDescription() + " | " + m_rhs->getDescription() + ")";
64}
65
67bool HKLFilterOr::isAllowed(const Kernel::V3D &hkl) const noexcept {
68 return m_lhs->isAllowed(hkl) || m_rhs->isAllowed(hkl);
69}
70
81 return std::make_shared<const HKLFilterNot>(filter);
82}
83
95 return std::make_shared<const HKLFilterAnd>(lhs, rhs);
96}
97
109 return std::make_shared<HKLFilterOr>(lhs, rhs);
110}
111
112} // namespace Mantid::Geometry
const std::vector< double > & rhs
std::string getDescription() const noexcept override
Returns a description of the HKLFilterAnd.
Definition: HKLFilter.cpp:52
bool isAllowed(const Kernel::V3D &hkl) const noexcept override
Returns true if both wrapped filters return true.
Definition: HKLFilter.cpp:57
HKLFilterBinaryLogicOperation(HKLFilter_const_sptr lhs, HKLFilter_const_sptr rhs)
Stores the left-hand and right-hand side operators, throws exception if either is null.
Definition: HKLFilter.cpp:43
std::string getDescription() const noexcept override
Returns a description of the HKLFilterNot.
Definition: HKLFilter.cpp:36
bool isAllowed(const Kernel::V3D &hkl) const noexcept override
Returns true if the wrapped filter returns false and false otherwise.
Definition: HKLFilter.cpp:39
bool isAllowed(const Kernel::V3D &hkl) const noexcept override
Returns true if either of the wrapped filters returns true.
Definition: HKLFilter.cpp:67
std::string getDescription() const noexcept override
Returns a description of the HKLFilterOr.
Definition: HKLFilter.cpp:62
HKLFilterUnaryLogicOperation(HKLFilter_const_sptr filter)
Stores the supplied filter, throws exception if filter is null.
Definition: HKLFilter.cpp:29
std::function< bool(const Kernel::V3D &)> fn() const noexcept
Returns a function object that wraps HKLFilter::isAllowed.
Definition: HKLFilter.cpp:24
virtual bool isAllowed(const Kernel::V3D &hkl) const =0
Class for 3D vectors.
Definition: V3D.h:34
MANTID_GEOMETRY_DLL const HKLFilter_const_sptr operator&(const HKLFilter_const_sptr &lhs, const HKLFilter_const_sptr &rhs)
Constructs an HKLFilterAnd from the operands.
Definition: HKLFilter.cpp:94
std::shared_ptr< const HKLFilter > HKLFilter_const_sptr
Definition: HKLFilter.h:76
MANTID_GEOMETRY_DLL const HKLFilter_const_sptr operator|(const HKLFilter_const_sptr &lhs, const HKLFilter_const_sptr &rhs)
Constructs an HKLFilterOr from the operands.
Definition: HKLFilter.cpp:108
MANTID_GEOMETRY_DLL const HKLFilter_const_sptr operator~(const HKLFilter_const_sptr &filter)
Constructs an HKLFilterNot from the operand.
Definition: HKLFilter.cpp:80
STL namespace.