atlas
ArrayReference.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 "atlas/io/Data.h"
14 #include "atlas/io/Metadata.h"
15 #include "atlas/io/types/array/ArrayMetadata.h"
16 
17 namespace atlas {
18 namespace io {
19 
20 //---------------------------------------------------------------------------------------------------------------------
21 
22 class ArrayReference : public ArrayMetadata {
23 public:
24  ArrayReference() = default;
25 
26  ArrayReference( const void* data, DataType, const ArrayShape& );
27 
28  template <typename T>
29  ArrayReference( const T* data, const ArrayShape& shape ) :
30  ArrayMetadata( DataType::create<T>(), shape ), data_( const_cast<T*>( data ) ) {}
31 
33 
34  ArrayReference& operator=( ArrayReference&& );
35 
36  void* data() const { return data_; }
37 
38  friend void decode( const atlas::io::Metadata&, const atlas::io::Data&, ArrayReference& );
39 
40 private:
41  void* data_{nullptr};
42 };
43 
44 //---------------------------------------------------------------------------------------------------------------------
45 
46 size_t encode_metadata( const ArrayReference& value, atlas::io::Metadata& out );
47 
48 void encode_data( const ArrayReference& value, atlas::io::Data& out );
49 
50 //---------------------------------------------------------------------------------------------------------------------
51 
52 } // namespace io
53 } // namespace atlas
Definition: ArrayShape.h:33
Definition: ArrayReference.h:22
Definition: Metadata.h:36
Definition: Data.h:22
Definition: ArrayMetadata.h:25
Definition: DataType.h:40
Contains all atlas classes and methods.
Definition: atlas-grids.cc:33