45 #ifndef TM_IN_SYS_TIME
59 #include <sys/types.h>
102 "The function requires a DAP string argument.");
106 "The CE Evaluator built an argument list where some constants held no values.");
108 string s =
static_cast<Str*
>(arg)->value();
110 DBG(cerr <<
"s: " << s << endl);
115 template<
class T>
static void set_array_using_double_helper(Array * a,
double *src,
int src_len)
117 T *values =
new T[src_len];
119 for (
int i = 0; i < src_len; ++i)
120 values[i] = (T) src[i];
123 a->val2buf(values,
true);
125 a->set_value(values, src_len);
157 "The function requires a DAP numeric-type array argument.");
163 if (dest->
length() != src_len)
165 "The source and destination array sizes don't match ("
175 set_array_using_double_helper<dods_byte>(dest, src, src_len);
178 set_array_using_double_helper<dods_uint16>(dest, src, src_len);
181 set_array_using_double_helper<dods_int16>(dest, src, src_len);
184 set_array_using_double_helper<dods_uint32>(dest, src, src_len);
187 set_array_using_double_helper<dods_int32>(dest, src, src_len);
190 set_array_using_double_helper<dods_float32>(dest, src, src_len);
193 set_array_using_double_helper<dods_float64>(dest, src, src_len);
197 "The argument list built by the CE parser contained an unsupported numeric type.");
204 template<
class T>
static double *extract_double_array_helper(Array * a)
206 int length = a->length();
208 T *b =
new T[length];
211 double *dest =
new double[length];
212 for (
int i = 0; i < length; ++i)
213 dest[i] = (
double) b[i];
229 "The function requires a DAP numeric-type array argument.");
233 string(
"The Array '") + a->
name() +
234 "'does not contain values.");
242 return extract_double_array_helper<dods_byte>(a);
244 return extract_double_array_helper<dods_uint16>(a);
246 return extract_double_array_helper<dods_int16>(a);
248 return extract_double_array_helper<dods_uint32>(a);
250 return extract_double_array_helper<dods_int32>(a);
252 return extract_double_array_helper<dods_float32>(a);
254 return extract_double_array_helper<dods_float64>(a);
257 "The argument list built by the CE parser contained an unsupported numeric type.");
274 "The function requires a DAP numeric-type argument.");
278 "The CE Evaluator built an argument list where some constants held no values.");
284 switch (arg->
type()) {
286 return (
double)(
static_cast<Byte*
>(arg)->value());
288 return (
double)(
static_cast<UInt16*
>(arg)->value());
290 return (
double)(
static_cast<Int16*
>(arg)->value());
292 return (
double)(
static_cast<UInt32*
>(arg)->value());
294 return (
double)(
static_cast<Int32*
>(arg)->value());
296 return (
double)(
static_cast<Float32*
>(arg)->value());
298 return static_cast<Float64*
>(arg)->value();
301 "The argument list built by the CE parser contained an unsupported numeric type.");
318 if (name.find_first_of(
' ') == name.npos)
322 unsigned int i = name.find_first_not_of(
' ');
323 string tmp_name = name.substr(i);
326 unsigned int j = tmp_name.find(
'?') + 1;
327 i = tmp_name.find_first_not_of(
' ', j);
328 tmp_name.erase(j, i - j);
342 vector<string> names(l.size());
345 typedef std::vector<BaseType *>::const_iterator citer ;
346 for (citer i = l.begin(); i != l.end(); i++) {
348 names[nelem++] = (*i)->name();
349 DBG(cerr <<
"NAMES[" << nelem - 1 <<
"]=" << names[nelem-1] << endl);
353 sort(names.begin(), names.end());
356 sort(names.begin(), names.end());
359 for (
int j = 1; j < nelem; ++j) {
360 if (names[j-1] == names[j]) {
362 oss <<
"The variable `" << names[j]
363 <<
"' is used more than once in " << type_name <<
" `"
384 extern "C" const char *
407 if (time(&TimBin) == (time_t) - 1)
408 return string(
"time() error");
411 string TimStr = ctime(&TimBin);
413 char *ctime_value = ctime(&TimBin);
415 string TimStr = ctime_value;
416 return TimStr.substr(0, TimStr.size() - 2);
430 for (
unsigned int i = 0; i < s.length(); i++)
431 s[i] = tolower(s[i]);
442 return (!s.empty() && s[0] ==
'\"' && s[s.length()-1] ==
'\"');
455 return s.substr(1, s.length() - 2);
463 if (strcmp(name,
"Byte") == 0)
466 if (strcmp(name,
"Int8") == 0)
469 if (strcmp(name,
"UInt8") == 0)
472 if (strcmp(name,
"Int16") == 0)
475 if (strcmp(name,
"UInt16") == 0)
478 if (strcmp(name,
"Int32") == 0)
481 if (strcmp(name,
"UInt32") == 0)
484 if (strcmp(name,
"Int64") == 0)
487 if (strcmp(name,
"UInt64") == 0)
490 if (strcmp(name,
"Float32") == 0)
493 if (strcmp(name,
"Float64") == 0)
496 if (strcmp(name,
"String") == 0)
499 if (strcmp(name,
"URL") == 0)
502 if (strcmp(name,
"Url") == 0)
505 if (strcmp(name,
"Array") == 0)
508 if (strcmp(name,
"Structure") == 0)
511 if (strcmp(name,
"Sequence") == 0)
514 if (strcmp(name,
"Grid") == 0)
526 return string(
"Null");
528 return string(
"Byte");
530 return string(
"Int16");
532 return string(
"UInt16");
534 return string(
"Int32");
536 return string(
"UInt32");
538 return string(
"Float32");
540 return string(
"Float64");
542 return string(
"String");
544 return string(
"Url");
546 return string(
"Array");
548 return string(
"Structure");
550 return string(
"Sequence");
552 return string(
"Grid");
555 return string(
"Int8");
557 return string(
"UInt8");
559 return string(
"Int64");
561 return string(
"UInt64");
563 return string(
"URL");
565 return string(
"Group");
567 return string(
"Enum");
570 throw InternalErr(__FILE__, __LINE__,
"Unknown type.");
739 return (stat(dir.c_str(), &buf) == 0) && (buf.st_mode & S_IFDIR);
749 char digits[] =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
753 if (base > 36 || base < 2) {
755 std::invalid_argument ex(
"The parameter base has an invalid value.");
760 r = ldiv(labs(val), base);
768 str_val += digits[(int)r.rem];
806 static const char path_sep[] =
810 static const char path_sep[] =
826 string::size_type pos = path.rfind(path_sep);
828 return (pos == string::npos) ? path : path.substr(++pos);
831 #define CHECK_BIT( tab, bit ) ( tab[ (bit)/8 ] & (1<<( (bit)%8 )) )
832 #define BITLISTSIZE 16
838 static void globchars(
const char *s,
const char *e,
char *b) {
849 if (s + 2 < e && s[1] ==
'-') {
850 for (c = s[0]; c <= s[2]; c++)
851 b[c / 8] |= (1 << (c % 8));
856 b[c / 8] |= (1 << (c % 8));
888 glob(
const char *c,
const char *s)
909 const char *here = c;
913 }
while (here == c || *c !=
']');
918 globchars(here, c, bitlist);
920 if (!
CHECK_BIT( bitlist, *(
unsigned char *)s ))
927 const char *here = s;
940 r = *c ?
glob(c, s) : *s ? -1 : 0;
955 if (!*c || *s++ != *c++)
980 return (sz > 0 && nelem < UINT_MAX / sz);
1002 if (path.length() > 255)
1005 Regex name(
"[-0-9A-z_./]+");
1007 name =
"[:print:]+";
1009 string::size_type len = path.length();
1010 int result = name.match(path.c_str(), len);
1013 if (len > INT_MAX || result != static_cast<int>(len))
1028 return (
string)
"OPeNDAP DAP/" +
libdap_version() +
": compiled on " + __DATE__ +
":" + __TIME__ ;
virtual bool read_p()
Has this variable been read?
Type get_type(const char *name)
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)
virtual int length() const
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.
Type
Identifies the data type.
Type type() const
Returns the type of the class instance.
Holds a 32-bit floating point value.
A class for software fault reporting.
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.
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.
const char * libdap_root()
void append_long_to_string(long val, int base, string &str_val)
double extract_double_value(BaseType *arg)
string name() const
Returns the name of the class instance.
string long_to_string(long val, int base)
#define CHECK_BIT(tab, bit)
string double_to_string(const double &num)
string remove_quotes(const string &s)
The basic data type for the DODS DAP types.
Holds a 64-bit (double precision) floating point value.
bool unique_names(vector< BaseType * > l, const string &var_name, const string &type_name, string &msg)
virtual bool is_simple_type()
Returns true if the instance is a numeric, string or URL type variable.
A class for error processing.
Holds a 32-bit unsigned integer.
string type_name(Type t)
Returns the type of the class instance as a string.
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.
void append_double_to_string(const double &num, string &str)
const char * libdap_name()