| 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 |
#include "atlas/field/MultiField.h" |
| 12 |
|
| 13 |
#include <iomanip> |
| 14 |
#include <map> |
| 15 |
#include <memory> |
| 16 |
#include <sstream> |
| 17 |
#include <string> |
| 18 |
#include <mutex> |
| 19 |
|
| 20 |
#include "atlas/field/MultiFieldCreator.h" |
| 21 |
#include "atlas/field/detail/MultiFieldImpl.h" |
| 22 |
#include "atlas/runtime/Exception.h" |
| 23 |
|
| 24 |
namespace atlas { |
| 25 |
namespace field { |
| 26 |
|
| 27 |
//----------------------------------------------------------------------------- |
| 28 |
|
| 29 |
MultiField::MultiField(const eckit::Configuration& config) { |
| 30 |
std::string type; |
| 31 |
if (!config.get("type", type)) { |
| 32 |
ATLAS_THROW_EXCEPTION("Could not find \"type\" in configuration"); |
| 33 |
} |
| 34 |
std::unique_ptr<MultiFieldCreator> creator(MultiFieldCreatorFactory::build(type, config)); |
| 35 |
reset(creator->create(config)); |
| 36 |
} |
| 37 |
|
| 38 |
MultiField::MultiField(const array::DataType datatype, const array::ArrayShape& shape, |
| 39 |
const std::vector<std::string>& var_names) { |
| 40 |
std::unique_ptr<MultiFieldCreator> creator(MultiFieldCreatorFactory::build("MultiFieldCreatorArray")); |
| 41 |
reset(creator->create(datatype, shape, var_names)); |
| 42 |
} |
| 43 |
|
| 44 |
const Field& MultiField::field(const std::string& name) const { return get()->field(name); } |
| 45 |
Field& MultiField::field(const std::string& name) { return get()->field(name); } |
| 46 |
bool MultiField::has(const std::string& name) const { return get()->has(name); } |
| 47 |
std::vector<std::string> MultiField::field_names() const { return get()->field_names(); } |
| 48 |
|
| 49 |
const Field& MultiField::field(const idx_t idx) const { return get()->field(idx); } |
| 50 |
Field& MultiField::field(const idx_t idx) { return get()->field(idx); } |
| 51 |
idx_t MultiField::size() const { return get()->size(); } |
| 52 |
|
| 53 |
const Field& MultiField::operator[](const idx_t idx) const { return get()->field(idx); } |
| 54 |
Field& MultiField::operator[](const idx_t idx) { return get()->field(idx); } |
| 55 |
|
| 56 |
const Field& MultiField::operator[](const std::string& name) const { return get()->field(name); } |
| 57 |
Field& MultiField::operator[](const std::string& name) { return get()->field(name); } |
| 58 |
|
| 59 |
const util::Metadata& MultiField::metadata() const { return get()->metadata(); } |
| 60 |
util::Metadata& MultiField::metadata() { return get()->metadata(); } |
| 61 |
|
| 62 |
MultiField::operator const array::Array&() const { return get()->array(); } |
| 63 |
MultiField::operator array::Array&() { return get()->array(); } |
| 64 |
|
| 65 |
MultiField::operator const FieldSet&() const { return get()->fieldset_; } |
| 66 |
MultiField::operator FieldSet&() { return get()->fieldset_; } |
| 67 |
|
| 68 |
const array::Array& MultiField::array() const { return get()->array(); } |
| 69 |
array::Array& MultiField::array() { return get()->array(); } |
| 70 |
|
| 71 |
//----------------------------------------------------------------------------- |
| 72 |
|
| 73 |
} // namespace field |
| 74 |
} // namespace atlas |