atlas
ArrayMetadata.h
1 /*
2  * (C) Copyright 2020 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 <cstdint>
14 #include <string>
15 
16 #include "atlas/array/ArrayShape.h"
17 #include "atlas/array/DataType.h"
18 #include "atlas/io/Metadata.h"
19 
20 namespace atlas {
21 namespace io {
22 
23 //---------------------------------------------------------------------------------------------------------------------
24 
26 public:
28  using DataType = array::DataType;
29 
30  static std::string type() { return "array"; }
31 
32 public:
33  ArrayMetadata();
34 
35  explicit ArrayMetadata( const Metadata& );
36 
37  explicit ArrayMetadata( const DataType&, const ArrayShape& );
38 
39  explicit ArrayMetadata( const ArrayMetadata& );
40 
42 
43  ArrayMetadata& operator=( ArrayMetadata&& );
44 
45  int rank() const { return int( shape_.size() ); }
46 
47  int shape( int i ) const;
48 
49  const ArrayShape& shape() const { return shape_; }
50 
51  DataType datatype() const { return datatype_; }
52 
53  size_t size() const;
54 
55  size_t bytes() const { return size() * datatype_.size(); }
56 
57  friend size_t encode_metadata( const ArrayMetadata& value, atlas::io::Metadata& out );
58 
59 private:
60  ArrayShape shape_;
61  DataType datatype_;
62 };
63 
64 //---------------------------------------------------------------------------------------------------------------------
65 
66 size_t encode_metadata( const ArrayMetadata& value, atlas::io::Metadata& out );
67 
68 //---------------------------------------------------------------------------------------------------------------------
69 
70 } // namespace io
71 } // namespace atlas
Definition: ArrayShape.h:33
Definition: Metadata.h:36
Definition: ArrayMetadata.h:25
Definition: DataType.h:40
Contains all atlas classes and methods.
Definition: atlas-grids.cc:33