Skip to content

Commit 92cf227

Browse files
committed
Copy datatypeToString to JSON implementation
1 parent b7240f5 commit 92cf227

File tree

1 file changed

+93
-3
lines changed

1 file changed

+93
-3
lines changed

src/IO/JSON/JSONIOHandlerImpl.cpp

Lines changed: 93 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,95 @@ namespace
153153
}
154154
}
155155
}
156+
157+
// Does the same as datatypeToString(), but this makes sure that we don't
158+
// accidentally change the JSON schema by modifying datatypeToString()
159+
std::string jsonDatatypeToString(Datatype dt)
160+
{
161+
switch (dt)
162+
{
163+
using DT = Datatype;
164+
case DT::CHAR:
165+
return "CHAR";
166+
case DT::UCHAR:
167+
return "UCHAR";
168+
case DT::SCHAR:
169+
return "SCHAR";
170+
case DT::SHORT:
171+
return "SHORT";
172+
case DT::INT:
173+
return "INT";
174+
case DT::LONG:
175+
return "LONG";
176+
case DT::LONGLONG:
177+
return "LONGLONG";
178+
case DT::USHORT:
179+
return "USHORT";
180+
case DT::UINT:
181+
return "UINT";
182+
case DT::ULONG:
183+
return "ULONG";
184+
case DT::ULONGLONG:
185+
return "ULONGLONG";
186+
case DT::FLOAT:
187+
return "FLOAT";
188+
case DT::DOUBLE:
189+
return "DOUBLE";
190+
case DT::LONG_DOUBLE:
191+
return "LONG_DOUBLE";
192+
case DT::CFLOAT:
193+
return "CFLOAT";
194+
case DT::CDOUBLE:
195+
return "CDOUBLE";
196+
case DT::CLONG_DOUBLE:
197+
return "CLONG_DOUBLE";
198+
case DT::STRING:
199+
return "STRING";
200+
case DT::VEC_CHAR:
201+
return "VEC_CHAR";
202+
case DT::VEC_SHORT:
203+
return "VEC_SHORT";
204+
case DT::VEC_INT:
205+
return "VEC_INT";
206+
case DT::VEC_LONG:
207+
return "VEC_LONG";
208+
case DT::VEC_LONGLONG:
209+
return "VEC_LONGLONG";
210+
case DT::VEC_UCHAR:
211+
return "VEC_UCHAR";
212+
case DT::VEC_USHORT:
213+
return "VEC_USHORT";
214+
case DT::VEC_UINT:
215+
return "VEC_UINT";
216+
case DT::VEC_ULONG:
217+
return "VEC_ULONG";
218+
case DT::VEC_ULONGLONG:
219+
return "VEC_ULONGLONG";
220+
case DT::VEC_FLOAT:
221+
return "VEC_FLOAT";
222+
case DT::VEC_DOUBLE:
223+
return "VEC_DOUBLE";
224+
case DT::VEC_LONG_DOUBLE:
225+
return "VEC_LONG_DOUBLE";
226+
case DT::VEC_CFLOAT:
227+
return "VEC_CFLOAT";
228+
case DT::VEC_CDOUBLE:
229+
return "VEC_CDOUBLE";
230+
case DT::VEC_CLONG_DOUBLE:
231+
return "VEC_CLONG_DOUBLE";
232+
case DT::VEC_SCHAR:
233+
return "VEC_SCHAR";
234+
case DT::VEC_STRING:
235+
return "VEC_STRING";
236+
case DT::ARR_DBL_7:
237+
return "ARR_DBL_7";
238+
case DT::BOOL:
239+
return "BOOL";
240+
case DT::UNDEFINED:
241+
return "UNDEFINED";
242+
}
243+
return "Unreachable!";
244+
}
156245
} // namespace
157246

158247
auto JSONIOHandlerImpl::retrieveDatasetMode(openPMD::json::TracingJSON &config)
@@ -453,7 +542,7 @@ void JSONIOHandlerImpl::createDataset(
453542
}
454543
setAndGetFilePosition(writable, name);
455544
auto &dset = jsonVal[name];
456-
dset["datatype"] = datatypeToString(parameter.dtype);
545+
dset["datatype"] = jsonDatatypeToString(parameter.dtype);
457546

458547
switch (localMode)
459548
{
@@ -1105,7 +1194,8 @@ void JSONIOHandlerImpl::writeAttribute(
11051194
{
11061195
case AttributeMode::Long:
11071196
(*jsonVal)[filePosition->id]["attributes"][parameter.name] = {
1108-
{"datatype", datatypeToString(parameter.dtype)}, {"value", value}};
1197+
{"datatype", jsonDatatypeToString(parameter.dtype)},
1198+
{"value", value}};
11091199
break;
11101200
case AttributeMode::Short:
11111201
// short form
@@ -2025,7 +2115,7 @@ nlohmann::json JSONIOHandlerImpl::platformSpecifics()
20252115
Datatype::BOOL};
20262116
for (auto it = std::begin(datatypes); it != std::end(datatypes); it++)
20272117
{
2028-
res[datatypeToString(*it)] = toBytes(*it);
2118+
res[jsonDatatypeToString(*it)] = toBytes(*it);
20292119
}
20302120
return res;
20312121
}

0 commit comments

Comments
 (0)