58#define ESCAPE_STRING_ATTRIBUTES 1
62 const string printable =
" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789~`!@#$%^&*()_-+={[}]|\\:;<,>.?/'\"\n\t\r";
63 const string ESC =
"\\";
65#if ESCAPE_STRING_ATTRIBUTES
66 const string DOUBLE_ESC = ESC + ESC;
67 const string QUOTE =
"\"";
68 const string ESCQUOTE = ESC + QUOTE;
72 while ((ind = s.find(ESC, ind)) != string::npos) {
73 s.replace(ind, 1, DOUBLE_ESC);
74 ind += DOUBLE_ESC.length();
79 while ((ind = s.find(QUOTE, ind)) != string::npos) {
80 s.replace(ind, 1, ESCQUOTE);
81 ind += ESCQUOTE.length();
87 while ((ind = s.find_first_not_of(printable, ind)) != string::npos)
88 s.replace(ind, 1, ESC +
octstring(s[ind]));
98 buf << oct << setw(3) << setfill(
'0')
99 <<
static_cast<unsigned int>(val);
105void HDF5CFDAPUtil::replace_double_quote(
string & str) {
107 const string offend_char =
"\"";
108 const string replace_str =
""e";
109 size_t found_quote = 0;
110 size_t start_pos = 0;
111 while (found_quote != string::npos) {
112 found_quote = str.find(offend_char,start_pos);
113 if (found_quote!= string::npos){
114 str.replace(found_quote,offend_char.size(),replace_str);
115 start_pos = found_quote+1;
121string HDF5CFDAPUtil::print_type(H5DataType type) {
125 string DAPUNSUPPORTED =
"Unsupported";
126 string DAPBYTE =
"Byte";
127 string DAPINT16 =
"Int16";
128 string DAPUINT16 =
"Uint16";
129 string DAPINT32 =
"Int32";
130 string DAPUINT32 =
"Uint32";
131 string DAPFLOAT32 =
"Float32";
132 string DAPFLOAT64 =
"Float64";
133 string DAP4INT64 =
"Int64";
134 string DAP4UINT64 =
"UInt64";
135 string DAPSTRING =
"String";
173 return DAPUNSUPPORTED;
176 return DAPUNSUPPORTED;
181D4AttributeType HDF5CFDAPUtil::print_type_dap4(H5DataType type) {
195 return attr_uint16_c;
201 return attr_uint32_c;
207 return attr_uint64_c;
210 return attr_float32_c;
213 return attr_float64_c;
231HDF5CFDAPUtil::get_mem_dtype(H5DataType dtype,
size_t mem_dtype_size ) {
235 return ((H5INT16 == dtype) && (1 == mem_dtype_size))?H5CHAR:dtype;
239HDF5CFDAPUtil:: print_attr(H5DataType type,
int loc,
void *vals)
251 unsigned long long *ullp;
261 gp.ucp = (
unsigned char *) vals;
271 gp.cp = (
char *) vals;
285 gp.sp = (
short *) vals;
293 gp.usp = (
unsigned short *) vals;
294 rep << *(gp.usp+loc);
301 gp.ip = (
int *) vals;
308 gp.uip = (
unsigned int *) vals;
309 rep << *(gp.uip+loc);
314 gp.llp = (
long long *) vals;
315 rep << *(gp.llp+loc);
321 gp.ullp = (
unsigned long long *) vals;
322 rep << *(gp.ullp+loc);
330 float attr_val = *(
float*)vals;
331 bool is_a_fin = isfinite(attr_val);
332 gp.fp = (
float *) vals;
334 rep << setprecision(10);
336 string tmp_rep_str = rep.str();
337 if (tmp_rep_str.find(
'.') == string::npos
338 && tmp_rep_str.find(
'e') == string::npos
339 && tmp_rep_str.find(
'E') == string::npos
340 && (
true == is_a_fin)){
348 double attr_val = *(
double*)vals;
349 bool is_a_fin = isfinite(attr_val);
350 gp.dp = (
double *) vals;
351 rep << std::showpoint;
352 rep << std::setprecision(17);
354 string tmp_rep_str = rep.str();
355 if (tmp_rep_str.find(
'.') == string::npos
356 && tmp_rep_str.find(
'e') == string::npos
357 && tmp_rep_str.find(
'E') == string::npos
358 && (
true == is_a_fin)) {
364 return string(
"UNKNOWN");
375 else if (s ==
"Int8")
377 else if (s ==
"UInt8")
379 else if (s ==
"Int16")
381 else if (s ==
"UInt16")
382 return attr_uint16_c;
383 else if (s ==
"Int32")
385 else if (s ==
"UInt32")
386 return attr_uint32_c;
387 else if (s ==
"Int64")
389 else if (s ==
"UInt64")
390 return attr_uint64_c;
391 else if (s ==
"Float32")
392 return attr_float32_c;
393 else if (s ==
"Float64")
394 return attr_float64_c;
395 else if (s ==
"String")
static string escattr(string s)
static D4AttributeType daptype_strrep_to_dap4_attrtype(const string &s)
static string octstring(unsigned char val)
Helper function for escattr.
Helper functions for generating DAS attributes and a function to check BES Key.