libdap  Updated for version 3.20.6
libdap4 is an implementation of OPeNDAP's DAP protocol.
util.h
1 
2 // -*- mode: c++; c-basic-offset:4 -*-
3 
4 // This file is part of libdap, A C++ implementation of the OPeNDAP Data
5 // Access Protocol.
6 
7 // Copyright (c) 2002,2003 OPeNDAP, Inc.
8 // Author: James Gallagher <jgallagher@opendap.org>
9 //
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 //
24 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
25 
26 // (c) COPYRIGHT URI/MIT 1994-1999
27 // Please read the full copyright statement in the file COPYRIGHT.
28 //
29 // Authors:
30 // jhrg,jimg James Gallagher (jgallagher@gso.uri.edu)
31 
32 // declarations for utility functions
33 //
34 // jhrg 9/21/94
35 
36 #ifndef _util_h
37 #define _util_h 1
38 
39 #include <cstdio>
40 #include <cmath>
41 #include <vector>
42 
43 #ifndef _basetype_h
44 #include "BaseType.h"
45 #endif
46 
47 using std::iostream;
48 
49 namespace libdap
50 {
51 
52 class Array;
53 
55 inline bool double_eq(double lhs, double rhs, double epsilon = 1.0e-5)
56 {
57  return fabs(lhs - rhs) < epsilon;
58 }
59 
60 string extract_string_argument(BaseType *arg) ;
61 double extract_double_value(BaseType *arg) ;
62 double *extract_double_array(Array *a) ;
63 void extract_double_array(Array *a, vector<double> &dest) ;
64 void set_array_using_double(Array *dest, double *src, int src_len) ;
65 
66 bool is_host_big_endian();
67 
68 string prune_spaces(const string &);
69 bool unique_names(vector<BaseType *> l, const string &var, const string &type, string &msg);
70 string systime();
71 const char *libdap_root();
72 extern "C" const char *libdap_version();
73 extern "C" const char *libdap_name();
74 
75 #ifdef WIN32
76 void flush_stream(iostream ios, FILE *out);
77 #endif
78 
79 void downcase(string &s);
80 bool is_quoted(const string &s);
81 string remove_quotes(const string &s);
82 
83 Type get_type(const char *name);
84 string D2type_name(Type t);
85 string D4type_name(Type t);
86 string type_name(Type t);
87 bool is_simple_type(Type t);
88 bool is_vector_type(Type t);
90 bool is_integer_type(Type t);
91 
92 bool dir_exists(const string &dir);
93 
94 // Jose Garcia
125 void append_long_to_string(long val, int base, string &str_val);
126 string long_to_string(long val, int base = 10);
128 
129 // Jose Garcia
143 void append_double_to_string(const double &num, string &str);
144 string double_to_string(const double &num);
146 
147 string path_to_filename(string path);
148 int glob( const char *c, const char *s );
149 time_t parse_time(const char * str, bool expand);
150 bool size_ok(unsigned int sz, unsigned int nelem);
151 bool pathname_ok(const string &path, bool strict = true);
152 string dap_version();
153 string open_temp_fstream(ofstream &f, const string &name_template, const string &suffix = "");
154 
155 } // namespace libdap
156 
157 #endif
void downcase(string &s)
Definition: util.cc:563
time_t parse_time(const char *str, bool expand)
Definition: util_mit.cc:129
bool is_constructor_type(Type t)
Returns true if the instance is a constructor (i.e., Structure, Sequence or Grid) type variable...
Definition: util.cc:859
string prune_spaces(const string &name)
Definition: util.cc:459
string open_temp_fstream(ofstream &f, const string &name_template, const string &suffix)
Definition: util.cc:1208
string extract_string_argument(BaseType *arg)
Definition: util.cc:119
bool dir_exists(const string &dir)
Definition: util.cc:925
bool size_ok(unsigned int sz, unsigned int nelem)
sanitize the size of an array. Test for integer overflow when dynamically allocating an array...
Definition: util.cc:1148
bool is_vector_type(Type t)
Returns true if the instance is a vector (i.e., array) type variable.
Definition: util.cc:815
Type
Identifies the data type.
Definition: Type.h:94
top level DAP object to house generic methods
Definition: AISConnect.cc:30
void set_array_using_double(Array *dest, double *src, int src_len)
Definition: util.cc:166
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...
Definition: util.cc:1169
double * extract_double_array(Array *a)
Definition: util.cc:261
ObjectType get_type(const string &value)
Definition: mime_util.cc:326
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...
Definition: util.cc:694
string path_to_filename(string path)
Definition: util.cc:1006
bool is_quoted(const string &s)
Definition: util.cc:574
bool is_simple_type(Type t)
Returns true if the instance is a numeric, string or URL type variable.
Definition: util.cc:775
string systime()
Definition: util.cc:542
double extract_double_value(BaseType *arg)
Definition: util.cc:402
string dap_version()
Definition: util.cc:1191
string remove_quotes(const string &s)
Definition: util.cc:585
The basic data type for the DODS DAP types.
Definition: BaseType.h:117
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...
Definition: util.cc:649
bool is_host_big_endian()
Does this host use big-endian byte order?
Definition: util.cc:94
string type_name(Type t)
Definition: util.cc:760
const char * libdap_version()
Definition: util.cc:526
A multidimensional array of identical data types.
Definition: Array.h:112
int glob(const char *c, const char *s)
Definition: util.cc:1069
bool double_eq(double lhs, double rhs, double epsilon=1.0e-5)
Definition: util.h:55
bool is_integer_type(Type t)
Definition: util.cc:900