Newer
Older
/*
* Distributed under the OSI-approved Apache License, Version 2.0. See
* accompanying file Copyright.txt for details.
*
* IO.tcc template implementations with fix types and specializations
*
* Created on: May 15, 2017
* Author: William F Godoy godoywf@ornl.gov
*/
#ifndef ADIOS2_CORE_IO_TCC_
#define ADIOS2_CORE_IO_TCC_
#include "IO.h"
/// \cond EXCLUDE_FROM_DOXYGEN
#include <iostream>
#include <stdexcept> //std::invalid_argument
/// \endcond
#include "adios2/ADIOSMPI.h"
#include "adios2/ADIOSMacros.h"
Variable<T> &IO::DefineVariable(const std::string &name, const Dims &shape,
const Dims &start, const Dims &count,
auto itVariable = m_Variables.find(name);
if (!IsEnd(itVariable, m_Variables))
throw std::invalid_argument("ERROR: variable " + name +
" exists in IO object " + m_Name +
", in call to DefineVariable\n");
}
}
auto &variableMap = GetVariableMap<T>();
const unsigned int size =
static_cast<const unsigned int>(variableMap.size());
auto itVariablePair =
variableMap.emplace(size, Variable<T>(name, shape, start, count,
constantShape, m_DebugMode));
m_Variables.emplace(name, std::make_pair(GetType<T>(), size));
}
template <class T>
Variable<T> &IO::GetVariable(const std::string &name)
{
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
return GetVariableMap<T>().at(GetMapIndex(name, m_Variables, "Variable"));
}
template <class T>
Attribute<T> &IO::DefineAttribute(const std::string &name, const T &value)
{
if (m_DebugMode)
{
CheckAttributeCommon(name);
}
auto &attributeMap = GetAttributeMap<T>();
const unsigned int size =
static_cast<const unsigned int>(attributeMap.size());
auto itAttributePair =
attributeMap.emplace(size, Attribute<T>(name, value));
m_Attributes.emplace(name, std::make_pair(GetType<T>(), size));
return itAttributePair.first->second;
}
template <class T>
Attribute<T> &IO::DefineAttribute(const std::string &name, const T *array,
const size_t elements)
{
if (m_DebugMode)
{
CheckAttributeCommon(name);
}
auto &attributeMap = GetAttributeMap<T>();
const unsigned int size =
static_cast<const unsigned int>(attributeMap.size());
auto itAttributePair =
attributeMap.emplace(size, Attribute<T>(name, array, elements));
m_Attributes.emplace(name, std::make_pair(GetType<T>(), size));
return itAttributePair.first->second;
}
template <class T>
Attribute<T> &IO::GetAttribute(const std::string &name)
{
return GetAttributeMap<T>().at(
GetMapIndex(name, m_Attributes, "Attribute"));
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
}
// PRIVATE
template <>
std::map<unsigned int, Variable<char>> &IO::GetVariableMap()
{
return m_Char;
}
template <>
std::map<unsigned int, Variable<unsigned char>> &IO::GetVariableMap()
{
return m_UChar;
}
template <>
std::map<unsigned int, Variable<short>> &IO::GetVariableMap()
{
return m_Short;
}
template <>
std::map<unsigned int, Variable<unsigned short>> &IO::GetVariableMap()
{
return m_UShort;
}
template <>
std::map<unsigned int, Variable<int>> &IO::GetVariableMap()
{
return m_Int;
}
template <>
std::map<unsigned int, Variable<unsigned int>> &IO::GetVariableMap()
{
return m_UInt;
}
template <>
std::map<unsigned int, Variable<long int>> &IO::GetVariableMap()
{
return m_LInt;
}
template <>
std::map<unsigned int, Variable<unsigned long int>> &IO::GetVariableMap()
{
return m_ULInt;
}
template <>
std::map<unsigned int, Variable<long long int>> &IO::GetVariableMap()
{
return m_LLInt;
}
template <>
std::map<unsigned int, Variable<unsigned long long int>> &IO::GetVariableMap()
{
return m_ULLInt;
}
template <>
std::map<unsigned int, Variable<float>> &IO::GetVariableMap()
{
return m_Float;
}
template <>
std::map<unsigned int, Variable<double>> &IO::GetVariableMap()
{
return m_Double;
}
template <>
std::map<unsigned int, Variable<long double>> &IO::GetVariableMap()
{
return m_LDouble;
}
template <>
std::map<unsigned int, Variable<cfloat>> &IO::GetVariableMap()
{
return m_CFloat;
}
template <>
std::map<unsigned int, Variable<cdouble>> &IO::GetVariableMap()
{
return m_CDouble;
}
template <>
std::map<unsigned int, Variable<cldouble>> &IO::GetVariableMap()
{
return m_CLDouble;
}
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
// attributes
template <>
std::map<unsigned int, Attribute<std::string>> &IO::GetAttributeMap()
{
return m_StringA;
}
template <>
std::map<unsigned int, Attribute<char>> &IO::GetAttributeMap()
{
return m_CharA;
}
template <>
std::map<unsigned int, Attribute<unsigned char>> &IO::GetAttributeMap()
{
return m_UCharA;
}
template <>
std::map<unsigned int, Attribute<short>> &IO::GetAttributeMap()
{
return m_ShortA;
}
template <>
std::map<unsigned int, Attribute<unsigned short>> &IO::GetAttributeMap()
{
return m_UShortA;
}
template <>
std::map<unsigned int, Attribute<int>> &IO::GetAttributeMap()
{
return m_IntA;
}
template <>
std::map<unsigned int, Attribute<unsigned int>> &IO::GetAttributeMap()
{
return m_UIntA;
}
template <>
std::map<unsigned int, Attribute<long int>> &IO::GetAttributeMap()
{
return m_LIntA;
}
template <>
std::map<unsigned int, Attribute<unsigned long int>> &IO::GetAttributeMap()
{
return m_ULIntA;
}
template <>
std::map<unsigned int, Attribute<long long int>> &IO::GetAttributeMap()
{
return m_LLIntA;
}
template <>
std::map<unsigned int, Attribute<unsigned long long int>> &IO::GetAttributeMap()
{
return m_ULLIntA;
}
template <>
std::map<unsigned int, Attribute<float>> &IO::GetAttributeMap()
{
return m_FloatA;
}
template <>
std::map<unsigned int, Attribute<double>> &IO::GetAttributeMap()
{
return m_DoubleA;
}
template <>
std::map<unsigned int, Attribute<long double>> &IO::GetAttributeMap()
{
return m_LDoubleA;
}
} // end namespace adios2