libdap++  Updated for version 3.13.3
util.h
Go to the documentation of this file.
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 set_array_using_double(Array *dest, double *src, int src_len) ;
64 
65 string prune_spaces(const string &);
66 bool unique_names(vector<BaseType *> l, const string &var, const string &type, string &msg);
67 string systime();
68 //FILE *compressor(FILE *output, int &childpid);
69 //bool deflate_exists();
70 const char *libdap_root();
71 extern "C" const char *libdap_version();
72 extern "C" const char *libdap_name();
73 
74 #ifdef WIN32
75 void flush_stream(iostream ios, FILE *out);
76 #endif
77 
78 void downcase(string &s);
79 bool is_quoted(const string &s);
80 string remove_quotes(const string &s);
81 
82 Type get_type(const char *name);
83 string type_name(Type t);
84 bool is_simple_type(Type t);
85 bool is_vector_type(Type t);
87 bool is_integer_type(Type t);
88 
89 bool dir_exists(const string &dir);
90 
91 // Jose Garcia
122 void append_long_to_string(long val, int base, string &str_val);
123 string long_to_string(long val, int base = 10);
125 
126 // Jose Garcia
140 void append_double_to_string(const double &num, string &str);
141 string double_to_string(const double &num);
143 
144 string path_to_filename(string path);
145 int glob( const char *c, const char *s );
146 time_t parse_time(const char * str, bool expand);
147 bool size_ok(unsigned int sz, unsigned int nelem);
148 bool pathname_ok(const string &path, bool strict = true);
149 string dap_version();
150 
151 #if COMPRESSION_FOR_SERVER3
152 FILE *compressor(FILE *output, int &childpid);
153 bool deflate_exists();
154 #endif
155 
156 #if 0
157 FILE *text_to_temp(string text);
158 #endif
159 #if 0
160 int wmatch(const char *pat, const char *s);
161 #endif
162 #if 0
163 string file_to_string(FILE *fp);
164 
165 int wildcmp(const char *wild, const char *string);
166 #endif
167 #if 0
168 const char *dods_progress();
169 #endif
170 
171 
172 } // namespace libdap
173 
174 #endif
void downcase(string &s)
Definition: util.cc:428
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:668
string prune_spaces(const string &name)
Definition: util.cc:315
string extract_string_argument(BaseType *arg)
Definition: util.cc:96
bool dir_exists(const string &dir)
Definition: util.cc:735
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:978
bool is_vector_type(Type t)
Returns true if the instance is a vector (i.e., array) type variable.
Definition: util.cc:622
Type
Identifies the data type.
Definition: BaseType.h:137
void set_array_using_double(Array *dest, double *src, int src_len)
Definition: util.cc:150
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:1000
double * extract_double_array(Array *a)
Definition: util.cc:223
ObjectType get_type(const string &value)
Definition: mime_util.cc:308
string path_to_filename(string path)
Definition: util.cc:824
bool is_quoted(const string &s)
Definition: util.cc:440
bool is_simple_type(Type t)
Returns true if the instance is a numeric, string or URL type variable.
Definition: util.cc:580
string systime()
Definition: util.cc:403
const char * libdap_root()
Definition: util.cc:375
void append_long_to_string(long val, int base, string &str_val)
Definition: util.cc:744
double extract_double_value(BaseType *arg)
Definition: util.cc:268
string long_to_string(long val, int base)
Definition: util.cc:773
string dap_version()
Definition: util.cc:1026
string double_to_string(const double &num)
Definition: util.cc:792
string remove_quotes(const string &s)
Definition: util.cc:452
bool unique_names(vector< BaseType * > l, const string &var_name, const string &type_name, string &msg)
Definition: util.cc:338
string type_name(Type t)
Returns the type of the class instance as a string.
Definition: util.cc:522
const char * libdap_version()
Definition: util.cc:385
int glob(const char *c, const char *s)
Definition: util.cc:888
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:710
void append_double_to_string(const double &num, string &str)
Definition: util.cc:781
const char * libdap_name()
Definition: util.cc:392