| 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 |
/// @author Willem Deconinck |
| 12 |
/// @date June 2015 |
| 13 |
|
| 14 |
#pragma once |
| 15 |
|
| 16 |
#include <map> |
| 17 |
#include <vector> |
| 18 |
|
| 19 |
#include "atlas/array/Array.h" |
| 20 |
#include "atlas/field/Field.h" |
| 21 |
#include "atlas/field/FieldSet.h" |
| 22 |
#include "atlas/util/Config.h" |
| 23 |
#include "atlas/util/Metadata.h" |
| 24 |
#include "atlas/util/Object.h" |
| 25 |
|
| 26 |
namespace atlas { |
| 27 |
namespace field { |
| 28 |
|
| 29 |
class MultiFieldImpl : public util::Object { |
| 30 |
public: // methods |
| 31 |
//-- Constructors |
| 32 |
|
| 33 |
MultiFieldImpl() {} |
| 34 |
|
| 35 |
MultiFieldImpl(const array::ArraySpec& spec) { |
| 36 |
array::ArraySpec s(spec); |
| 37 |
array_.reset(array::Array::create(std::move(s))); |
| 38 |
} |
| 39 |
|
| 40 |
virtual ~MultiFieldImpl() {} |
| 41 |
|
| 42 |
|
| 43 |
//-- Accessors |
| 44 |
|
| 45 |
const Field& field(const std::string& name) const { return fieldset_.field(name); } |
| 46 |
Field& field(const std::string& name) { return fieldset_.field(name); } |
| 47 |
bool has(const std::string& name) const { return fieldset_.has(name); } |
| 48 |
std::vector<std::string> field_names() const { return fieldset_.field_names(); } |
| 49 |
|
| 50 |
const Field& field(const idx_t idx) const { return fieldset_[idx]; } |
| 51 |
Field& field(const idx_t idx) { return fieldset_[idx]; } |
| 52 |
idx_t size() const { return fieldset_.size(); } |
| 53 |
|
| 54 |
const Field& operator[](const idx_t idx) const { return fieldset_[idx]; } |
| 55 |
Field& operator[](const idx_t idx) { return fieldset_[idx]; } |
| 56 |
|
| 57 |
const Field& operator[](const std::string& name) const { return fieldset_.field(name); } |
| 58 |
Field& operator[](const std::string& name) { return fieldset_.field(name); } |
| 59 |
|
| 60 |
const util::Metadata& metadata() const { return metadata_; } |
| 61 |
util::Metadata& metadata() { return metadata_; } |
| 62 |
|
| 63 |
// -- Modifiers |
| 64 |
|
| 65 |
/// @brief Implicit conversion to Array |
| 66 |
operator const array::Array&() const { return array(); } |
| 67 |
operator array::Array&() { return array(); } |
| 68 |
|
| 69 |
operator const FieldSet&() const { return fieldset_; } |
| 70 |
|
| 71 |
operator FieldSet&() { return fieldset_; } |
| 72 |
|
| 73 |
/// @brief Access contained Array |
| 74 |
const array::Array& array() const { |
| 75 |
ATLAS_ASSERT(array_); |
| 76 |
return *array_; |
| 77 |
} |
| 78 |
array::Array& array() { |
| 79 |
ATLAS_ASSERT(array_); |
| 80 |
return *array_; |
| 81 |
} |
| 82 |
|
| 83 |
/// @brief Access contained FieldSet |
| 84 |
const FieldSet& fieldset() const { return fieldset_; } |
| 85 |
FieldSet& fieldset() { return fieldset_; } |
| 86 |
|
| 87 |
void add(Field& field); |
| 88 |
|
| 89 |
public: // temporary public for prototyping |
| 90 |
FieldSet fieldset_; |
| 91 |
std::shared_ptr<array::Array> array_; |
| 92 |
util::Metadata metadata_; |
| 93 |
}; |
| 94 |
|
| 95 |
} // namespace field |
| 96 |
} // namespace atlas |