Debian Codegraph @

packages/seacas/libraries/ioss/src/Ioss_TransformFactory.C

raw
1 // Copyright(C) 1999-2021, 2024, 2024 National Technology & Engineering Solutions
2 // of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
3 // NTESS, the U.S. Government retains certain rights in this software.
4 //
5 // See packages/seacas/LICENSE for details
6
7 #include "Ioss_TransformFactory.h"
8 #include "Ioss_Utils.h"
9 #include <map>
10 #include <ostream>
11 #include <string>
12
13 #include "Ioss_CodeTypes.h"
14
15 namespace Ioss {
16 class Transform;
17
18 Ioss::Transform *TransformFactory::create(const std::string &type)
19 {
20 Ioss::Transform *transform = nullptr;
21 auto iter = registry().find(type);
22 if (iter == registry().end()) {
23 if (registry().empty()) {
24 std::ostringstream errmsg;
25 errmsg << "ERROR: No transformations have been registered.\n"
26 << " Was Iotr::Initializer::initialize() called?\n\n";
27 IOSS_ERROR(errmsg);
28 }
29 else {
30 std::ostringstream errmsg;
31 errmsg << "ERROR: The transform named '" << type << "' is not supported.\n";
32 IOSS_ERROR(errmsg);
33 }
34 }
35 else {
36 TransformFactory *factory = (*iter).second;
37 transform = factory->make(type);
38 }
39 return transform;
40 }
41
42 Ioss::NameList TransformFactory::describe()
43 {
44 Ioss::NameList names;
45 describe(&names);
46 return names;
47 }
48
49 int TransformFactory::describe(Ioss::NameList *names)
50 {
51 int count = 0;
52 for (const auto &entry : registry()) {
53 names->push_back(entry.first);
54 count++;
55 }
56 return count;
57 }
58
59 TransformFactory::TransformFactory(const std::string &type)
60 {
61 registry().insert(std::make_pair(type, this));
62 }
63
64 void TransformFactory::alias(const std::string &base, const std::string &syn)
65 {
66 TransformFactory *factory = (*registry().find(base)).second;
67 registry().insert(std::make_pair(syn, factory));
68 }
69
70 TransformFactoryMap &TransformFactory::registry()
71 {
72 static TransformFactoryMap registry_;
73 return registry_;
74 }
75
76 } // namespace Ioss