atlas
ArrayUtil.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 "atlas/array/ArrayIdx.h"
16 #include "atlas/array/ArrayLayout.h"
17 #include "atlas/array/ArrayShape.h"
18 #include "atlas/array/ArraySpec.h"
19 #include "atlas/array/ArrayStrides.h"
20 
21 //------------------------------------------------------------------------------------------------------
22 
23 namespace atlas {
24 namespace array {
25 
26 #ifndef DOXYGEN_SHOULD_SKIP_THIS
27 template <typename T>
28 struct remove_const {
29  typedef T type;
30 };
31 template <typename T>
32 struct remove_const<T const> {
33  typedef T type;
34 };
35 
36 template <typename T>
37 struct add_const {
38  typedef const typename remove_const<T>::type type;
39 };
40 template <typename T>
41 struct add_const<T const> {
42  typedef const T type;
43 };
44 #endif
45 
47 public:
48  virtual ~ArrayDataStore() {}
49  virtual void updateDevice() const = 0;
50  virtual void updateHost() const = 0;
51  virtual bool valid() const = 0;
52  virtual void syncHostDevice() const = 0;
53  virtual bool hostNeedsUpdate() const = 0;
54  virtual bool deviceNeedsUpdate() const = 0;
55  virtual void reactivateDeviceWriteViews() const = 0;
56  virtual void reactivateHostWriteViews() const = 0;
57  virtual void* voidDataStore() = 0;
58  virtual void* voidHostData() = 0;
59  virtual void* voidDeviceData() = 0;
60  template <typename Value>
61  Value* hostData() {
62  return static_cast<Value*>( voidHostData() );
63  }
64  template <typename Value>
65  Value* deviceData() {
66  return static_cast<Value*>( voidDeviceData() );
67  }
68 };
69 
70 #ifndef DOXYGEN_SHOULD_SKIP_THIS
71 template <int Dim>
72 static constexpr char array_dim() {
73  return Dim == 0 ? 'i' : ( Dim == 1 ? 'j' : ( Dim == 2 ? 'k' : ( Dim == 3 ? 'l' : ( Dim == 4 ? 'm' : ( '*' ) ) ) ) );
74 }
75 
76 void throw_OutOfRange( const std::string& class_name, char idx_str, int idx, int max );
77 #endif
78 
79 //------------------------------------------------------------------------------------------------------
80 
81 } // namespace array
82 } // namespace atlas
Definition: ArrayUtil.h:46
Definition: ArrayUtil.h:28
Definition: ArrayUtil.h:37
Contains all atlas classes and methods.
Definition: atlas-grids.cc:33
Definition: ArrayViewDefs.h:20