44 #ifndef TM_IN_SYS_TIME 58 #include <sys/types.h> 95 #ifdef COMPUTE_ENDIAN_AT_RUNTIME 97 dods_int16 i = 0x0100;
98 char *c =
reinterpret_cast<char*
>(&i);
122 if (arg->
type() != dods_str_c)
throw Error(malformed_expr,
"The function requires a string argument.");
126 "The CE Evaluator built an argument list where some constants held no values.");
128 return static_cast<Str*
>(arg)->value();
131 template<
class T>
static void set_array_using_double_helper(Array *a,
double *src,
int src_len)
137 vector<T> values(src_len);
138 for (
int i = 0; i < src_len; ++i)
139 values[i] = (T) src[i];
142 a->set_value(values, src_len);
173 || dest->
var()->
type() == dods_url_c)
174 throw InternalErr(__FILE__, __LINE__,
"The function requires a numeric-type array argument.");
180 if (dest->
length() != src_len)
182 "The source and destination array sizes don't match (" + long_to_string(src_len) +
" versus " 183 + long_to_string(dest->
length()) +
").");
191 set_array_using_double_helper<dods_byte>(dest, src, src_len);
194 set_array_using_double_helper<dods_uint16>(dest, src, src_len);
197 set_array_using_double_helper<dods_int16>(dest, src, src_len);
200 set_array_using_double_helper<dods_uint32>(dest, src, src_len);
203 set_array_using_double_helper<dods_int32>(dest, src, src_len);
206 set_array_using_double_helper<dods_float32>(dest, src, src_len);
209 set_array_using_double_helper<dods_float64>(dest, src, src_len);
214 set_array_using_double_helper<dods_byte>(dest, src, src_len);
217 set_array_using_double_helper<dods_int8>(dest, src, src_len);
220 set_array_using_double_helper<dods_uint64>(dest, src, src_len);
223 set_array_using_double_helper<dods_int64>(dest, src, src_len);
227 "The argument list built by the CE parser contained an unsupported numeric type.");
234 template<
class T>
static double *extract_double_array_helper(Array * a)
238 int length = a->length();
243 double *dest =
new double[length];
244 for (
int i = 0; i < length; ++i)
245 dest[i] = (
double) b[i];
266 || a->
var()->
type() == dods_url_c)
267 throw Error(malformed_expr,
"The function requires a DAP numeric-type array argument.");
270 throw InternalErr(__FILE__, __LINE__,
string(
"The Array '") + a->
name() +
"'does not contain values.");
278 return extract_double_array_helper<dods_byte>(a);
280 return extract_double_array_helper<dods_uint16>(a);
282 return extract_double_array_helper<dods_int16>(a);
284 return extract_double_array_helper<dods_uint32>(a);
286 return extract_double_array_helper<dods_int32>(a);
288 return extract_double_array_helper<dods_float32>(a);
294 return extract_double_array_helper<dods_float64>(a);
298 return extract_double_array_helper<dods_byte>(a);
300 return extract_double_array_helper<dods_int8>(a);
302 return extract_double_array_helper<dods_uint64>(a);
304 return extract_double_array_helper<dods_int64>(a);
307 "The argument list built by the CE parser contained an unsupported numeric type.");
314 template<
class T>
static void extract_double_array_helper(Array * a, vector<double> &dest)
317 assert(dest.size() == (
unsigned long )a->length());
319 int length = a->length();
324 for (
int i = 0; i < length; ++i)
325 dest[i] = (
double) b[i];
348 || a->
var()->
type() == dods_url_c)
349 throw Error(malformed_expr,
"The function requires a DAP numeric-type array argument.");
352 throw InternalErr(__FILE__, __LINE__,
string(
"The Array '") + a->
name() +
"' does not contain values.");
362 return extract_double_array_helper<dods_byte>(a, dest);
364 return extract_double_array_helper<dods_uint16>(a, dest);
366 return extract_double_array_helper<dods_int16>(a, dest);
368 return extract_double_array_helper<dods_uint32>(a, dest);
370 return extract_double_array_helper<dods_int32>(a, dest);
372 return extract_double_array_helper<dods_float32>(a, dest);
374 return a->value(&dest[0]);
379 return extract_double_array_helper<dods_byte>(a, dest);
381 return extract_double_array_helper<dods_int8>(a, dest);
383 return extract_double_array_helper<dods_uint64>(a, dest);
385 return extract_double_array_helper<dods_int64>(a, dest);
388 "The argument list built by the CE parser contained an unsupported numeric type.");
407 throw Error(malformed_expr,
"The function requires a numeric-type argument.");
411 "The Evaluator built an argument list where some constants held no values.");
417 switch (arg->
type()) {
419 return (
double) (
static_cast<Byte*
>(arg)->value());
421 return (
double) (
static_cast<UInt16*
>(arg)->value());
423 return (
double) (
static_cast<Int16*
>(arg)->value());
425 return (
double) (
static_cast<UInt32*
>(arg)->value());
427 return (
double) (
static_cast<Int32*
>(arg)->value());
429 return (
double) (
static_cast<Float32*
>(arg)->value());
431 return static_cast<Float64*
>(arg)->value();
435 return (
double) (
static_cast<Byte*
>(arg)->value());
437 return (
double) (
static_cast<Int8*
>(arg)->value());
439 return (
double) (
static_cast<UInt64*
>(arg)->value());
441 return (
double) (
static_cast<Int64*
>(arg)->value());
445 "The argument list built by the parser contained an unsupported numeric type.");
461 if (name.find_first_of(
' ') == name.npos)
465 unsigned int i = name.find_first_not_of(
' ');
466 string tmp_name = name.substr(i);
469 unsigned int j = tmp_name.find(
'?') + 1;
470 i = tmp_name.find_first_not_of(
' ', j);
471 tmp_name.erase(j, i - j);
480 bool unique_names(vector<BaseType *> l,
const string &var_name,
const string &type_name,
string &msg)
483 vector<string> names(l.size());
486 typedef std::vector<BaseType *>::const_iterator citer;
487 for (citer i = l.begin(); i != l.end(); i++) {
489 names[nelem++] = (*i)->name();
490 DBG(cerr <<
"NAMES[" << nelem - 1 <<
"]=" << names[nelem-1] << endl);
494 sort(names.begin(), names.end());
497 sort(names.begin(), names.end());
500 for (
int j = 1; j < nelem; ++j) {
501 if (names[j - 1] == names[j]) {
503 oss <<
"The variable `" << names[j] <<
"' is used more than once in " <<
type_name <<
" `" << var_name
524 extern "C" const char *
527 return PACKAGE_VERSION;
530 extern "C" const char *
545 if (time(&TimBin) == (time_t) -1)
546 return string(
"time() error");
548 char *ctime_value = ctime(&TimBin);
550 string TimStr = ctime_value;
551 return TimStr.substr(0, TimStr.size() - 2);
564 for (
unsigned int i = 0; i < s.length(); i++)
565 s[i] = tolower(s[i]);
575 return (!s.empty() && s[0] ==
'\"' && s[s.length() - 1] ==
'\"');
587 return s.substr(1, s.length() - 2);
595 if (strcmp(name,
"Byte") == 0)
return dods_byte_c;
597 if (strcmp(name,
"Char") == 0)
return dods_char_c;
599 if (strcmp(name,
"Int8") == 0)
return dods_int8_c;
601 if (strcmp(name,
"UInt8") == 0)
return dods_uint8_c;
603 if (strcmp(name,
"Int16") == 0)
return dods_int16_c;
605 if (strcmp(name,
"UInt16") == 0)
return dods_uint16_c;
607 if (strcmp(name,
"Int32") == 0)
return dods_int32_c;
609 if (strcmp(name,
"UInt32") == 0)
return dods_uint32_c;
611 if (strcmp(name,
"Int64") == 0)
return dods_int64_c;
613 if (strcmp(name,
"UInt64") == 0)
return dods_uint64_c;
615 if (strcmp(name,
"Float32") == 0)
return dods_float32_c;
617 if (strcmp(name,
"Float64") == 0)
return dods_float64_c;
619 if (strcmp(name,
"String") == 0)
return dods_str_c;
624 if (strcmp(name,
"Url") == 0 || strcmp(name,
"URL") == 0)
return dods_url_c;
626 if (strcmp(name,
"Enum") == 0)
return dods_enum_c;
628 if (strcmp(name,
"Opaque") == 0)
return dods_opaque_c;
630 if (strcmp(name,
"Array") == 0)
return dods_array_c;
632 if (strcmp(name,
"Structure") == 0)
return dods_structure_c;
634 if (strcmp(name,
"Sequence") == 0)
return dods_sequence_c;
636 if (strcmp(name,
"Grid") == 0)
return dods_grid_c;
652 return string(
"Null");
654 return string(
"Byte");
656 return string(
"Int16");
658 return string(
"UInt16");
660 return string(
"Int32");
662 return string(
"UInt32");
664 return string(
"Float32");
666 return string(
"Float64");
668 return string(
"String");
670 return string(
"Url");
673 return string(
"Array");
674 case dods_structure_c:
675 return string(
"Structure");
676 case dods_sequence_c:
677 return string(
"Sequence");
679 return string(
"Grid");
682 throw InternalErr(__FILE__, __LINE__,
"Unknown type.");
697 return string(
"Null");
699 return string(
"Byte");
701 return string(
"Char");
703 return string(
"Int8");
705 return string(
"UInt8");
707 return string(
"Int16");
709 return string(
"UInt16");
711 return string(
"Int32");
713 return string(
"UInt32");
715 return string(
"Int64");
717 return string(
"UInt64");
719 return string(
"Enum");
722 return string(
"Float32");
724 return string(
"Float64");
727 return string(
"String");
729 return string(
"URL");
732 return string(
"Opaque");
735 return string(
"Array");
737 case dods_structure_c:
738 return string(
"Structure");
739 case dods_sequence_c:
740 return string(
"Sequence");
742 return string(
"Group");
745 throw InternalErr(__FILE__, __LINE__,
"Unknown type.");
802 case dods_structure_c:
803 case dods_sequence_c:
847 case dods_structure_c:
848 case dods_sequence_c:
890 case dods_structure_c:
891 case dods_sequence_c:
934 return (stat(dir.c_str(), &buf) == 0) && (buf.st_mode & S_IFDIR);
938 void append_long_to_string(
long val,
int base,
string &str_val)
943 char digits[] =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
947 if (base > 36 || base < 2) {
949 std::invalid_argument ex(
"The parameter base has an invalid value.");
952 if (val < 0) str_val +=
'-';
953 r = ldiv(labs(val), base);
956 if (r.quot > 0) append_long_to_string(r.quot, base, str_val);
960 str_val += digits[(int) r.rem];
964 string long_to_string(
long val,
int base)
967 append_long_to_string(val, base, s);
972 void append_double_to_string(
const double &num,
string &str)
982 string double_to_string(
const double &num)
985 append_double_to_string(num, s);
996 static const char path_sep[] =
1000 static const char path_sep[] = {
"/" };
1013 string::size_type pos = path.rfind(path_sep);
1015 return (pos == string::npos) ? path : path.substr(++pos);
1018 #define CHECK_BIT( tab, bit ) ( tab[ (bit)/8 ] & (1<<( (bit)%8 )) ) 1019 #define BITLISTSIZE 16 1025 static void globchars(
const char *s,
const char *e,
char *b)
1029 memset(b,
'\0', BITLISTSIZE);
1031 if (*s ==
'^') neg++, s++;
1036 if (s + 2 < e && s[1] ==
'-') {
1037 for (c = s[0]; c <= s[2]; c++)
1038 b[c / 8] |= (1 << (c % 8));
1043 b[c / 8] |= (1 << (c % 8));
1049 for (i = 0; i < BITLISTSIZE; i++)
1074 int glob(
const char *c,
const char *s)
1076 if (!c || !s)
return 1;
1078 char bitlist[BITLISTSIZE];
1087 if (!*s++)
return i;
1093 const char *here = c;
1095 if (!*c++)
return i;
1096 }
while (here == c || *c !=
']');
1101 globchars(here, c, bitlist);
1103 if (!CHECK_BIT(bitlist, *(
unsigned char * )s))
return i;
1109 const char *here = s;
1122 r = *c ?
glob(c, s) : *s ? -1 : 0;
1126 else if (r < 0)
return i;
1136 if (!*c || *s++ != *c++)
return i;
1140 if (*s++ != c[-1])
return i;
1157 return (sz > 0 && nelem < UINT_MAX / sz);
1178 if (path.length() > 255)
return false;
1180 Regex name(
"[-0-9A-z_./]+");
1181 if (!strict) name =
"[:print:]+";
1183 string::size_type len = path.length();
1184 int result = name.
match(path.c_str(), len);
1187 if (len > INT_MAX || result != static_cast<int>(len))
return false;
1200 return (
string)
"OPeNDAP DAP/" +
libdap_version() +
": compiled on " + __DATE__ +
":" + __TIME__;
1218 copy(name_template.begin(), name_template.end(), back_inserter(name));
1219 if (!suffix.empty())
1220 copy(suffix.begin(), suffix.end(), back_inserter(name));
1221 name.push_back(
'\0');
1224 int tmpfile = mkstemps(&name[0], suffix.length());
1226 throw Error(internal_error,
"Could not make a temporary file.");
1233 throw Error(internal_error,
"Could not make a temporary file.");
1235 return string(&name[0]);
Holds an 8-bit signed integer value.
Holds a64-bit signed integer.
virtual bool read_p()
Has this variable been read?
virtual string name() const
Returns the name of the class instance.
bool is_constructor_type(Type t)
Returns true if the instance is a constructor (i.e., Structure, Sequence or Grid) type variable...
string prune_spaces(const string &name)
string open_temp_fstream(ofstream &f, const string &name_template, const string &suffix)
Holds an unsigned 16-bit integer.
virtual void set_read_p(bool state)
Indicates that the data is ready to send.
string extract_string_argument(BaseType *arg)
bool dir_exists(const string &dir)
bool size_ok(unsigned int sz, unsigned int nelem)
sanitize the size of an array. Test for integer overflow when dynamically allocating an array...
bool is_vector_type(Type t)
Returns true if the instance is a vector (i.e., array) type variable.
virtual bool is_simple_type() const
Returns true if the instance is a numeric, string or URL type variable.
Type
Identifies the data type.
Holds a 32-bit floating point value.
A class for software fault reporting.
int match(const char *s, int len, int pos=0)
Does the pattern match.
virtual BaseType * var(const string &name="", bool exact_match=true, btp_stack *s=0)
Holds character string data.
void set_array_using_double(Array *dest, double *src, int src_len)
bool pathname_ok(const string &path, bool strict)
Does the string name a potentially valid pathname? Test the given pathname to verify that it is a val...
double * extract_double_array(Array *a)
Holds a 16-bit signed integer value.
virtual Type type() const
Returns the type of the class instance.
ObjectType get_type(const string &value)
string D4type_name(Type t)
Returns the type of the class instance as a string. Supports all DAP4 types and not the DAP2-only typ...
string path_to_filename(string path)
bool is_quoted(const string &s)
bool is_simple_type(Type t)
Returns true if the instance is a numeric, string or URL type variable.
Holds a 64-bit unsigned integer.
double extract_double_value(BaseType *arg)
string remove_quotes(const string &s)
The basic data type for the DODS DAP types.
string D2type_name(Type t)
Returns the type of the class instance as a string. Supports all DAP2 types and not the DAP4-only typ...
Holds a 64-bit (double precision) floating point value.
virtual int length() const
A class for error processing.
bool is_host_big_endian()
Does this host use big-endian byte order?
Holds a 32-bit unsigned integer.
const char * libdap_version()
A multidimensional array of identical data types.
int glob(const char *c, const char *s)
bool is_integer_type(Type t)
Holds a 32-bit signed integer.