50 #define ESCAPE_STRING_ATTRIBUTES 0
54 const string printable =
" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789~`!@#$%^&*()_-+={[}]|\\:;<,>.?/'\"\n\t\r";
55 const string ESC =
"\\";
56 #if ESCAPE_STRING_ATTRIBUTES
57 const string DOUBLE_ESC = ESC + ESC;
58 const string QUOTE =
"\"";
59 const string ESCQUOTE = ESC + QUOTE;
63 while ((ind = s.find(ESC, ind)) != string::npos) {
64 s.replace(ind, 1, DOUBLE_ESC);
65 ind += DOUBLE_ESC.length();
70 while ((ind = s.find(QUOTE, ind)) != string::npos) {
71 s.replace(ind, 1, ESCQUOTE);
72 ind += ESCQUOTE.length();
78 while ((ind = s.find_first_not_of(printable, ind)) != string::npos)
79 s.replace(ind, 1, ESC + octstring(s[ind]));
89 buf << oct << setw(3) << setfill(
'0')
90 <<
static_cast<unsigned int>(val);
96 void HDF5CFDAPUtil::replace_double_quote(
string & str) {
98 const string offend_char =
"\"";
99 const string replace_str =
""e";
100 size_t found_quote = 0;
101 size_t start_pos = 0;
102 while (found_quote != string::npos) {
103 found_quote = str.find(offend_char,start_pos);
104 if (found_quote!= string::npos){
105 str.replace(found_quote,offend_char.size(),replace_str);
106 start_pos = found_quote+1;
112 string HDF5CFDAPUtil::print_type(H5DataType type) {
116 string DAPUNSUPPORTED =
"Unsupported";
117 string DAPBYTE =
"Byte";
118 string DAPINT16 =
"Int16";
119 string DAPUINT16 =
"Uint16";
120 string DAPINT32 =
"Int32";
121 string DAPUINT32 =
"Uint32";
122 string DAPFLOAT32 =
"Float32";
123 string DAPFLOAT64 =
"Float64";
124 string DAP4INT64 =
"Int64";
125 string DAP4UINT64 =
"UInt64";
126 string DAPSTRING =
"String";
164 return DAPUNSUPPORTED;
167 return DAPUNSUPPORTED;
172 D4AttributeType HDF5CFDAPUtil::print_type_dap4(H5DataType type) {
186 return attr_uint16_c;
192 return attr_uint32_c;
198 return attr_uint64_c;
201 return attr_float32_c;
204 return attr_float64_c;
222 HDF5CFDAPUtil::get_mem_dtype(H5DataType dtype,
size_t mem_dtype_size ) {
226 return ((H5INT16 == dtype) && (1 == mem_dtype_size))?H5CHAR:dtype;
230 HDF5CFDAPUtil:: print_attr(H5DataType type,
int loc,
void *vals)
242 unsigned long long *ullp;
252 gp.ucp = (
unsigned char *) vals;
262 gp.cp = (
char *) vals;
276 gp.sp = (
short *) vals;
284 gp.usp = (
unsigned short *) vals;
285 rep << *(gp.usp+loc);
292 gp.ip = (
int *) vals;
299 gp.uip = (
unsigned int *) vals;
300 rep << *(gp.uip+loc);
305 gp.llp = (
long long *) vals;
306 rep << *(gp.llp+loc);
312 gp.ullp = (
unsigned long long *) vals;
313 rep << *(gp.ullp+loc);
321 float attr_val = *(
float*)vals;
322 bool is_a_fin = isfinite(attr_val);
323 gp.fp = (
float *) vals;
325 rep << setprecision(10);
327 string tmp_rep_str = rep.str();
328 if (tmp_rep_str.find(
'.') == string::npos
329 && tmp_rep_str.find(
'e') == string::npos
330 && tmp_rep_str.find(
'E') == string::npos
331 && (
true == is_a_fin)){
339 double attr_val = *(
double*)vals;
340 bool is_a_fin = isfinite(attr_val);
341 gp.dp = (
double *) vals;
342 rep << std::showpoint;
343 rep << std::setprecision(17);
345 string tmp_rep_str = rep.str();
346 if (tmp_rep_str.find(
'.') == string::npos
347 && tmp_rep_str.find(
'e') == string::npos
348 && tmp_rep_str.find(
'E') == string::npos
349 && (
true == is_a_fin)) {
355 return string(
"UNKNOWN");
366 else if (s ==
"Int8")
368 else if (s ==
"UInt8")
370 else if (s ==
"Int16")
372 else if (s ==
"UInt16")
373 return attr_uint16_c;
374 else if (s ==
"Int32")
376 else if (s ==
"UInt32")
377 return attr_uint32_c;
378 else if (s ==
"Int64")
380 else if (s ==
"UInt64")
381 return attr_uint64_c;
382 else if (s ==
"Float32")
383 return attr_float32_c;
384 else if (s ==
"Float64")
385 return attr_float64_c;
386 else if (s ==
"String")
static string escattr(string s)
static string octstring(unsigned char val)
Helper function for escattr.
static D4AttributeType daptype_strrep_to_dap4_attrtype(std::string s)
Helper functions for generating DAS attributes and a function to check BES Key.