Mantid
Loading...
Searching...
No Matches
SymmetryOperationFactory.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 +
10
11#include <algorithm>
12#include <boost/algorithm/string.hpp>
13#include <memory>
14
15namespace Mantid::Geometry {
16
19 if (!isSubscribed(identifier)) {
20 subscribeSymOp(identifier);
21 }
22
23 return SymmetryOperation(m_prototypes[identifier]);
24}
25
27std::vector<SymmetryOperation> SymmetryOperationFactoryImpl::createSymOps(const std::string &identifiers) {
28 std::vector<std::string> symOpStrings;
29 boost::split(symOpStrings, identifiers, boost::is_any_of(";"));
30
31 return createSymOps(symOpStrings);
32}
33
36std::vector<SymmetryOperation> SymmetryOperationFactoryImpl::createSymOps(const std::vector<std::string> &identifiers) {
37 std::vector<SymmetryOperation> symOps;
38 symOps.reserve(identifiers.size());
39 std::transform(identifiers.cbegin(), identifiers.cend(), std::back_inserter(symOps),
40 [this](const auto &identifier) { return createSymOp(boost::trim_copy(identifier)); });
41 return symOps;
42}
43
45void SymmetryOperationFactoryImpl::subscribeSymOp(const std::string &identifier) {
46 SymmetryOperation prototype(identifier);
47
48 subscribe(identifier, prototype);
49}
50
52void SymmetryOperationFactoryImpl::unsubscribeSymOp(const std::string &identifier) {
53 if (isSubscribed(identifier)) {
54 m_prototypes.erase(identifier);
55 }
56}
57
59bool SymmetryOperationFactoryImpl::isSubscribed(const std::string &identifier) const {
60 return m_prototypes.find(identifier) != m_prototypes.end();
61}
62
64std::vector<std::string> SymmetryOperationFactoryImpl::subscribedSymbols() const {
65 std::vector<std::string> symbols;
66 symbols.reserve(m_prototypes.size());
67 std::transform(m_prototypes.cbegin(), m_prototypes.cend(), std::back_inserter(symbols),
68 [](const auto &prototype) { return prototype.first; });
69 return symbols;
70}
71
73void SymmetryOperationFactoryImpl::subscribe(const std::string &alias, const SymmetryOperation &prototype) {
74 if (!isSubscribed(alias)) {
75 m_prototypes.emplace(alias, prototype);
76 }
77}
78
81
82} // namespace Mantid::Geometry
void unsubscribeSymOp(const std::string &identifier)
Unsubscribes a symmetry operation from the factory.
bool isSubscribed(const std::string &identifier) const
Returns true if identifier already has a prototype in the factory.
std::map< std::string, SymmetryOperation > m_prototypes
std::vector< std::string > subscribedSymbols() const
Returns all symbols in the factory.
void subscribeSymOp(const std::string &identifier)
Subscribes a symmetry operation into the factory.
void subscribe(const std::string &alias, const SymmetryOperation &prototype)
Subscribes symmetry operation into factory, using the supplied alias as key.
SymmetryOperation createSymOp(const std::string &identifier)
Creates a SymmetryOperation object from its identifier.
std::vector< SymmetryOperation > createSymOps(const std::string &identifiers)
Creates all symmetry operations in string (separated by semicolon).
Crystallographic symmetry operations are composed of a rotational component, which is represented by ...
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...