| 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 |
#ifndef atlas_field_MultiFieldCreator_h |
| 12 |
#define atlas_field_MultiFieldCreator_h |
| 13 |
|
| 14 |
#include <string> |
| 15 |
|
| 16 |
#include "atlas/util/Object.h" |
| 17 |
|
| 18 |
#include "atlas/field/MultiField.h" |
| 19 |
|
| 20 |
namespace eckit { |
| 21 |
class Configuration; |
| 22 |
} |
| 23 |
|
| 24 |
//------------------------------------------------------------------------------------------------------ |
| 25 |
|
| 26 |
namespace atlas { |
| 27 |
namespace field { |
| 28 |
|
| 29 |
//------------------------------------------------------------------------------------------------------ |
| 30 |
|
| 31 |
/*! |
| 32 |
* \brief Base class for creating new multifields based on Configuration |
| 33 |
* |
| 34 |
* \details |
| 35 |
* Example to create field[100][3] of default type double: |
| 36 |
* \code{.cpp} |
| 37 |
* FieldImpl* field = Field::create( |
| 38 |
* Config |
| 39 |
* ("creator","ArraySpec") // ArraySpec MultiFieldCreator |
| 40 |
* ("shape",array::make_shape(100,3)) // Rank 2 field with indexing [100][3] |
| 41 |
* ); |
| 42 |
* \endcode |
| 43 |
*/ |
| 44 |
class MultiFieldCreator : public util::Object { |
| 45 |
public: |
| 46 |
MultiFieldCreator(); |
| 47 |
MultiFieldCreator(const eckit::Configuration& config); |
| 48 |
|
| 49 |
virtual ~MultiFieldCreator(); |
| 50 |
|
| 51 |
virtual MultiFieldImpl* create(const eckit::Configuration& config = util::Config()) const = 0; |
| 52 |
virtual MultiFieldImpl* create(const array::DataType datatype, const array::ArrayShape& shape, |
| 53 |
const std::vector<std::string>& var_names) const = 0; |
| 54 |
}; |
| 55 |
|
| 56 |
//------------------------------------------------------------------------------------------------------ |
| 57 |
|
| 58 |
class MultiFieldCreatorFactory : public util::Factory<MultiFieldCreatorFactory> { |
| 59 |
public: |
| 60 |
static std::string className() { return "MultiFieldCreatorFactory"; } |
| 61 |
|
| 62 |
/*! |
| 63 |
* \brief build MultiFieldCreator with options specified in parametrisation |
| 64 |
* \return mesh generator |
| 65 |
*/ |
| 66 |
static MultiFieldCreator* build(const std::string&, const eckit::Configuration& = util::Config()); |
| 67 |
|
| 68 |
using Factory::Factory; |
| 69 |
|
| 70 |
private: |
| 71 |
virtual MultiFieldCreator* make() = 0; |
| 72 |
virtual MultiFieldCreator* make(const eckit::Configuration&) = 0; |
| 73 |
}; |
| 74 |
|
| 75 |
template <class T> |
| 76 |
class MultiFieldCreatorBuilder : public MultiFieldCreatorFactory { |
| 77 |
virtual MultiFieldCreator* make() { return new T(); } |
| 78 |
virtual MultiFieldCreator* make(const eckit::Configuration& config) { return new T(config); } |
| 79 |
|
| 80 |
public: |
| 81 |
using MultiFieldCreatorFactory::MultiFieldCreatorFactory; |
| 82 |
}; |
| 83 |
|
| 84 |
//------------------------------------------------------------------------------------------------------ |
| 85 |
|
| 86 |
} // namespace field |
| 87 |
} // namespace atlas |
| 88 |
|
| 89 |
#endif |