Debian Codegraph @

src/atlas/trans/Cache.h

raw
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 <memory>
14
15 #include "eckit/filesystem/PathName.h"
16
17 #include "atlas/util/ObjectHandle.h"
18
19 //-----------------------------------------------------------------------------
20 // Forward declarations
21
22 namespace atlas {
23 class Field;
24 class FieldSet;
25 class FunctionSpace;
26 class Grid;
27 class Domain;
28 namespace trans {
29 class TransImpl;
30 class Trans;
31 } // namespace trans
32 } // namespace atlas
33
34 //-----------------------------------------------------------------------------
35
36 namespace atlas {
37 namespace trans {
38
39 //-----------------------------------------------------------------------------
40
41 class TransCacheEntry {
42 public:
43 operator bool() const { return size() != 0; }
44 virtual ~TransCacheEntry() = default;
45 virtual size_t size() const = 0;
46 virtual const void* data() const = 0;
47 };
48
49 //-----------------------------------------------------------------------------
50
51 class EmptyCacheEntry final : public TransCacheEntry {
52 public:
53 virtual size_t size() const override { return 0; }
54 virtual const void* data() const override { return nullptr; }
55 };
56
57 //-----------------------------------------------------------------------------
58 class TransCacheFileEntry final : public TransCacheEntry {
59 public:
60 TransCacheFileEntry(const eckit::PathName& path);
61 virtual ~TransCacheFileEntry() override;
62 virtual size_t size() const override { return size_; }
63 virtual const void* data() const override { return data_; }
64 private:
65 void* data_ = nullptr;
66 size_t size_ = 0;
67 };
68
69 //-----------------------------------------------------------------------------
70
71 class TransCacheMemoryEntry final : public TransCacheEntry {
72 public:
73 TransCacheMemoryEntry(const void* data, size_t size);
74 virtual const void* data() const override { return data_; }
75 virtual size_t size() const override { return size_; }
76
77 private:
78 const void* data_;
79 const size_t size_;
80 };
81
82 //-----------------------------------------------------------------------------
83
84 class TransCacheOwnedMemoryEntry final : public TransCacheEntry {
85 public:
86 TransCacheOwnedMemoryEntry(size_t size);
87 virtual ~TransCacheOwnedMemoryEntry() override;
88 virtual const void* data() const override { return data_; }
89 virtual size_t size() const override { return size_; }
90
91 private:
92 void* data_ = nullptr;
93 const size_t size_ = 0;
94 };
95
96 //-----------------------------------------------------------------------------
97
98 class Cache {
99 public:
100 Cache();
101 Cache(const Cache& other) = default;
102 operator bool() const;
103 const TransImpl* trans() const { return trans_.get(); }
104 const TransCacheEntry& legendre() const { return *legendre_; }
105 const TransCacheEntry& fft() const { return *fft_; }
106 virtual ~Cache();
107
108 protected:
109 Cache(const std::shared_ptr<TransCacheEntry>& legendre);
110 Cache(const std::shared_ptr<TransCacheEntry>& legendre, const std::shared_ptr<TransCacheEntry>& fft);
111 Cache(const TransImpl*);
112
113 private:
114 util::ObjectHandle<const TransImpl> trans_;
115 std::shared_ptr<TransCacheEntry> legendre_;
116 std::shared_ptr<TransCacheEntry> fft_;
117 };
118
119 class TransCache : public Cache {
120 public:
121 TransCache(const Trans&);
122 };
123
124
125 class LegendreCache : public Cache {
126 public:
127 LegendreCache(size_t size);
128 LegendreCache(const void* address, size_t size);
129 LegendreCache(const eckit::PathName& path);
130 };
131
132 class LegendreFFTCache : public Cache {
133 public:
134 LegendreFFTCache(const void* legendre_address, size_t legendre_size, const void* fft_address, size_t fft_size);
135 LegendreFFTCache(const eckit::PathName& legendre_path, const eckit::PathName& fft_path);
136 };
137
138 //----------------------------------------------------------------------------------------------------------------------
139
140 } // namespace trans
141 } // namespace atlas