atlas
Metadata.h
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  using eckit::LocalConfiguration::get;
39 
40  template <typename ValueT>
41  ValueT get( const std::string& name ) const {
42  ValueT value;
43  if ( not eckit::LocalConfiguration::get( name, value ) )
44  throw_not_found( name );
45  return value;
46  }
47 
48  friend std::ostream& operator<<( std::ostream& s, const Metadata& v ) {
49  v.print( s );
50  return s;
51  }
52 
53  void broadcast();
54  void broadcast( idx_t root );
55  void broadcast( Metadata& );
56  void broadcast( Metadata&, idx_t root );
57  void broadcast( Metadata& ) const;
58  void broadcast( Metadata&, idx_t root ) const;
59 
60  size_t footprint() const;
61 
62 private:
63  [[noreturn]] void throw_not_found( const std::string& ) const;
64 
65  Metadata( const eckit::Value& );
66 };
67 
68 // ------------------------------------------------------------------
69 // C wrapper interfaces to C++ routines
70 
71 extern "C" {
72 Metadata* atlas__Metadata__new();
73 
74 void atlas__Metadata__delete( Metadata* This );
75 void atlas__Metadata__print( Metadata* This, std::ostream* channel );
76 void atlas__Metadata__json( Metadata* This, char*& json, int& size, int& allocated );
77 int atlas__Metadata__has( Metadata* This, const char* name );
78 void atlas__Metadata__set_int( Metadata* This, const char* name, int value );
79 void atlas__Metadata__set_long( Metadata* This, const char* name, long value );
80 void atlas__Metadata__set_float( Metadata* This, const char* name, float value );
81 void atlas__Metadata__set_double( Metadata* This, const char* name, double value );
82 void atlas__Metadata__set_string( Metadata* This, const char* name, const char* value );
83 void atlas__Metadata__set_array_int( Metadata* This, const char* name, int value[], int size );
84 void atlas__Metadata__set_array_long( Metadata* This, const char* name, long value[], int size );
85 void atlas__Metadata__set_array_float( Metadata* This, const char* name, float value[], int size );
86 void atlas__Metadata__set_array_double( Metadata* This, const char* name, double value[], int size );
87 
88 int atlas__Metadata__get_int( Metadata* This, const char* name );
89 long atlas__Metadata__get_long( Metadata* This, const char* name );
90 float atlas__Metadata__get_float( Metadata* This, const char* name );
91 double atlas__Metadata__get_double( Metadata* This, const char* name );
92 void atlas__Metadata__get_string( Metadata* This, const char* name, char* output_str, int max_len );
93 void atlas__Metadata__get_array_int( Metadata* This, const char* name, int*& value, int& size, int& allocated );
94 void atlas__Metadata__get_array_long( Metadata* This, const char* name, long*& value, int& size, int& allocated );
95 void atlas__Metadata__get_array_float( Metadata* This, const char* name, float*& value, int& size, int& allocated );
96 void atlas__Metadata__get_array_double( Metadata* This, const char* name, double*& value, int& size, int& allocated );
97 }
98 
99 // ------------------------------------------------------------------
100 
101 } // namespace util
102 } // namespace atlas
Definition: Metadata.h:23
Contains all atlas classes and methods.
Definition: atlas-grids.cc:33
long idx_t
Integer type for indices in connectivity tables.
Definition: config.h:42