Debian Codegraph @

src/atlas/trans/detail/TransFactory.h

raw
1 /*
2 * (C) Copyright 2013 ECMWF.
3 *
4 * This software is licensed under the terms of the Apache Licence Version 2.0
5 * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6 * In applying this licence, ECMWF does not waive the privileges and immunities
7 * granted to it by virtue of its status as an intergovernmental organisation
8 * nor does it submit to any jurisdiction.
9 */
10
11 #pragma once
12
13 #include <string>
14
15 #include "atlas/runtime/Exception.h"
16 #include "atlas/util/Config.h"
17 #include "atlas/util/Factory.h"
18
19 //----------------------------------------------------------------------------------------------------------------------
20
21 // forward declarations
22 namespace atlas {
23 class Grid;
24 class FunctionSpace;
25 class Domain;
26 namespace trans {
27 class TransImpl;
28 class Cache;
29 } // namespace trans
30 } // namespace atlas
31
32 //----------------------------------------------------------------------------------------------------------------------
33
34 namespace atlas {
35 namespace trans {
36
37 //----------------------------------------------------------------------------------------------------------------------
38
39 class TransFactory : public util::Factory<TransFactory> {
40 public:
41 static std::string className() { return "TransFactory"; }
42
43 public:
44 /*!
45 * \brief build Trans
46 * \return TransImpl
47 */
48 static const TransImpl* build(const FunctionSpace& gp, const FunctionSpace& sp,
49 const eckit::Configuration& = util::Config());
50 static const TransImpl* build(const Grid&, int truncation, const eckit::Configuration& = util::Config());
51
52 static const TransImpl* build(const Grid&, const Domain&, int truncation,
53 const eckit::Configuration& = util::Config());
54
55 static const TransImpl* build(const Cache&, const FunctionSpace& gp, const FunctionSpace& sp,
56 const eckit::Configuration& = util::Config());
57
58 static const TransImpl* build(const Cache&, const Grid&, int truncation,
59 const eckit::Configuration& = util::Config());
60
61 static const TransImpl* build(const Cache&, const Grid&, const Domain&, int truncation,
62 const eckit::Configuration& = util::Config());
63
64 static void list(std::ostream& out);
65
66 static bool has(const std::string& backend);
67
68 static void backend(const std::string&);
69
70 static std::string backend();
71
72 static const eckit::Configuration& config();
73
74 static void config(const eckit::Configuration&);
75
76 public:
77 TransFactory(const std::string& name, const std::string& backend);
78 virtual ~TransFactory();
79
80 TransFactory() {}
81
82 private:
83 std::string name_;
84 std::string backend_;
85
86 virtual const TransImpl* make(const Cache&, const FunctionSpace& /*gp*/, const FunctionSpace& /*sp*/,
87 const eckit::Configuration&) {
88 return nullptr;
89 }
90 virtual const TransImpl* make(const Cache&, const Grid& /*gp*/, const Domain&, int /*truncation*/,
91 const eckit::Configuration&) {
92 return nullptr;
93 }
94 };
95
96 //----------------------------------------------------------------------------------------------------------------------
97
98 template <class T>
99 class TransBuilderFunctionSpace : public TransFactory {
100 virtual const TransImpl* make(const Cache& cache, const FunctionSpace& gp, const FunctionSpace& sp,
101 const eckit::Configuration& config) override {
102 return new T(cache, gp, sp, config);
103 }
104 virtual const TransImpl* make(const Cache&, const Grid&, const Domain&, int, const eckit::Configuration&) override {
105 throw_Exception("This function should not be called", Here());
106 }
107
108 public:
109 TransBuilderFunctionSpace(const std::string& name, const std::string& backend): TransFactory(name, backend) {}
110
111 TransBuilderFunctionSpace() {}
112 };
113
114 template <class T>
115 class TransBuilderGrid : public TransFactory {
116 virtual const TransImpl* make(const Cache& cache, const Grid& grid, const Domain& domain, int truncation,
117 const eckit::Configuration& config) override {
118 return new T(cache, grid, domain, truncation, config);
119 }
120 virtual const TransImpl* make(const Cache&, const FunctionSpace&, const FunctionSpace&,
121 const eckit::Configuration&) override {
122 throw_Exception("This function should not be called", Here());
123 }
124
125 public:
126 TransBuilderGrid(const std::string& name, const std::string& backend): TransFactory(name, backend) {}
127
128 TransBuilderGrid() {}
129 };
130
131 //----------------------------------------------------------------------------------------------------------------------
132
133
134 } // namespace trans
135 } // namespace atlas