openPMD-api
Access.hpp
1 /* Copyright 2017-2021 Fabian Koller and Franz Poeschel
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 
25 namespace openPMD
26 {
29 enum class Access
30 {
65  READ_ONLY,
67  /*
68  * Open Series as read-only, fails if Series is not found.
69  * This access mode requires use of Series::readIterations().
70  * Global attributes are available directly after calling
71  * Series::readIterations(), Iterations and all their corresponding data
72  * become available by use of the returned Iterator, e.g. in a foreach loop.
73  * See Access::READ_ONLY for when to use this.
74  */
75  READ_LINEAR,
80  READ_WRITE,
81  CREATE,
82  APPEND
83 }; // Access
84 
85 namespace access
86 {
87  inline bool readOnly(Access access)
88  {
89  switch (access)
90  {
91  case Access::READ_LINEAR:
92  case Access::READ_ONLY:
93  return true;
94  case Access::READ_WRITE:
95  case Access::CREATE:
96  case Access::APPEND:
97  return false;
98  }
99  throw std::runtime_error("Unreachable!");
100  }
101 
102  inline bool write(Access access)
103  {
104  return !readOnly(access);
105  }
106 
107  inline bool writeOnly(Access access)
108  {
109  switch (access)
110  {
111  case Access::READ_LINEAR:
112  case Access::READ_ONLY:
113  case Access::READ_WRITE:
114  return false;
115  case Access::CREATE:
116  case Access::APPEND:
117  return true;
118  }
119  throw std::runtime_error("Unreachable!");
120  }
121 
122  inline bool read(Access access)
123  {
124  return !writeOnly(access);
125  }
126 } // namespace access
127 
128 // deprecated name (used prior to 0.12.0)
129 // note: "using old [[deprecated(msg)]] = new;" is still badly supported, thus
130 // using typedef
131 // https://en.cppreference.com/w/cpp/language/attributes/deprecated
132 // - NVCC < 11.0.167 works but noisy "warning: attribute does not apply to any
133 // entity"
134 // Nvidia bug report: 2991260
135 // - Intel C++ 19.1.0.20200306 bug report: 04651484
136 [[deprecated("AccessType is deprecated, use Access instead.")]] typedef Access
137  AccessType;
138 } // namespace openPMD
Open existing Series as writable.
Access
File access mode to use during IO.
Definition: Access.hpp:29
create new series and truncate existing (files)
Public definitions of openPMD-api.
write new iterations to an existing series without reading
Open Series as read-only, fails if Series is not found.
more explicit alias for READ_ONLY