| 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 <memory> |
| 14 |
|
| 15 |
#include "atlas/trans/Trans.h" |
| 16 |
#include "atlas/util/Config.h" |
| 17 |
#include "atlas/util/Object.h" |
| 18 |
#include "atlas/util/ObjectHandle.h" |
| 19 |
|
| 20 |
//----------------------------------------------------------------------------- |
| 21 |
// Forward declarations |
| 22 |
|
| 23 |
namespace atlas { |
| 24 |
class Grid; |
| 25 |
} // namespace atlas |
| 26 |
|
| 27 |
//----------------------------------------------------------------------------- |
| 28 |
|
| 29 |
namespace atlas { |
| 30 |
namespace trans { |
| 31 |
|
| 32 |
//----------------------------------------------------------------------------- |
| 33 |
|
| 34 |
class LegendreCacheCreatorImpl : public util::Object { |
| 35 |
public: |
| 36 |
virtual ~LegendreCacheCreatorImpl() = 0; |
| 37 |
|
| 38 |
virtual bool supported() const = 0; |
| 39 |
|
| 40 |
virtual std::string uid() const = 0; |
| 41 |
|
| 42 |
virtual void create(const std::string& path) const = 0; |
| 43 |
|
| 44 |
virtual Cache create() const = 0; |
| 45 |
|
| 46 |
virtual size_t estimate() const = 0; |
| 47 |
}; |
| 48 |
|
| 49 |
// ------------------------------------------------------------------ |
| 50 |
|
| 51 |
class LegendreCacheCreator : DOXYGEN_HIDE(public util::ObjectHandle<LegendreCacheCreatorImpl>) { |
| 52 |
public: |
| 53 |
using Handle::Handle; |
| 54 |
LegendreCacheCreator() = default; |
| 55 |
LegendreCacheCreator(const Grid&, int truncation, const eckit::Configuration& = util::NoConfig()); |
| 56 |
|
| 57 |
bool supported() const; |
| 58 |
|
| 59 |
std::string uid() const; |
| 60 |
|
| 61 |
void create(const std::string& path) const; |
| 62 |
|
| 63 |
Cache create() const; |
| 64 |
|
| 65 |
size_t estimate() const; |
| 66 |
}; |
| 67 |
|
| 68 |
//---------------------------------------------------------------------------------------------------------------------- |
| 69 |
|
| 70 |
class LegendreCacheCreatorFactory { |
| 71 |
public: |
| 72 |
/*! |
| 73 |
* \brief build Trans |
| 74 |
* \return TransImpl |
| 75 |
*/ |
| 76 |
static LegendreCacheCreatorImpl* build(const Grid&, int truncation, const eckit::Configuration& = util::Config()); |
| 77 |
|
| 78 |
/*! |
| 79 |
* \brief list all registered trans implementations |
| 80 |
*/ |
| 81 |
static void list(std::ostream&); |
| 82 |
|
| 83 |
static bool has(const std::string& name); |
| 84 |
|
| 85 |
private: |
| 86 |
std::string name_; |
| 87 |
virtual LegendreCacheCreatorImpl* make(const Grid& /*gp*/, int truncation, const eckit::Configuration&) { |
| 88 |
return nullptr; |
| 89 |
} |
| 90 |
|
| 91 |
protected: |
| 92 |
LegendreCacheCreatorFactory(const std::string&); |
| 93 |
virtual ~LegendreCacheCreatorFactory(); |
| 94 |
}; |
| 95 |
|
| 96 |
//---------------------------------------------------------------------------------------------------------------------- |
| 97 |
|
| 98 |
template <class T> |
| 99 |
class LegendreCacheCreatorBuilder : public LegendreCacheCreatorFactory { |
| 100 |
virtual LegendreCacheCreatorImpl* make(const Grid& grid, int truncation, const eckit::Configuration& config) { |
| 101 |
return new T(grid, truncation, config); |
| 102 |
} |
| 103 |
|
| 104 |
public: |
| 105 |
LegendreCacheCreatorBuilder(const std::string& name): LegendreCacheCreatorFactory(name) {} |
| 106 |
}; |
| 107 |
|
| 108 |
//---------------------------------------------------------------------------------------------------------------------- |
| 109 |
|
| 110 |
} // namespace trans |
| 111 |
} // namespace atlas |