Mantid
Loading...
Searching...
No Matches
SurfaceFactory.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 +
7#include <algorithm>
8#include <cmath>
9#include <fstream>
10#include <iomanip>
11#include <list>
12#include <map>
13#include <sstream>
14#include <stack>
15#include <utility>
16#include <vector>
17
27#include "MantidKernel/Logger.h"
28#include "MantidKernel/Matrix.h"
30#include "MantidKernel/V3D.h"
31
32namespace Mantid {
33
34namespace {
35Kernel::Logger logger("surfaceFactory");
36}
37
38namespace Geometry {
39
40SurfaceFactory *SurfaceFactory::FOBJ(nullptr);
41
47{
48 if (!FOBJ) {
49 FOBJ = new SurfaceFactory();
50 }
51 return FOBJ;
52}
53
58{
60}
61
62SurfaceFactory::SurfaceFactory(const SurfaceFactory &other) : ID(other.ID) {
63 for (const auto &vc : other.SGrid)
64 this->SGrid.emplace_back(vc.first, vc.second->clone());
65}
66
68 if (this != &other) // protect against invalid self-assignment
69 {
70 this->ID = other.ID;
71 for (const auto &vc : other.SGrid)
72 this->SGrid.emplace_back(vc.first, vc.second->clone());
73 }
74 return *this;
75}
76
81{
82 SGrid.emplace_back("Plane", std::make_unique<Plane>());
83 SGrid.emplace_back("Cylinder", std::make_unique<Cylinder>());
84 SGrid.emplace_back("Cone", std::make_unique<Cone>());
85 // SGrid["Torus"]=new Torus;
86 SGrid.emplace_back("General", std::make_unique<General>());
87 SGrid.emplace_back("Sphere", std::make_unique<Sphere>());
88
89 ID['c'] = "Cylinder";
90 ID['k'] = "Cone";
91 ID['g'] = "General";
92 ID['p'] = "Plane";
93 ID['s'] = "Sphere";
94 // ID['t']="Torus";}
95}
96namespace {
97class KeyEquals {
98public:
99 explicit KeyEquals(std::string key) : m_key(std::move(key)) {}
100 bool operator()(const std::pair<std::string, std::unique_ptr<Surface>> &element) { return m_key == element.first; }
101
102private:
103 std::string m_key;
104};
105} // namespace
106
107std::unique_ptr<Surface> SurfaceFactory::createSurface(const std::string &Key) const
116{
117 MapType::const_iterator vc;
118 vc = std::find_if(SGrid.begin(), SGrid.end(), KeyEquals(Key));
119 if (vc == SGrid.end()) {
120 throw Kernel::Exception::NotFoundError("SurfaceFactory::createSurface", Key);
121 }
122 return vc->second->clone();
123}
124
125std::unique_ptr<Surface> SurfaceFactory::createSurfaceID(const std::string &Key) const
134{
135 std::map<char, std::string>::const_iterator mc;
136
137 mc = (Key.empty()) ? ID.end() : ID.find(static_cast<char>(tolower(Key[0])));
138 if (mc == ID.end()) {
139 throw Kernel::Exception::NotFoundError("SurfaceFactory::createSurfaceID", Key);
140 }
141
142 return createSurface(mc->second);
143}
144
145std::unique_ptr<Surface> SurfaceFactory::processLine(const std::string &Line) const
154{
155 std::string key;
157 throw Kernel::Exception::NotFoundError("SurfaceFactory::processLine", Line);
158
159 std::unique_ptr<Surface> X = createSurfaceID(key);
160 if (X->setSurface(Line)) {
161 logger.error() << "X:: " << X->setSurface(Line) << '\n';
162 throw Kernel::Exception::NotFoundError("SurfaceFactory::processLine", Line);
163 }
164
165 return X;
166}
167
168} // NAMESPACE Geometry
169
170} // NAMESPACE Mantid
std::string m_key
Impliments a line.
Definition: Line.h:43
Creates instances of Surfaces.
std::unique_ptr< Surface > createSurface(const std::string &) const
Creates an instance of tally given a valid key.
std::map< char, std::string > ID
Short letter identifiers.
SurfaceFactory & operator=(const SurfaceFactory &other)
MapType SGrid
The tally stack.
std::unique_ptr< Surface > processLine(const std::string &) const
Creates an instance of a surface given a valid line.
static SurfaceFactory * Instance()
Effective new command / this command.
static SurfaceFactory * FOBJ
Effective "this".
SurfaceFactory()
singleton constructor
std::unique_ptr< Surface > createSurfaceID(const std::string &) const
Creates an instance of tally given a valid key.
void registerSurface()
Register tallies to be used.
Exception for when an item is not found in a collection.
Definition: Exception.h:145
int convert(const std::string &A, T &out)
Convert a string into a number.
Definition: Strings.cpp:665
Helper class which provides the Collimation Length for SANS instruments.
STL namespace.