openPMD-api
 
Loading...
Searching...
No Matches
Access.hpp
1/* Copyright 2017-2025 Fabian Koller and Franz Poeschel, Axel Huebl
2 *
3 * This file is part of openPMD-api.
4 *
5 * openPMD-api is free software: you can redistribute it and/or modify
6 * it under the terms of of either the GNU General Public License or
7 * the GNU Lesser General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * openPMD-api is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License and the GNU Lesser General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * and the GNU Lesser General Public License along with openPMD-api.
19 * If not, see <http://www.gnu.org/licenses/>.
20 */
21#pragma once
22
23#include <stdexcept>
24
25namespace openPMD
26{
57enum class Access
58{
59 READ_ONLY = 0,
86 READ_RANDOM_ACCESS = READ_ONLY,
87 CREATE = CREATE_RANDOM_ACCESS,
89}; // Access
90
91std::ostream &operator<<(std::ostream &o, Access const &a);
92
93namespace access
94{
95 inline bool readOnly(Access access)
96 {
97 switch (access)
98 {
100 case Access::READ_ONLY:
101 return true;
107 return false;
108 }
109 throw std::runtime_error("Unreachable!");
110 }
111
112 inline bool write(Access access)
113 {
114 return !readOnly(access);
115 }
116
117 inline bool writeOnly(Access access)
118 {
119 switch (access)
120 {
122 case Access::READ_ONLY:
124 return false;
129 return true;
130 }
131 throw std::runtime_error("Unreachable!");
132 }
133
134 inline bool read(Access access)
135 {
136 return !writeOnly(access);
137 }
138
139 inline bool random_access(Access access)
140 {
141 switch (access)
142 {
143
144 case Access::READ_ONLY:
148 return true;
152 return false;
153 }
154 throw std::runtime_error("Unreachable");
155 }
156
157 inline bool linear(Access access)
158 {
159 return !random_access(access);
160 }
161
162 inline bool append(Access access)
163 {
164 switch (access)
165 {
166
167 case Access::READ_ONLY:
172 return false;
175 return true;
176 }
177 throw std::runtime_error("Unreachable");
178 }
179
180 inline bool create(Access access)
181 {
182 switch (access)
183 {
184
185 case Access::READ_ONLY:
190 return false;
193 return true;
194 }
195 throw std::runtime_error("Unreachable");
196 }
197} // namespace access
198
199// deprecated name (used prior to 0.12.0)
200// note: "using old [[deprecated(msg)]] = new;" is still badly supported, thus
201// using typedef
202// https://en.cppreference.com/w/cpp/language/attributes/deprecated
203// - NVCC < 11.0.167 works but noisy "warning: attribute does not apply to any
204// entity"
205// Nvidia bug report: 2991260
206// - Intel C++ 19.1.0.20200306 bug report: 04651484
207[[deprecated("AccessType is deprecated, use Access instead.")]] typedef Access
208 AccessType;
209} // namespace openPMD
Public definitions of openPMD-api.
Definition Date.cpp:29
Access
File access mode to use during IO.
Definition Access.hpp:58
@ CREATE_RANDOM_ACCESS
create new series and truncate existing (files)
Definition Access.hpp:76
@ APPEND_RANDOM_ACCESS
write new iterations to an existing series without reading
Definition Access.hpp:82
@ CREATE_LINEAR
create new series and truncate existing (files)
Definition Access.hpp:79
@ READ_RANDOM_ACCESS
more explicit alias for READ_ONLY
Definition Access.hpp:86
@ READ_LINEAR
Open Series as read-only, fails if Series is not found.
Definition Access.hpp:67
@ READ_WRITE
Open existing Series as writable.
Definition Access.hpp:73
@ APPEND_LINEAR
write new iterations to an existing series without reading
Definition Access.hpp:85