| 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 "eckit/config/LocalConfiguration.h" |
| 16 |
#include "eckit/config/Parametrisation.h" |
| 17 |
|
| 18 |
#include "atlas/library/config.h" |
| 19 |
|
| 20 |
namespace atlas { |
| 21 |
namespace util { |
| 22 |
|
| 23 |
class Metadata : public eckit::LocalConfiguration { |
| 24 |
public: |
| 25 |
Metadata(): eckit::LocalConfiguration() {} |
| 26 |
|
| 27 |
Metadata(const eckit::LocalConfiguration& p): eckit::LocalConfiguration(p) {} |
| 28 |
//Metadata(const Metadata& p): eckit::LocalConfiguration(p) {} |
| 29 |
|
| 30 |
using eckit::LocalConfiguration::set; |
| 31 |
|
| 32 |
template <typename ValueT> |
| 33 |
Metadata& set(const std::string& name, const ValueT& value) { |
| 34 |
eckit::LocalConfiguration::set(name, value); |
| 35 |
return *this; |
| 36 |
} |
| 37 |
|
| 38 |
Metadata& set(const eckit::Configuration&); |
| 39 |
|
| 40 |
using eckit::LocalConfiguration::get; |
| 41 |
|
| 42 |
template <typename ValueT> |
| 43 |
ValueT get(const std::string& name) const { |
| 44 |
ValueT value; |
| 45 |
if (not eckit::LocalConfiguration::get(name, value)) |
| 46 |
throw_not_found(name); |
| 47 |
return value; |
| 48 |
} |
| 49 |
|
| 50 |
friend std::ostream& operator<<(std::ostream& s, const Metadata& v) { |
| 51 |
v.print(s); |
| 52 |
return s; |
| 53 |
} |
| 54 |
|
| 55 |
void broadcast(); |
| 56 |
void broadcast(idx_t root); |
| 57 |
void broadcast(Metadata&); |
| 58 |
void broadcast(Metadata&, idx_t root); |
| 59 |
void broadcast(Metadata&) const; |
| 60 |
void broadcast(Metadata&, idx_t root) const; |
| 61 |
|
| 62 |
size_t footprint() const; |
| 63 |
|
| 64 |
private: |
| 65 |
[[noreturn]] void throw_not_found(const std::string&) const; |
| 66 |
|
| 67 |
Metadata(const eckit::Value&); |
| 68 |
}; |
| 69 |
|
| 70 |
// ------------------------------------------------------------------ |
| 71 |
// C wrapper interfaces to C++ routines |
| 72 |
|
| 73 |
extern "C" { |
| 74 |
Metadata* atlas__Metadata__new(); |
| 75 |
|
| 76 |
void atlas__Metadata__delete(Metadata* This); |
| 77 |
void atlas__Metadata__print(Metadata* This, std::ostream* channel); |
| 78 |
void atlas__Metadata__json(Metadata* This, char*& json, int& size, int& allocated); |
| 79 |
int atlas__Metadata__has(Metadata* This, const char* name); |
| 80 |
void atlas__Metadata__set_int(Metadata* This, const char* name, int value); |
| 81 |
void atlas__Metadata__set_long(Metadata* This, const char* name, long value); |
| 82 |
void atlas__Metadata__set_float(Metadata* This, const char* name, float value); |
| 83 |
void atlas__Metadata__set_double(Metadata* This, const char* name, double value); |
| 84 |
void atlas__Metadata__set_string(Metadata* This, const char* name, const char* value); |
| 85 |
void atlas__Metadata__set_array_int(Metadata* This, const char* name, int value[], int size); |
| 86 |
void atlas__Metadata__set_array_long(Metadata* This, const char* name, long value[], int size); |
| 87 |
void atlas__Metadata__set_array_float(Metadata* This, const char* name, float value[], int size); |
| 88 |
void atlas__Metadata__set_array_double(Metadata* This, const char* name, double value[], int size); |
| 89 |
|
| 90 |
int atlas__Metadata__get_int(Metadata* This, const char* name); |
| 91 |
long atlas__Metadata__get_long(Metadata* This, const char* name); |
| 92 |
float atlas__Metadata__get_float(Metadata* This, const char* name); |
| 93 |
double atlas__Metadata__get_double(Metadata* This, const char* name); |
| 94 |
void atlas__Metadata__get_string(Metadata* This, const char* name, char* output_str, int max_len); |
| 95 |
void atlas__Metadata__get_array_int(Metadata* This, const char* name, int*& value, int& size, int& allocated); |
| 96 |
void atlas__Metadata__get_array_long(Metadata* This, const char* name, long*& value, int& size, int& allocated); |
| 97 |
void atlas__Metadata__get_array_float(Metadata* This, const char* name, float*& value, int& size, int& allocated); |
| 98 |
void atlas__Metadata__get_array_double(Metadata* This, const char* name, double*& value, int& size, int& allocated); |
| 99 |
} |
| 100 |
|
| 101 |
// ------------------------------------------------------------------ |
| 102 |
|
| 103 |
} // namespace util |
| 104 |
} // namespace atlas |