libdap Updated for version 3.20.10
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
47using std::iostream;
48
49namespace libdap
50{
51
52class Array;
53
55inline bool double_eq(double lhs, double rhs, double epsilon = 1.0e-5)
56{
57 return fabs(lhs - rhs) < epsilon;
58}
59
60string extract_string_argument(BaseType *arg) ;
61double extract_double_value(BaseType *arg) ;
62double *extract_double_array(Array *a) ;
63void extract_double_array(Array *a, vector<double> &dest) ;
64void set_array_using_double(Array *dest, double *src, int src_len) ;
65
67
68string prune_spaces(const string &);
69bool unique_names(vector<BaseType *> l, const string &var, const string &type, string &msg);
70string systime();
71const char *libdap_root();
72extern "C" const char *libdap_version();
73extern "C" const char *libdap_name();
74
75#ifdef WIN32
76void flush_stream(iostream ios, FILE *out);
77#endif
78
79void downcase(string &s);
80bool is_quoted(const string &s);
81string remove_quotes(const string &s);
82
83Type get_type(const char *name);
84string D2type_name(Type t);
85string D4type_name(Type t);
86string type_name(Type t);
87bool is_simple_type(Type t);
88bool is_vector_type(Type t);
89bool is_constructor_type(Type t);
90bool is_integer_type(Type t);
91
92bool dir_exists(const string &dir);
93
94// Jose Garcia
125void append_long_to_string(long val, int base, string &str_val);
126string long_to_string(long val, int base = 10);
128
129// Jose Garcia
143void append_double_to_string(const double &num, string &str);
144string double_to_string(const double &num);
146
147string path_to_filename(string path);
148int glob( const char *c, const char *s );
149time_t parse_time(const char * str, bool expand);
150bool size_ok(unsigned int sz, unsigned int nelem);
151bool pathname_ok(const string &path, bool strict = true);
152string dap_version();
153string open_temp_fstream(ofstream &f, const string &name_template, const string &suffix = "");
154
155} // namespace libdap
156
157#endif
top level DAP object to house generic methods
string open_temp_fstream(ofstream &f, const string &name_template, const string &suffix)
Definition util.cc:1232
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:1152
string remove_quotes(const string &s)
Definition util.cc:588
string path_to_filename(string path)
Definition util.cc:1009
bool is_host_big_endian()
Does this host use big-endian byte order?
Definition util.cc:94
const char * libdap_version()
Definition util.cc:526
double extract_double_value(BaseType *arg)
Definition util.cc:402
string prune_spaces(const string &name)
Definition util.cc:459
string type_name(Type t)
Definition util.cc:763
void set_array_using_double(Array *dest, double *src, int src_len)
Definition util.cc:166
bool is_simple_type(Type t)
Returns true if the instance is a numeric, string or URL type variable.
Definition util.cc:778
bool dir_exists(const string &dir)
Definition util.cc:928
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:1173
bool double_eq(double lhs, double rhs, double epsilon=1.0e-5)
Definition util.h:55
void downcase(string &s)
Definition util.cc:566
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:652
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:697
string systime()
Definition util.cc:544
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:862
bool is_vector_type(Type t)
Returns true if the instance is a vector (i.e., array) type variable.
Definition util.cc:818
bool is_integer_type(Type t)
Definition util.cc:903
time_t parse_time(const char *str, bool expand)
Definition util_mit.cc:153
int glob(const char *c, const char *s)
Definition util.cc:1072
string extract_string_argument(BaseType *arg)
Definition util.cc:119
ObjectType get_type(const string &value)
Definition mime_util.cc:324
double * extract_double_array(Array *a)
Definition util.cc:261
bool is_quoted(const string &s)
Definition util.cc:577
string dap_version()
Definition util.cc:1215