Mantid
Loading...
Searching...
No Matches
ReflectionCondition.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 <algorithm>
9#include <functional>
10#include <iterator>
11#include <memory>
12#include <stdexcept>
13
14namespace Mantid::Geometry {
15
16// General template definition for RegisterConditions
17template <typename... Args> struct RegisterConditions;
18
19// Specialisation for recursive case
20template <typename R, typename... Args> struct RegisterConditions<R, Args...> {
21 static void run(ReflectionConditions &container) {
22 container.emplace_back(std::make_shared<R>());
24 }
25};
26
27// Specialisation to end recursion
28template <> struct RegisterConditions<> {
29 static void run(ReflectionConditions &) {}
30};
31
34 static ReflectionConditions conditions;
35 if (conditions.empty()) {
41 }
42 return conditions;
43}
44
46std::vector<std::string>
47transformReflectionConditions(const std::function<std::string(const ReflectionCondition_sptr &)> &fn) {
48 const auto &conditions = getAllReflectionConditions();
49
50 std::vector<std::string> names;
51 names.reserve(conditions.size());
52 std::transform(conditions.cbegin(), conditions.cend(), std::back_inserter(names), fn);
53
54 return names;
55}
56
58std::vector<std::string> getAllReflectionConditionNames() {
59 return transformReflectionConditions([](const ReflectionCondition_sptr &condition) { return condition->getName(); });
60}
61
63std::vector<std::string> getAllReflectionConditionSymbols() {
65 [](const ReflectionCondition_sptr &condition) { return condition->getSymbol(); });
66}
67
82 const std::string &hint) {
83 const auto &conditions = getAllReflectionConditions();
84
85 auto it = std::find_if(conditions.cbegin(), conditions.cend(), fn);
86
87 if (it == conditions.cend()) {
88 throw std::invalid_argument("No ReflectionCondition found that matches '" + hint + "'.");
89 }
90
91 return *it;
92}
93
98 [=](const ReflectionCondition_sptr &condition) { return condition->getName() == name; }, name);
99}
100
105 [=](const ReflectionCondition_sptr &condition) { return condition->getSymbol() == symbol; }, symbol);
106}
107
108} // namespace Mantid::Geometry
Hexagonally centred, reverse ReflectionCondition.
Rhombohedrally centred, obverse ReflectionCondition.
Rhombohedrally centred, reverse ReflectionCondition.
std::shared_ptr< ReflectionCondition > ReflectionCondition_sptr
Shared pointer to a ReflectionCondition.
MANTID_GEOMETRY_DLL ReflectionCondition_sptr getReflectionConditionBySymbol(const std::string &symbol)
Returns the ReflectionCondition for the specified centering symbol, see getAllReflectionConditionSymb...
std::vector< ReflectionCondition_sptr > ReflectionConditions
A collection of reflections.
ReflectionCondition_sptr getReflectionConditionWhere(const std::function< bool(const ReflectionCondition_sptr &)> &fn, const std::string &hint)
Returns a reflection condition according to a filter function.
std::vector< std::string > transformReflectionConditions(const std::function< std::string(const ReflectionCondition_sptr &)> &fn)
Helper function that transforms all ReflectionConditions to strings.
MANTID_GEOMETRY_DLL const ReflectionConditions & getAllReflectionConditions()
MANTID_GEOMETRY_DLL ReflectionCondition_sptr getReflectionConditionByName(const std::string &name)
Returns the requested ReflectionCondition, see getAllReflectionConditionNames for possible names.
MANTID_GEOMETRY_DLL std::vector< std::string > getAllReflectionConditionSymbols()
Returns all centering symbols.
MANTID_GEOMETRY_DLL std::vector< std::string > getAllReflectionConditionNames()
Returns all ReflectionCondition names.
static void run(ReflectionConditions &container)
static void run(ReflectionConditions &)